org.geotoolkit.math
Class Vector

Object
  extended by AbstractCollection<E>
      extended by AbstractList<Number>
          extended by Vector
All Implemented Interfaces:
Iterable<Number>, Collection<Number>, List<Number>, RandomAccess, CheckedCollection<Number>, CheckedContainer<Number>

public abstract class Vector
extends AbstractList<Number>
implements CheckedCollection<Number>, RandomAccess

A vector of real numbers. An instance of Vector can be a wrapper around an array of Java primitive type (typically float[] or double[]), or it may be a function calculating values on the fly. Often the two above-cited cases are used together, for example in a time series where:

Instances of Vector are created by calls to the create(Object) static method. The supplied array is not cloned - changes to the primitive array are reflected in the vector, and vis-versa.

Vectors can be created over a subrange of an array, provides a view of the elements in reverse order, etc. The example below creates a view over a subrange:

Vector v = Vector.create(array).subList(lower, upper)

Since:
1.0
Version:
3.00
Author:
Martin Desruisseaux (MPO, Geomatys)
Module:
utility/geotk-utility (download)    View source code for this class

Field Summary
 
Fields inherited from class AbstractList
modCount
 
Constructor Summary
protected Vector()
          For subclasses constructor.
 
Method Summary
abstract  byte byteValue(int index)
          Returns the value at the given index as a byte.
 Vector concatenate(Vector toAppend)
          Returns the concatenation of this vector with the given one.
static Vector create(Object array)
          Wraps the given object in a vector.
static Vector createSequence(double first, double increment, int length)
          Creates a sequence of numbers in a given range of values using the given increment.
abstract  double doubleValue(int index)
          Returns the value at the given index as a double.
abstract  float floatValue(int index)
          Returns the value at the given index as a float.
abstract  Number get(int index)
          Returns the number at the given index, or null if none.
abstract  Class<? extends Number> getElementType()
          Returns the type of elements in this vector.
abstract  int intValue(int index)
          Returns the value at the given index as an int.
abstract  boolean isNaN(int index)
          Returns true if the value at the given index is NaN.
abstract  long longValue(int index)
          Returns the value at the given index as a long.
 Vector reverse()
          Returns a view which contains the values of this vector in reverse order.
abstract  Number set(int index, Number value)
          Sets the number at the given index.
abstract  short shortValue(int index)
          Returns the value at the given index as a short.
abstract  int size()
          Returns the number of elements in this vector.
 Vector subList(int lower, int upper)
          Returns a view which contain the values of this vector in the given index range.
 Vector subList(int first, int step, int length)
          Returns a view which contain the values of this vector in a given index range.
 Vector view(int... index)
          Returns a view which contains the values of this vector at the given indexes.
 
Methods inherited from class AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange
 
Methods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

Vector

protected Vector()
For subclasses constructor.

Method Detail

create

public static Vector create(Object array)
                     throws IllegalArgumentException
Wraps the given object in a vector. The argument should be one of the following:

The argument is not cloned. Consequently changes in the underlying array are reflected in this vector, and vis-versa.

Parameters:
array - The object to wrap in a vector, or null.
Returns:
The given object wrapped in a vector, or null if the argument was null.
Throws:
IllegalArgumentException - If the type of the given object is not recognized by the method.

createSequence

public static Vector createSequence(double first,
                                    double increment,
                                    int length)
Creates a sequence of numbers in a given range of values using the given increment. The range of values will be first inclusive to (first + increment*length) exclusive. Note that the value given by the first argument is equivalent to a "lowest" or "minimum" value only if the given increment is positive.

The element type will be the smallest type that can be used for storing every values. For example it will be Byte.class for the range [100:1:120] but will be Double.class for the range [0:0.1:1].

Parameters:
first - The first value, inclusive.
increment - The difference between the values at two adjacent indexes.
length - The length of the desired vector.
Returns:
The given sequence as a vector.

size

public abstract int size()
Returns the number of elements in this vector.

Specified by:
size in interface Collection<Number>
Specified by:
size in interface List<Number>
Specified by:
size in class AbstractCollection<Number>
Returns:
The number of elements in this vector.

getElementType

public abstract Class<? extends Number> getElementType()
Returns the type of elements in this vector. If this vector is backed by an array of a primitive type, then this method returns the wrapper class, not the primitive type. For example if this vector is backed by an array of type float[], then this method returns Float.class, not Float.TYPE.

Specified by:
getElementType in interface CheckedCollection<Number>
Specified by:
getElementType in interface CheckedContainer<Number>
Returns:
The element type.

isNaN

public abstract boolean isNaN(int index)
                       throws IndexOutOfBoundsException
Returns true if the value at the given index is NaN.

Parameters:
index - The index in the [0 … size-1] range.
Returns:
true if the value at the given index is NaN.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.

doubleValue

public abstract double doubleValue(int index)
                            throws IndexOutOfBoundsException,
                                   ClassCastException
Returns the value at the given index as a double.

Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ClassCastException - if the component type can not be converted to a double by an identity or widening conversion.

floatValue

public abstract float floatValue(int index)
                          throws IndexOutOfBoundsException,
                                 ClassCastException
Returns the value at the given index as a float. If this vector uses internally a wider type like double, then this method may cast the value or throw an exception at implementation choice. The general guidelines are:

For safety users should either call doubleValue(int) in all cases, or call this methods only if the type returned by getElementType() has been verified.

Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ClassCastException - if the component type can not be converted to a float by an identity or widening conversion.

longValue

public abstract long longValue(int index)
                        throws IndexOutOfBoundsException,
                               ClassCastException
Returns the value at the given index as a long. If this vector uses internally a wider type, then this method may cast the value or throw an exception according the same guidelines than floatValue(int).

Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ClassCastException - if the component type can not be converted to a long by an identity or widening conversion.

intValue

public abstract int intValue(int index)
                      throws IndexOutOfBoundsException,
                             ClassCastException
Returns the value at the given index as an int. If this vector uses internally a wider type, then this method may cast the value or throw an exception according the same guidelines than floatValue(int).

Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ClassCastException - if the component type can not be converted to an int by an identity or widening conversion.

shortValue

public abstract short shortValue(int index)
                          throws IndexOutOfBoundsException,
                                 ClassCastException
Returns the value at the given index as a short. If this vector uses internally a wider type, then this method may cast the value or throw an exception according the same guidelines than floatValue(int).

Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ClassCastException - if the component type can not be converted to a short by an identity or widening conversion.

byteValue

public abstract byte byteValue(int index)
                        throws IndexOutOfBoundsException,
                               ClassCastException
Returns the value at the given index as a byte. If this vector uses internally a wider type, then this method may cast the value or throw an exception according the same guidelines than floatValue(int).

Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ClassCastException - if the component type can not be converted to a byte by an identity or widening conversion.

get

public abstract Number get(int index)
                    throws IndexOutOfBoundsException
Returns the number at the given index, or null if none.

Specified by:
get in interface List<Number>
Specified by:
get in class AbstractList<Number>
Parameters:
index - The index in the [0 … size-1] range.
Returns:
The value at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.

set

public abstract Number set(int index,
                           Number value)
                    throws IndexOutOfBoundsException,
                           ArrayStoreException
Sets the number at the given index.

Specified by:
set in interface List<Number>
Overrides:
set in class AbstractList<Number>
Parameters:
index - The index in the [0 … size-1] range.
value - The value to set at the given index.
Returns:
The value previously stored at the given index.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.
ArrayStoreException - if the given value can not be stored in this vector.

view

public Vector view(int... index)
            throws IndexOutOfBoundsException
Returns a view which contains the values of this vector at the given indexes. This method does not copy the values, consequently any modification to the values of this vector will be reflected in the returned view and vis-versa.

The indexes don't need to be in any particular order. The same index can be repeated more than once. Thus it is possible to create a vector larger than the original vector.

Parameters:
index - Index of the values to be returned.
Returns:
A view of this vector containing values at the given indexes.
Throws:
IndexOutOfBoundsException - if at least one index is out of bounds.

reverse

public final Vector reverse()
Returns a view which contains the values of this vector in reverse order. This method delegates its work to subList(size-1, -1, size). It is declared final in order to force every subclasses to override the later method instead than this one.

Returns:
The vector values in reverse order.

subList

public final Vector subList(int lower,
                            int upper)
                     throws IndexOutOfBoundsException
Returns a view which contain the values of this vector in the given index range. The returned view will contain the values from index lower inclusive to upper exclusive.

This method delegates its work to subList(lower, 1, upper-lower). It is declared final in order to force every subclasses to override the later method instead than this one.

Specified by:
subList in interface List<Number>
Overrides:
subList in class AbstractList<Number>
Parameters:
lower - Index of the first value to be included in the returned view.
upper - Index after the last value to be included in the returned view.
Returns:
A view of this vector containing values in the given index range.
Throws:
IndexOutOfBoundsException - If an index is outside the [0 … size-1] range.

subList

public Vector subList(int first,
                      int step,
                      int length)
               throws IndexOutOfBoundsException
Returns a view which contain the values of this vector in a given index range. The returned view will contain the values from index first inclusive to (first + step*length) exclusive with index incremented by the given step value, which can be negative. More specifically the index i in the returned vector will maps the element at index (first + step*i) in this vector.

This method does not copy the values. Consequently any modification to the values of this vector will be reflected in the returned view and vis-versa.

Parameters:
first - Index of the first value to be included in the returned view.
step - The index increment in this vector between two consecutive values in the returned vector. Can be positive, zero or negative.
length - The length of the vector to be returned. Can not be greater than the length of this vector, except if the step is zero.
Returns:
A view of this vector containing values in the given index range.
Throws:
IndexOutOfBoundsException - If first or first + step*(length-1) is outside the [0 … size-1] range.

concatenate

public Vector concatenate(Vector toAppend)
Returns the concatenation of this vector with the given one. Indexes in the [0 … size-1] range will map to this vector, while indexes in the [size … size + toAppend.size] range while map to the given vector.

Parameters:
toAppend - The vector to concatenate at the end of this vector.
Returns:
The concatenation of this vector with the given vector.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.