Module datarush.library
Class SparseNumericTokenList
- java.lang.Object
-
- com.pervasive.datarush.sequences.scalar.SparseNumericTokenList
-
- All Implemented Interfaces:
MutableTokenSequence
,MutableNumericTokenSequence
,MutableScalarTokenSequence
,NumericTokenSequence
,ScalarTokenAppendable
,ScalarTokenSequence
,TokenAppendable
,TokenSequence
,ScalarTyped
,TokenTyped
public final class SparseNumericTokenList extends Object implements MutableNumericTokenSequence
An implementation ofMutableNumericTokenSequence
which stores data sparsely. That is, zero values are not stored. This is a much more efficient mechanism when the majority of values are zero.
-
-
Constructor Summary
Constructors Constructor Description SparseNumericTokenList(int initialCapacity)
Creates a new empty list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(TokenSequence data)
Appends all tokens in the specified sequence to this sequence.void
append(TokenSequence data, int start, int length)
Appends a subsequence of tokens in the specified sequence to this sequence.void
append(TokenValued value)
Appends the specified token value to this sequence.void
append(TokenValued value, long count)
Appends the specified token value to this sequence multiple times.void
append(BigDecimal value)
Appends the specified BigDecimal to this sequence.void
append(BigDecimal value, int count)
Appends the specified BigDecimal to this sequence multiple times.void
appendDouble(double value)
Appends the specified double to this sequence.void
appendLong(long value)
Appends the specified long to this sequence.void
appendNull()
Append a null value to this sequence.void
appendNull(int count)
Append a null value to this sequence.void
appendZero()
Appends a zero value to this sequence.void
appendZero(int count)
Appends the specified number of zero values to this sequence.int
compareElement(int absoluteIndex, TokenValued value)
Compares the value of the specified token to the token at which the given port is positioned.int
compareElements(int lhsAbsoluteIndex, int rhsAbsoluteIndex)
Compares the values of the tokens at the specified positions.void
ensureCanonical()
Ensures that the internal representation is in a canonical form such that it can be read safely by multiple threads.void
fillValue(int start, int length, TokenValued value)
Sets the tokens in the specified subsequence to the given value.BigDecimal
getBigDecimal(int index)
Gets the value of the specified token as aBigDecimal
.ElementComparator
getElementComparator(TokenOrder sortOrder)
Gets anElementComparator
for this sequence using the specified ordering.long
getModificationCount()
Returns the current modification count.NumericValued
getToken(int index)
Gets the value at the specified position.NumericSettable
getTokenSetter(int index)
Returns a mutator for the given index.ScalarTokenType
getType()
Gets the data type of the tokens in the sequence.void
getValues(int start, BigDecimal[] values, boolean[] nulls, int offset, int length)
Gets the values and null indicators for a range of tokens asBigDecimal
objects.int
hashCode(int absoluteIndex)
Gets the hash code for the token at the specified position.boolean
isNull()
Returns whether all elements are null.boolean
isNull(int absoluteIndex)
Indicates whether the specified token has a null value.boolean
isZero(int absoluteIndex)
Indicates whether the specified token has a zero value.NumericValuedIterator
newValueIterator()
Creates an iterator over the non-null values of this sequence.void
reset()
Removes all elements from the sequence.void
setBigDecimal(int absoluteIndex, BigDecimal value)
Sets the token at the specified position to the given value.void
setNull(int absoluteIndex)
Sets the token at the specified position to be null valued.void
setNull(int start, int length)
Sets the tokens in the specified subsequence to be null valued.void
setValue(int absoluteIndex, TokenValued value)
Sets the token at the specified position to the given value.void
setValues(int start, TokenSequence values, int offset, int length)
Sets the tokens in the specified subsequence of the array to the corresponding values from a subsequence of the given source sequence.void
setZero(int absoluteIndex)
Sets the token at the specified position to be zero valued.void
setZero(int start, int length)
Sets the tokens in the specified subsequence to be zero valued.int
size()
Gets the length of the sequence.String
toString()
String
toString(int absoluteIndex)
Gets the string representation of the token at the specified position.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.pervasive.datarush.sequences.scalar.MutableScalarTokenSequence
ensureCanonical, getModificationCount
-
Methods inherited from interface com.pervasive.datarush.sequences.MutableTokenSequence
appendNull, appendNull, appendZero, appendZero, fillValue, reset, setNull, setNull, setValue, setValues, setZero, setZero
-
Methods inherited from interface com.pervasive.datarush.sequences.scalar.ScalarTokenSequence
getType, isNull, isZero
-
Methods inherited from interface com.pervasive.datarush.sequences.TokenAppendable
append, append, append, append
-
Methods inherited from interface com.pervasive.datarush.sequences.TokenSequence
compareElement, compareElements, getElementComparator, hashCode, isNull, size, toString
-
-
-
-
Method Detail
-
append
public void append(BigDecimal value)
Description copied from interface:MutableNumericTokenSequence
Appends the specified BigDecimal to this sequence.- Specified by:
append
in interfaceMutableNumericTokenSequence
- Parameters:
value
- the value to append. Ifnull
, this is equivalent toappendNull()
.
-
appendDouble
public void appendDouble(double value)
Description copied from interface:MutableNumericTokenSequence
Appends the specified double to this sequence.- Specified by:
appendDouble
in interfaceMutableNumericTokenSequence
- Parameters:
value
- the value to append. IfDouble.NaN
, this is equivalent toappendNull()
.
-
appendLong
public void appendLong(long value)
Description copied from interface:MutableNumericTokenSequence
Appends the specified long to this sequence.- Specified by:
appendLong
in interfaceMutableNumericTokenSequence
- Parameters:
value
- the value to append.
-
append
public void append(BigDecimal value, int count)
Description copied from interface:MutableNumericTokenSequence
Appends the specified BigDecimal to this sequence multiple times.- Specified by:
append
in interfaceMutableNumericTokenSequence
- Parameters:
value
- the value to append. Ifnull
, this is equivalent toappendNull(count)
.count
- the number of copies to append.
-
setBigDecimal
public void setBigDecimal(int absoluteIndex, BigDecimal value)
Description copied from interface:MutableNumericTokenSequence
Sets the token at the specified position to the given value.- Specified by:
setBigDecimal
in interfaceMutableNumericTokenSequence
- Parameters:
absoluteIndex
- the position to modifyvalue
- the new value
-
getBigDecimal
public BigDecimal getBigDecimal(int index)
Description copied from interface:NumericTokenSequence
Gets the value of the specified token as aBigDecimal
.- Specified by:
getBigDecimal
in interfaceNumericTokenSequence
- Parameters:
index
- the position of the token in the sequence- Returns:
- the value of the token. If the
token is null valued,
null
is returned.
-
getToken
public NumericValued getToken(int index)
Description copied from interface:TokenSequence
Gets the value at the specified position.- Specified by:
getToken
in interfaceNumericTokenSequence
- Specified by:
getToken
in interfaceScalarTokenSequence
- Specified by:
getToken
in interfaceTokenSequence
- Parameters:
index
- the index of the token- Returns:
- the value
-
getTokenSetter
public NumericSettable getTokenSetter(int index)
Description copied from interface:MutableTokenSequence
Returns a mutator for the given index.- Specified by:
getTokenSetter
in interfaceMutableNumericTokenSequence
- Specified by:
getTokenSetter
in interfaceMutableScalarTokenSequence
- Specified by:
getTokenSetter
in interfaceMutableTokenSequence
- Parameters:
index
- the position- Returns:
- a mutator for the given index.
-
getValues
public void getValues(int start, BigDecimal[] values, boolean[] nulls, int offset, int length)
Description copied from interface:NumericTokenSequence
Gets the values and null indicators for a range of tokens asBigDecimal
objects.- Specified by:
getValues
in interfaceNumericTokenSequence
- Parameters:
start
- the starting index of the rangevalues
- an array into which to place element valuesnulls
- an array into which to place null indicator valuesoffset
- the starting offset into the target arrays. That is,elements[offset]
andnulls[offset]
will get the value and null indicator respectively of the token at positionstart
, and so on.length
- number of tokens to get
-
newValueIterator
public NumericValuedIterator newValueIterator()
Description copied from interface:TokenSequence
Creates an iterator over the non-null values of this sequence. The iterator will automatically be reset as modifications are made to the sequence.- Specified by:
newValueIterator
in interfaceNumericTokenSequence
- Specified by:
newValueIterator
in interfaceScalarTokenSequence
- Specified by:
newValueIterator
in interfaceTokenSequence
- Returns:
- an newly-created iterator over the non-null values of this sequence.
-
isNull
public final boolean isNull()
Description copied from interface:ScalarTokenSequence
Returns whether all elements are null.- Specified by:
isNull
in interfaceScalarTokenSequence
- Returns:
- whether all elements are null.
-
getModificationCount
public final long getModificationCount()
Description copied from interface:MutableScalarTokenSequence
Returns the current modification count. Modification count must be strictly increasing.- Specified by:
getModificationCount
in interfaceMutableScalarTokenSequence
- Returns:
- the current change sequence number
-
size
public final int size()
Description copied from interface:TokenSequence
Gets the length of the sequence.- Specified by:
size
in interfaceTokenSequence
- Returns:
- the number of tokens in the sequence.
-
setZero
public final void setZero(int absoluteIndex)
Description copied from interface:MutableTokenSequence
Sets the token at the specified position to be zero valued.- Specified by:
setZero
in interfaceMutableTokenSequence
- Parameters:
absoluteIndex
- the position of the token in the array
-
setZero
public void setZero(int start, int length)
Description copied from interface:MutableTokenSequence
Sets the tokens in the specified subsequence to be zero valued.- Specified by:
setZero
in interfaceMutableTokenSequence
- Parameters:
start
- the starting index of the subsequence in the arraylength
- the length of the subsequence
-
setNull
public final void setNull(int absoluteIndex)
Description copied from interface:MutableTokenSequence
Sets the token at the specified position to be null valued.- Specified by:
setNull
in interfaceMutableTokenSequence
- Parameters:
absoluteIndex
- the position of the token in the array
-
setNull
public final void setNull(int start, int length)
Description copied from interface:MutableTokenSequence
Sets the tokens in the specified subsequence to be null valued.- Specified by:
setNull
in interfaceMutableTokenSequence
- Parameters:
start
- the starting index of the subsequence in the arraylength
- the length of the subsequence
-
getType
public ScalarTokenType getType()
Description copied from interface:ScalarTokenSequence
Gets the data type of the tokens in the sequence.- Specified by:
getType
in interfaceScalarTokenSequence
- Specified by:
getType
in interfaceScalarTyped
- Specified by:
getType
in interfaceTokenTyped
- Returns:
- the token data type
-
isNull
public final boolean isNull(int absoluteIndex)
Description copied from interface:TokenSequence
Indicates whether the specified token has a null value.- Specified by:
isNull
in interfaceTokenSequence
- Parameters:
absoluteIndex
- the index of the token- Returns:
true
if the element is null,false
otherwise
-
isZero
public final boolean isZero(int absoluteIndex)
Description copied from interface:ScalarTokenSequence
Indicates whether the specified token has a zero value.- Specified by:
isZero
in interfaceScalarTokenSequence
- Parameters:
absoluteIndex
- the index of the token- Returns:
true
if the element is zero,false
otherwise
-
compareElement
public final int compareElement(int absoluteIndex, TokenValued value)
Description copied from interface:TokenSequence
Compares the value of the specified token to the token at which the given port is positioned.- Specified by:
compareElement
in interfaceTokenSequence
- Parameters:
absoluteIndex
- the index of the tokenvalue
- the input port positioned at the token for comparison- Returns:
0
if the values are equal,1
if the sequence token value is greater,-1
if the sequence token value is lesser. A null value is greater than any other non-null; two null values compare as equal.
-
compareElements
public final int compareElements(int lhsAbsoluteIndex, int rhsAbsoluteIndex)
Description copied from interface:TokenSequence
Compares the values of the tokens at the specified positions.- Specified by:
compareElements
in interfaceTokenSequence
- Parameters:
lhsAbsoluteIndex
- the index of the left-hand elementrhsAbsoluteIndex
- the index of the right-hand element- Returns:
0
if the values are equal,1
if the left hand value is greater,-1
if the left hand value is lesser. A null value is greater than any other non-null; two null values compare as equal.
-
getElementComparator
public final ElementComparator getElementComparator(TokenOrder sortOrder)
Description copied from interface:TokenSequence
Gets anElementComparator
for this sequence using the specified ordering.- Specified by:
getElementComparator
in interfaceTokenSequence
- Parameters:
sortOrder
- the desired ordering- Returns:
- an
ElementComparator
for this sequence.
-
hashCode
public final int hashCode(int absoluteIndex)
Description copied from interface:TokenSequence
Gets the hash code for the token at the specified position.- Specified by:
hashCode
in interfaceTokenSequence
- Parameters:
absoluteIndex
- the index of the token- Returns:
- the hash code for the token
-
toString
public final String toString(int absoluteIndex)
Description copied from interface:TokenSequence
Gets the string representation of the token at the specified position.- Specified by:
toString
in interfaceTokenSequence
- Parameters:
absoluteIndex
- the index of the token- Returns:
- the string representation of the token
-
appendNull
public final void appendNull()
Append a null value to this sequence.- Specified by:
appendNull
in interfaceMutableTokenSequence
-
appendNull
public final void appendNull(int count)
Append a null value to this sequence.- Specified by:
appendNull
in interfaceMutableTokenSequence
- Parameters:
count
- the number of null values to append
-
appendZero
public final void appendZero()
Description copied from interface:MutableTokenSequence
Appends a zero value to this sequence.- Specified by:
appendZero
in interfaceMutableTokenSequence
-
appendZero
public void appendZero(int count)
Description copied from interface:MutableTokenSequence
Appends the specified number of zero values to this sequence.- Specified by:
appendZero
in interfaceMutableTokenSequence
- Parameters:
count
- the number of zero values to append
-
reset
public final void reset()
Description copied from interface:MutableTokenSequence
Removes all elements from the sequence.- Specified by:
reset
in interfaceMutableTokenSequence
-
append
public final void append(TokenValued value)
Description copied from interface:TokenAppendable
Appends the specified token value to this sequence.The data types of the sequence and the value must be compatible. If the types are not identical, appropriate coercion will be attempted.
- Specified by:
append
in interfaceTokenAppendable
- Parameters:
value
- the token value to append
-
append
public final void append(TokenValued value, long count)
Description copied from interface:TokenAppendable
Appends the specified token value to this sequence multiple times.The data types of the sequence and the value must be compatible. If the types are not identical, appropriate coercion will be attempted.
- Specified by:
append
in interfaceTokenAppendable
- Parameters:
value
- the token value to appendcount
- the number of copies to append
-
setValue
public final void setValue(int absoluteIndex, TokenValued value)
Description copied from interface:MutableTokenSequence
Sets the token at the specified position to the given value.- Specified by:
setValue
in interfaceMutableTokenSequence
- Parameters:
absoluteIndex
- the position of the token in the arrayvalue
- the value to which to set the token. This value must be of an appropriate type for the array.
-
fillValue
public final void fillValue(int start, int length, TokenValued value)
Description copied from interface:MutableTokenSequence
Sets the tokens in the specified subsequence to the given value.- Specified by:
fillValue
in interfaceMutableTokenSequence
- Parameters:
start
- the starting index of the subsequence in the arraylength
- the length of the subsequencevalue
- the value to which to set the tokens. This value must be of an appropriate type for the array
-
setValues
public final void setValues(int start, TokenSequence values, int offset, int length)
Description copied from interface:MutableTokenSequence
Sets the tokens in the specified subsequence of the array to the corresponding values from a subsequence of the given source sequence.- Specified by:
setValues
in interfaceMutableTokenSequence
- Parameters:
start
- the starting index of the subsequence in the arrayvalues
- the source sequence. This sequence must be of an appropriate type for the array.offset
- the starting index in the source sequence. Corresponding values will be taken relative to this position. That is, the value of the token at positionoffset
invalues
will be assigned to the token at positionstart
, and so on.length
- the number of tokens to copy
-
append
public final void append(TokenSequence data)
Description copied from interface:TokenAppendable
Appends all tokens in the specified sequence to this sequence.The data types of the sequences must be compatible. If not identical, appropriate coercion will be attempted.
- Specified by:
append
in interfaceTokenAppendable
- Parameters:
data
- the sequence to append
-
append
public final void append(TokenSequence data, int start, int length)
Description copied from interface:TokenAppendable
Appends a subsequence of tokens in the specified sequence to this sequence.The data types of the sequences must be compatible. If not identical, appropriate coercion will be attempted.
- Specified by:
append
in interfaceTokenAppendable
- Parameters:
data
- the sequence containing tokens to appendstart
- the starting index of the subsequence in the sourcelength
- the length of the subsequence
-
ensureCanonical
public final void ensureCanonical()
Description copied from interface:MutableScalarTokenSequence
Ensures that the internal representation is in a canonical form such that it can be read safely by multiple threads.- Specified by:
ensureCanonical
in interfaceMutableScalarTokenSequence
-
-