Class GrowableArray

java.lang.Object
cnuphys.splot.pdata.GrowableArray
Direct Known Subclasses:
DataColumn

public class GrowableArray extends Object
This class supports named arrays that grow. They are an alternative to Vectors or ArrayLists. The advantages are speed and usage for those cases where arrays are more convenient. Clients only have access to minimal copies which can be used as "just the right size" arrays.
Author:
heddle
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double[]
     
    protected int
     
    protected int
     
    protected int
     
    protected double
     
    protected double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a GrowableArray with initial capacity 100 and increment 100.
    GrowableArray(int initCap, int increment)
    Create a GrowableArray
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(double val)
    Add a value to the array, growing it if necessary.
    void
    Reset the data array to the initial capacity and fill with all NaNs.
    double
    get(int index)
    Get the value at the given index
    double
    Get the maximum data value
    double[]
    Get the minimal copy of the data array.
    double
    Get the minimum data value
    void
    removes the first entry and moves all other entries up one
    void
    set(int index, double val)
    Set the value at the given index
    int
    Get the number of real data in the array, which in general is less than the length of the array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _data

      protected double[] _data
    • _dataLen

      protected int _dataLen
    • _increment

      protected int _increment
    • _initCap

      protected int _initCap
    • _minValue

      protected double _minValue
    • _maxValue

      protected double _maxValue
  • Constructor Details

    • GrowableArray

      public GrowableArray()
      Creates a GrowableArray with initial capacity 100 and increment 100.
    • GrowableArray

      public GrowableArray(int initCap, int increment)
      Create a GrowableArray
      Parameters:
      initCap - the initial capacity
      increment - the increment when the array grows.
  • Method Details

    • size

      public int size()
      Get the number of real data in the array, which in general is less than the length of the array. This is the effective length of the array, so loops should go from 0 to this value minus 1.
      Returns:
      the number of real data.
    • getMinimalCopy

      public double[] getMinimalCopy()
      Get the minimal copy of the data array. This copies the actual data into a new array of just the right size. This new array can be used normally, i.e., it is safe to use its length.
      Returns:
      a copy of the data array of just the right length
    • removeFirst

      public void removeFirst()
      removes the first entry and moves all other entries up one
    • add

      public void add(double val)
      Add a value to the array, growing it if necessary.
      Parameters:
      val - the value to add
    • getMinValue

      public double getMinValue()
      Get the minimum data value
      Returns:
      the minimum data value
    • getMaxValue

      public double getMaxValue()
      Get the maximum data value
      Returns:
      the maximum data value
    • clear

      public void clear()
      Reset the data array to the initial capacity and fill with all NaNs.
    • get

      public double get(int index)
      Get the value at the given index
      Parameters:
      index - the index
      Returns:
      the value at the index
    • set

      public void set(int index, double val)
      Set the value at the given index
      Parameters:
      index - the index
      val - the value at the index