nrc.fuzzy
Class DoubleVector

java.lang.Object
  |
  +--nrc.fuzzy.DoubleVector
All Implemented Interfaces:
java.io.Serializable

public class DoubleVector
extends java.lang.Object
implements java.io.Serializable

The DoubleVector class implements a growable array of double values. Like an array, the values can be accessed using an integer index. However, the size of a DoubleVector can grow as needed to accommodate adding items after the DoubleVector has been created. This class was created for the utility of the package and was not written with the intention of allowing user access.

See Also:
Serialized Form

Field Summary
protected  double[] d
          The array of doubles values.
protected  int increment
          The increment amount by which the DoubleVector expands when it reaches capacity and has to insert another double value.
protected  int index
          The current number of double values in the array, and the index of the array at which the next double value should be inserted.
protected static int INITIAL_CAPACITY
          The default initial capacity of the DoubleVector.
 
Constructor Summary
DoubleVector()
          Creates an empty DoubleVector with the default initial capacity and increment values.
DoubleVector(double[] doubleArray, int length)
          Creates a DoubleVector with the length specified in the parameters, and initialized for the full length of the DoubleVector from the double values contained in the passed array.
DoubleVector(int initialCapacity)
          Creates an empty DoubleVector with the specified initial capacity and the default increment value.
DoubleVector(int initialCapacity, int increment)
          Creates an empty DoubleVector with the specified initial capacity and increment value.
 
Method Summary
 void addDouble(double value)
          Adds a double value to the end of the DoubleVector, increasing its size by one.
 void concat(nrc.fuzzy.DoubleVector other)
          Concatenates the DoubleVector argument with this DoubleVector.
 double doubleAt(int i)
          Returns the double value at the specified index.
 void insertDoubleAt(double value, int i)
          Inserts the double argument into the DoubleVector at the specified index.
 void removeDoubleAt(int i)
          Removes the double value from the DoubleVector at the specified index.
 void setDoubleAt(double value, int i)
          Sets the double value in the DoubleVector at the specified index.
 int size()
          Returns the size of the DoubleVector, or the number of double values in the DoubleVector.
 double[] todoubleArray()
          Returns the array of doubles, trimmed to size, that this DoubleVector contains.
 void trimToSize()
          Trims the capacity of this DoubleVector to be the DoubleVector's current size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

protected static final int INITIAL_CAPACITY
The default initial capacity of the DoubleVector. This default initial capacity is only used when the initial capacity of the DoubleVector is not a parameter passed to the constructor used.

See Also:
Constant Field Values

increment

protected int increment
The increment amount by which the DoubleVector expands when it reaches capacity and has to insert another double value. This increment value can be set by choosing a constructor that allows you to specify it.


d

protected double[] d
The array of doubles values. This array is manipulated in such a way that it will expand as required to accomodate the addition of double values after the DoubleVector is created.


index

protected int index
The current number of double values in the array, and the index of the array at which the next double value should be inserted.

Constructor Detail

DoubleVector

public DoubleVector()
Creates an empty DoubleVector with the default initial capacity and increment values.


DoubleVector

public DoubleVector(int initialCapacity)
Creates an empty DoubleVector with the specified initial capacity and the default increment value.

Parameters:
initialCapacity - the int which specifies the desired initial capacity of the DoubleVector. This is best used it is known that the DoubleVector will be quite large so as to avoid multiple expansions of the DoubleVector, which is inefficient.

DoubleVector

public DoubleVector(int initialCapacity,
                    int increment)
Creates an empty DoubleVector with the specified initial capacity and increment value.

Parameters:
initialCapacity - the int to specify the desired initial capacity of the DoubleVector. This is best used it is known that the DoubleVector will be quite large so as to avoid multiple expansions of the DoubleVector, which is inefficient.
increment - the int to specify the desired increment of the DoubleVector

DoubleVector

public DoubleVector(double[] doubleArray,
                    int length)
Creates a DoubleVector with the length specified in the parameters, and initialized for the full length of the DoubleVector from the double values contained in the passed array.

Parameters:
doubleArray - the array of doubles which contains the double values with which to initialize the DoubleVector.
length - this parameter is basically equivalent to the initial capacity parameter in the other constructors. However, it has one additional implication. It is expected that length is less than or equal to the length of doubleArray.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the length parameter is greater than the length of doubleArray.
Method Detail

addDouble

public void addDouble(double value)
Adds a double value to the end of the DoubleVector, increasing its size by one.

Parameters:
value - the double value to be added to the DoubleVector

concat

public void concat(nrc.fuzzy.DoubleVector other)
Concatenates the DoubleVector argument with this DoubleVector. The values contained within the DoubleVector argument are effectively added to the end of this DoubleVector.

Parameters:
other - the DoubleVector to concatenate onto the end of this DoubleVector

doubleAt

public double doubleAt(int i)
Returns the double value at the specified index.

Parameters:
i - the index in the DoubleVector of the desired double value
Returns:
the double value at the specified index

setDoubleAt

public void setDoubleAt(double value,
                        int i)
Sets the double value in the DoubleVector at the specified index.

Parameters:
value - the double value to set the specified position in the DoubleVector to
i - the index in the DoubleVector of the double value position that is desired to be set

removeDoubleAt

public void removeDoubleAt(int i)
Removes the double value from the DoubleVector at the specified index. The subsequent values in the DoubleVector are then shifted down one index position.

Parameters:
i - the position of the double value to remove

insertDoubleAt

public void insertDoubleAt(double value,
                           int i)
Inserts the double argument into the DoubleVector at the specified index. The double value at the specified index and all subsequent values in the DoubleVector are then shifted up one index position.

Parameters:
value - the double value to be inserted into the DoubleVector
i - the index position of the DoubleVector into which the double value argument is to be inserted

trimToSize

public void trimToSize()
Trims the capacity of this DoubleVector to be the DoubleVector's current size. This can be used to minimize the storage of a DoubleVector.


size

public int size()
Returns the size of the DoubleVector, or the number of double values in the DoubleVector.


todoubleArray

public double[] todoubleArray()
Returns the array of doubles, trimmed to size, that this DoubleVector contains.

Returns:
the double[] of the values contained by the DoubleVector. The length of the returned double vector is the current size of the DoubleVector; in other words, the exact number of double values in the DoubleVector.