- java.lang.Object
-
- com.pervasive.datarush.tokens.scalar.BinaryToken
-
- All Implemented Interfaces:
DataToken
,BinaryValued
,ScalarToken
,ScalarValued
,TokenValued
,ScalarTyped
,TokenTyped
,Serializable
,Comparable<BinaryToken>
public final class BinaryToken extends Object implements ScalarToken, Comparable<BinaryToken>
An immutableBinaryValued
object.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static BinaryToken
NULL
A null valuedBinaryToken
static BinaryToken
ZERO
A zero valuedBinaryToken
static byte[]
ZERO_VALUE
The byte array representing a zero value, the emptybyte[]
.
-
Constructor Summary
Constructors Constructor Description BinaryToken(byte[] value)
Constructs a new token with the given non-null binary value.BinaryToken(BinaryValued value)
Constructs a new token with the binary value in the given container.BinaryToken(String value)
Constructs aBinaryToken
with the non-null binary value encoded by the given hexadecimal string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
asBinary()
Gets the contained binary value.byte[]
asBinaryRef()
Gets a reference to the contained binary value.int
compareTo(BinaryToken that)
boolean
equals(Object obj)
Indicates whether another object is equal to this token.ScalarTokenType
getType()
Gets the data type of the token.int
hashCode()
Returns a hash code for the token.boolean
isNull()
Indicates whether the token is null valued.boolean
isZero()
Indicates whether the value is the zero value for the type.static BinaryToken
parse(String value)
Converts a string representation of a binary value into a token.boolean
represents(byte[] otherData)
A 'deep equals' comparison of this token's contents to the provided raw bytes.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.pervasive.datarush.tokens.scalar.ScalarValued
getType, isZero
-
Methods inherited from interface com.pervasive.datarush.tokens.TokenValued
isNull
-
-
-
-
Field Detail
-
NULL
public static final BinaryToken NULL
A null valuedBinaryToken
-
ZERO_VALUE
public static final byte[] ZERO_VALUE
The byte array representing a zero value, the emptybyte[]
.
-
ZERO
public static final BinaryToken ZERO
A zero valuedBinaryToken
-
-
Constructor Detail
-
BinaryToken
public BinaryToken(BinaryValued value)
Constructs a new token with the binary value in the given container.- Parameters:
value
- aBinaryValued
containing the desired value
-
BinaryToken
public BinaryToken(byte[] value)
Constructs a new token with the given non-null binary value. If a null valued token is desired, useNULL
.- Parameters:
value
- the binary value of the token. A copy of the array will be made.- Throws:
NullPointerException
- if the supplied array isnull
-
BinaryToken
public BinaryToken(String value)
Constructs aBinaryToken
with the non-null binary value encoded by the given hexadecimal string. If a null valued token is desired, useNULL
.- Parameters:
value
- a hexadecimal string representing the binary value- Throws:
NullPointerException
- if the supplied hexadecimal string isnull
-
-
Method Detail
-
compareTo
public int compareTo(BinaryToken that)
- Specified by:
compareTo
in interfaceComparable<BinaryToken>
-
equals
public boolean equals(Object obj)
Description copied from interface:DataToken
Indicates whether another object is equal to this token. Two null valued tokens are considered equal. This differs from the behavior ofTokenComparator.equal(TokenValued,TokenValued)
but makes it possible to storeDataToken
s inMap
s.
-
represents
public boolean represents(byte[] otherData)
A 'deep equals' comparison of this token's contents to the provided raw bytes. Implementations SHOULD use this instead of equals when comparing BinaryTokens to arrays; equals() will eventually stop recognizing byte arrays to comply with the general equals/hashcode contracts.- Parameters:
otherData
- the object that we're comparing to- Returns:
- a 'deep equals' comparison of contents with otherData
-
hashCode
public int hashCode()
Description copied from interface:DataToken
Returns a hash code for the token. This value is guaranteed to be consistent with that returned byTokenConverter.asHashCode(TokenValued)
.
-
parse
public static BinaryToken parse(String value)
Converts a string representation of a binary value into a token.- Parameters:
value
- a hexadecimal string representing a binary value- Returns:
- a token with the specified value
-
getType
public final ScalarTokenType getType()
Description copied from interface:TokenValued
Gets the data type of the token. This type will dictate the valid values that can be contained.- Specified by:
getType
in interfaceScalarTyped
- Specified by:
getType
in interfaceScalarValued
- Specified by:
getType
in interfaceTokenTyped
- Specified by:
getType
in interfaceTokenValued
- Returns:
- the token type.
-
asBinary
public final byte[] asBinary()
Description copied from interface:BinaryValued
Gets the contained binary value.The array returned is a copy of the binary data contained in the object. To avoid this overhead, use
BinaryValued.asBinaryRef()
instead.- Specified by:
asBinary
in interfaceBinaryValued
- Returns:
- the contained value as a
byte[]
. If null valued, as indicated byTokenValued.isNull()
,null
is returned.
-
asBinaryRef
public final byte[] asBinaryRef()
Description copied from interface:BinaryValued
Gets a reference to the contained binary value.While this call avoids the overhead seen with
BinaryValued.asBinary()
, the caller must guarantee that the returned array will not be modified. Failure to comply may result in the dataflow exhibiting unexpected behavior, as other operators may (or may not) see the modified value.- Specified by:
asBinaryRef
in interfaceBinaryValued
- Returns:
- a reference to the
byte[]
holding the contained value. If null valued, as indicated byTokenValued.isNull()
,null
is returned.
-
isZero
public final boolean isZero()
Description copied from interface:ScalarValued
Indicates whether the value is the zero value for the type. Zero values are not stored in sparse representation formats.- Specified by:
isZero
in interfaceScalarValued
- Returns:
true
if the value is the zero value,false
otherwise.
-
isNull
public final boolean isNull()
Description copied from interface:TokenValued
Indicates whether the token is null valued. Tokens support null values analogous to SQL. Before accessing the value of the container, it is usually best to ensure it is not null valued using this method.- Specified by:
isNull
in interfaceTokenValued
- Returns:
true
if the token is null valued,false
otherwise
-
-