Package trade.invision.indicators.series
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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected longGets the number of timesadd(Object, boolean)has been called.protected longThe index of the last value in thisSeries, which changes due togetMaximumLength().protected final Numprotected final intThe maximum number of values that thisSerieswill store internally in memory.protected final NumFactoryprotected longThe index of the first value in thisSeries, which changes due togetMaximumLength(). -
Constructor Summary
ConstructorsConstructorDescriptionSeries(int maximumLength) CallsSeries(Collection, int, NumFactory, Num)withinitialValuesset tonull,numFactoryset tonull, andepsilonset tonull.Series(int maximumLength, @Nullable NumFactory numFactory) CallsSeries(Collection, int, NumFactory, Num)withinitialValuesset tonullandepsilonset tonull.Series(@Nullable Collection<T> initialValues, int maximumLength) Series(@Nullable Collection<T> initialValues, int maximumLength, @Nullable NumFactory numFactory, @Nullable Num epsilon) Instantiates a newSeries. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidAdds the givenvalueto thisSeries.get(long index) Gets the value at the givenindex.longGets the number of timesadd(Object, boolean)has been called.longThe index of the last value in thisSeries, which changes due togetMaximumLength().getFirst()Callsget(long)withgetStartIndex().getLast()Callsget(long)withgetEndIndex().longGets the number of values in thisSeries, which changes due togetMaximumLength().intThe maximum number of values that thisSerieswill store internally in memory.longThe index of the first value in thisSeries, which changes due togetMaximumLength().booleanisEmpty()listView()Convenience method forgetNumFactory()NumFactory.of(Number).Convenience method forgetNumFactory()NumFactory.of(String).numOf(BigDecimal bigDecimal) Convenience method forgetNumFactory()NumFactory.of(BigDecimal).Convenience method forgetNumFactory()NumFactory.of(Num).voidreplaceLast(T value)
-
Field Details
-
maximumLength
protected final int maximumLength -
numFactory
-
epsilon
-
values
-
startIndex
protected long startIndexThe index of the first value in thisSeries, which changes due togetMaximumLength(). This will be-1ifisEmpty()istrue. -
endIndex
protected long endIndexThe index of the last value in thisSeries, which changes due togetMaximumLength(). This will be-1ifisEmpty()istrue. -
addCallCount
protected long addCallCountGets the number of timesadd(Object, boolean)has been called. Use to track if thisSeriesmay have changed in any way. Number may overflow.
-
-
Constructor Details
-
Series
public Series(int maximumLength) CallsSeries(Collection, int, NumFactory, Num)withinitialValuesset tonull,numFactoryset tonull, andepsilonset tonull. -
Series
-
Series
CallsSeries(Collection, int, NumFactory, Num)withinitialValuesset tonullandepsilonset tonull. -
Series
public Series(@Nullable @Nullable Collection<T> initialValues, int maximumLength, @Nullable @Nullable NumFactory numFactory, @Nullable @Nullable Num epsilon) Instantiates a newSeries.- Parameters:
initialValues- the initialCollectionof values, ornullfor no initial valuesmaximumLength- thegetMaximumLength()numFactory- thegetNumFactory(), ornullforDecimalNum.decimalNum64Factory()epsilon- thegetEpsilon(), ornullforNumFactory.zero()
-
-
Method Details
-
replaceLast
-
add
-
add
Adds the givenvalueto thisSeries. -
get
Gets the value at the givenindex. If the givenindexis less thangetStartIndex(), thengetStartIndex()is used.- Parameters:
index- the index- Returns:
- the
Seriesvalue - Throws:
IndexOutOfBoundsException- thrown if the index is outside the range of thisSeries
-
getFirst
Callsget(long)withgetStartIndex().- Returns:
- the first value in this
Series
-
getLast
Callsget(long)withgetEndIndex().- Returns:
- the last value in this
Series
-
getLength
public long getLength()Gets the number of values in thisSeries, which changes due togetMaximumLength().- Returns:
- the length of this
Series
-
isEmpty
public boolean isEmpty()- Returns:
trueif empty,falseotherwise
-
listView
- Returns:
- the
Listview
-
numOf
Convenience method forgetNumFactory()NumFactory.of(Number). -
numOf
Convenience method forgetNumFactory()NumFactory.of(BigDecimal). -
numOf
Convenience method forgetNumFactory()NumFactory.of(String). -
numOf
Convenience method forgetNumFactory()NumFactory.of(Num). -
getMaximumLength
public int getMaximumLength() -
getNumFactory
-
getEpsilon
-
getStartIndex
public long getStartIndex()The index of the first value in thisSeries, which changes due togetMaximumLength(). This will be-1ifisEmpty()istrue. -
getEndIndex
public long getEndIndex()The index of the last value in thisSeries, which changes due togetMaximumLength(). This will be-1ifisEmpty()istrue. -
getAddCallCount
public long getAddCallCount()Gets the number of timesadd(Object, boolean)has been called. Use to track if thisSeriesmay have changed in any way. Number may overflow.
-