Class Series<T>

java.lang.Object
trade.invision.indicators.series.Series<T>
Type Parameters:
T - the immutable type
Direct Known Subclasses:
BarSeries, Indicator.CacheSeries, NumSeries

public class Series<T> extends Object
Series is a class that provides a simple interface for storing and retrieving values from a series. Values can only be added to this Series, except for the last value, which can be replaced with a new value. When the number of values stored in this Series exceed a configurable maximum upon adding a new value, then values at the beginning of this Series are removed. Values should be of an immutable type. This class is not thread-safe.
  • Field Details

    • maximumLength

      protected final int maximumLength
      The maximum number of values that this Series will store internally in memory. If the number of values stored in this Series exceed this limit upon adding a new value, then the values at the beginning of this Series are removed.
    • numFactory

      protected final NumFactory numFactory
      The NumFactory that consumers of this Series may use for creating Nums.
    • epsilon

      protected final Num epsilon
      The Num to use as the epsilon in tolerant comparison operations that consumers of this Series may use.
    • values

      protected final List<T> values
    • startIndex

      protected long startIndex
      The index of the first value in this Series, which changes due to getMaximumLength(). This will be -1 if isEmpty() is true.
    • endIndex

      protected long endIndex
      The index of the last value in this Series, which changes due to getMaximumLength(). This will be -1 if isEmpty() is true.
    • addCallCount

      protected long addCallCount
      Gets the number of times add(Object, boolean) has been called. Use to track if this Series may have changed in any way. Number may overflow.
  • Constructor Details

  • Method Details

    • replaceLast

      public void replaceLast(T value)
      Calls add(Object, boolean) with replaceLast set to true.
    • add

      public void add(T value)
      Calls add(Object, boolean) with replaceLast set to false.
    • add

      public void add(T value, boolean replaceLast)
      Adds the given value to this Series.
      Parameters:
      value - the value
      replaceLast - true to replace the last value in this Series, false to add the value to the end of this Series
    • get

      public T get(long index)
      Gets the value at the given index. If the given index is less than getStartIndex(), then getStartIndex() is used.
      Parameters:
      index - the index
      Returns:
      the Series value
      Throws:
      IndexOutOfBoundsException - thrown if the index is outside the range of this Series
    • getFirst

      public T getFirst()
      Returns:
      the first value in this Series
    • getLast

      public T getLast()
      Returns:
      the last value in this Series
    • getLength

      public long getLength()
      Gets the number of values in this Series, which changes due to getMaximumLength().
      Returns:
      the length of this Series
    • isEmpty

      public boolean isEmpty()
      Checks if this Series is empty (getLength() is 0).
      Returns:
      true if empty, false otherwise
    • listView

      public List<T> listView()
      Returns a read-only view of this Series as a List.
      Returns:
      the List view
    • getMaximumLength

      public int getMaximumLength()
      The maximum number of values that this Series will store internally in memory. If the number of values stored in this Series exceed this limit upon adding a new value, then the values at the beginning of this Series are removed.
    • getNumFactory

      public NumFactory getNumFactory()
      The NumFactory that consumers of this Series may use for creating Nums.
    • getEpsilon

      public Num getEpsilon()
      The Num to use as the epsilon in tolerant comparison operations that consumers of this Series may use.
    • getStartIndex

      public long getStartIndex()
      The index of the first value in this Series, which changes due to getMaximumLength(). This will be -1 if isEmpty() is true.
    • getEndIndex

      public long getEndIndex()
      The index of the last value in this Series, which changes due to getMaximumLength(). This will be -1 if isEmpty() is true.
    • getAddCallCount

      public long getAddCallCount()
      Gets the number of times add(Object, boolean) has been called. Use to track if this Series may have changed in any way. Number may overflow.