Package rma.util

Class DoubleVector

java.lang.Object
rma.util.DoubleVector
All Implemented Interfaces:
AsciiSerializable, FieldAccessor, Serializable, Cloneable

public class DoubleVector extends Object implements Cloneable, Serializable, AsciiSerializable
The DoubleVector class implements a growable array of double primatives. Like an array, it contains components that can be accessed using an integer index. However, the size of a DoubleVector can grow or shrink as needed to accommodate adding and removing items after the DoubleVector has been created.

Each vector tries to optimize storage management by maintaining a capacity and a _capacityIncrement . The capacity is always at least as large as the vector size; it is usually larger because as components are added to the vector, the vector's storage increases in chunks the size of _capacityIncrement . An application can increase the capacity of a vector before inserting a large number of components; this reduces the amount of incremental reallocation.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity.
    protected int
    The number of valid components in the vector.
    protected double[]
    The array buffer into which the components of the vector are stored.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty DoubleVector.
    DoubleVector(int initialCapacity)
    Constructs an empty DoubleVector with the specified initial capacity.
    DoubleVector(int initialCapacity, int capacityIncrement)
    Constructs an empty DoubleVector with the specified initial capacity and capacity increment.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(double obj)
    Adds the specified component to the end of this vector, increasing its size by one.
    boolean
    Appends all of the elements in the specified DoubleVector to the end of this DoubleVector, in the order that they are returned by the specified DoubleVector's Iterator.
    final void
    addElement(double obj)
    Adds the specified component to the end of this vector, increasing its size by one.
    final int
    Returns the current capacity of this vector.
    void
    Removes all components from this vector and sets its size to zero.
    Returns a clone of this vector.
    final boolean
    contains(double elem)
    Tests if the specified double is a component in this vector.
    final void
    copyInto(double[] anArray)
    Copies the components of this DoubleVector into the specified array.
    final double
    elementAt(int index)
    Returns the component at the specified index.
    double
    Returns the total value of all the elements
    final void
    ensureCapacity(int minCapacity)
    Increases the capacity of this DoubleVector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
    boolean
     
    final double
    Returns the first component of this vector.
    double
    get(int index)
    Returns the component at the specified index.
    Gets the FieldObject attribute of the DoubleVector object
    double
     
    double
     
    final int
    indexOf(double elem)
    Searches for the first occurence of the given argument, testing for equality using ==.
    final int
    indexOf(double elem, int index)
    Searches for the first occurence of the given argument, beginning the search at index , and testing for equality using ==.
    final void
    insertElementAt(double obj, int index)
    Inserts the specified double as a component in this vector at the specified index .
    final boolean
    Tests if this vector has no components.
    final double
    Returns the last component of the vector.
    final int
    lastIndexOf(double elem)
    Returns the index of the last occurrence of the specified double in this vector.
    final int
    lastIndexOf(double elem, int index)
    Searches backwards for the specified double, starting from the specified index, and returns an index to it.
    boolean
    remove(double obj)
    Removes the first occurrence of the argument from this vector.
    final void
    Removes all components from this vector and sets its size to zero.
    final boolean
    removeElement(double obj)
    Removes the first occurrence of the argument from this vector.
    final void
    removeElementAt(int index)
    Deletes the component at the double index.
    final void
    setElementAt(double obj, int index)
    Sets the double at the specified index of this vector to be the specified double.
    boolean
    Sets the FieldObject attribute of the DoubleVector object
    final void
    setSize(int newSize)
    Sets the size of this vector.
    final void
    setSize(int newSize, double defaultValue)
    Sets the size of this vector.
    final int
    Returns the number of components in this vector.
    void
    sort(boolean reverse)
     
    double[]
    Returns an array containing all of the elements in this list in the correct order.
    final String
    Returns a string representation of this vector.
    final void
    Trims the capacity of this DoubleVector to be the DoubleVector's current size.

    Methods inherited from class java.lang.Object

    finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • _elementData

      protected double[] _elementData
      The array buffer into which the components of the vector are stored. The capacity of the vector is the length of this array buffer.
    • _elementCount

      protected int _elementCount
      The number of valid components in the vector.
    • _capacityIncrement

      protected int _capacityIncrement
      The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. If the capacity increment is 0 , the capacity of the vector is doubled each time it needs to grow.
  • Constructor Details

    • DoubleVector

      public DoubleVector(int initialCapacity, int capacityIncrement)
      Constructs an empty DoubleVector with the specified initial capacity and capacity increment.
      Parameters:
      initialCapacity - the initial capacity of the vector.
      capacityIncrement - the amount by which the capacity is increased when the vector overflows.
    • DoubleVector

      public DoubleVector(int initialCapacity)
      Constructs an empty DoubleVector with the specified initial capacity.
      Parameters:
      initialCapacity - the initial capacity of the vector.
    • DoubleVector

      public DoubleVector()
      Constructs an empty DoubleVector.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • copyInto

      public final void copyInto(double[] anArray)
      Copies the components of this DoubleVector into the specified array. The array must be big enough to hold all the ints in this DoubleVector.
      Parameters:
      anArray - the array into which the components get copied.
    • trimToSize

      public final void trimToSize()
      Trims the capacity of this DoubleVector to be the DoubleVector's current size. An application can use this operation to minimize the storage of a DoubleVector.
    • ensureCapacity

      public final void ensureCapacity(int minCapacity)
      Increases the capacity of this DoubleVector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
      Parameters:
      minCapacity - the desired minimum capacity.
    • setSize

      public final void setSize(int newSize)
      Sets the size of this vector. If the new size is greater than the current size, new RMAConst.UNDEF_DOUBLE items are added to the end of the vector. If the new size is less than the current size, all components at index newSize and greater are discarded.
      Parameters:
      newSize - the new size of this vector.
    • setSize

      public final void setSize(int newSize, double defaultValue)
      Sets the size of this vector. If the new size is greater than the current size, new defaultValue items are added to the end of the vector. If the new size is less than the current size, all components at index newSize and greater are discarded.
      Parameters:
      newSize - the new size of this vector.
      defaultValue - value to fill new array elements with
    • capacity

      public final int capacity()
      Returns the current capacity of this vector.
      Returns:
      the current capacity of this vector.
      Since:
      JDK1.0
    • size

      public final int size()
      Returns the number of components in this vector.
      Returns:
      the number of components in this vector.
      Since:
      JDK1.0
    • isEmpty

      public final boolean isEmpty()
      Tests if this vector has no components.
      Returns:
      true if this vector has no components; false otherwise.
      Since:
      JDK1.0
    • contains

      public final boolean contains(double elem)
      Tests if the specified double is a component in this vector.
      Parameters:
      elem - an int.
      Returns:
      true if the specified double is a component in this vector; false otherwise.
    • indexOf

      public final int indexOf(double elem)
      Searches for the first occurence of the given argument, testing for equality using ==.
      Parameters:
      elem - a double.
      Returns:
      the index of the first occurrence of the argument in this vector; returns -1 if the double is not found.
    • indexOf

      public final int indexOf(double elem, int index)
      Searches for the first occurence of the given argument, beginning the search at index , and testing for equality using ==.
      Parameters:
      elem - a double.
      index - the index to start searching from.
      Returns:
      the index of the first occurrence of the double argument in this vector at position index or later in the vector; returns -1 if the int is not found.
    • lastIndexOf

      public final int lastIndexOf(double elem)
      Returns the index of the last occurrence of the specified double in this vector.
      Parameters:
      elem - the desired component.
      Returns:
      the index of the last occurrence of the specified double in this vector; returns -1 if the double is not found.
    • lastIndexOf

      public final int lastIndexOf(double elem, int index)
      Searches backwards for the specified double, starting from the specified index, and returns an index to it.
      Parameters:
      elem - the desired component.
      index - the index to start searching from.
      Returns:
      the index of the last occurrence of the specified double in this vector at position less than index in the vector; -1 if the double is not found.
    • get

      public double get(int index)
      Returns the component at the specified index. wrapper for elementAt(int);
      Parameters:
      index - Description
      Returns:
      Description
    • elementAt

      public final double elementAt(int index)
      Returns the component at the specified index.
      Parameters:
      index - an index into this vector.
      Returns:
      the component at the specified index.
    • firstElement

      public final double firstElement()
      Returns the first component of this vector.
      Returns:
      the first component of this vector.
    • lastElement

      public final double lastElement()
      Returns the last component of the vector.
      Returns:
      the last component of the vector, i.e., the component at index size() - 1 .
    • setElementAt

      public final void setElementAt(double obj, int index)
      Sets the double at the specified index of this vector to be the specified double. The previous double at that position is discarded.

      The index must be a value greater than or equal to 0 and less than the current size of the vector.

      Parameters:
      obj - what the double is to be set to.
      index - the specified index.
      See Also:
    • removeElementAt

      public final void removeElementAt(int index)
      Deletes the component at the double index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously.

      The index must be a value greater than or equal to 0 and less than the current size of the vector.

      Parameters:
      index - the index of the double to remove.
      See Also:
    • insertElementAt

      public final void insertElementAt(double obj, int index)
      Inserts the specified double as a component in this vector at the specified index . Each component in this vector with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously.

      The index must be a value greater than or equal to 0 and less than or equal to the current size of the vector.

      Parameters:
      obj - the double to insert.
      index - where to insert the new component.
      See Also:
    • add

      public void add(double obj)
      Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. wrapper for addElement(double);
      Parameters:
      obj - the double to be added
    • addAll

      public boolean addAll(DoubleVector dv)
      Appends all of the elements in the specified DoubleVector to the end of this DoubleVector, in the order that they are returned by the specified DoubleVector's Iterator. The behavior of this operation is undefined if the specified DoubleVector is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified DoubleVector is this DoubleVector, and this DoubleVector is nonempty.)
      Parameters:
      dv - the elements to be inserted into this list.
      Returns:
      true if this list changed as a result of the call.
      Throws:
      NullPointerException - if the specified DoubleVector is null.
    • addElement

      public final void addElement(double obj)
      Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity.
      Parameters:
      obj - the double to be added.
    • toArray

      public double[] toArray()
      Returns an array containing all of the elements in this list in the correct order.
      Returns:
      an array containing all of the elements in this list in the correct order.
    • remove

      public boolean remove(double obj)
      Removes the first occurrence of the argument from this vector. If the double is found in this vector, each component in the vector with an index greater or equal to the double's index is shifted downward to have an index one smaller than the value it had previously. wrapper for removeElement(double)
      Parameters:
      obj - the double to remove
      Returns:
      true if the argument was a component of this vector; false otherwise.
    • removeElement

      public final boolean removeElement(double obj)
      Removes the first occurrence of the argument from this vector. If the double is found in this vector, each component in the vector with an index greater or equal to the int's index is shifted downward to have an index one smaller than the value it had previously.
      Parameters:
      obj - the double to be removed.
      Returns:
      true if the argument was a component of this vector; false otherwise.
    • clear

      public void clear()
      Removes all components from this vector and sets its size to zero. wrapper for removeAllElements();
    • removeAllElements

      public final void removeAllElements()
      Removes all components from this vector and sets its size to zero.
      Since:
      JDK1.0
    • clone

      public Object clone()
      Returns a clone of this vector.
      Overrides:
      clone in class Object
      Returns:
      a clone of this vector.
      Since:
      JDK1.0
    • getMax

      public double getMax()
      Returns:
      the max value of the elements
    • getMin

      public double getMin()
      Returns:
      the min value of the elements
    • elementTotal

      public double elementTotal()
      Returns the total value of all the elements
    • toString

      public final String toString()
      Returns a string representation of this vector.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this vector.
      Since:
      JDK1.0
    • getFieldObject

      public Object getFieldObject(Field fld)
      Gets the FieldObject attribute of the DoubleVector object
      Specified by:
      getFieldObject in interface FieldAccessor
      Parameters:
      fld - Description
      Returns:
      The FieldObject value
    • setFieldObject

      public boolean setFieldObject(Field fld, Object fobj)
      Sets the FieldObject attribute of the DoubleVector object
      Specified by:
      setFieldObject in interface FieldAccessor
      Parameters:
      fld - The new FieldObject value
      fobj - The new FieldObject value
      Returns:
      Description
    • sort

      public void sort(boolean reverse)