Class TupleEncoding<T extends Tuple>
- All Implemented Interfaces:
Encoding<T>
,NaturalSortAware
,Serializable
,Comparator<T>
- Direct Known Subclasses:
Tuple2Encoding
,Tuple3Encoding
,Tuple4Encoding
,Tuple5Encoding
- See Also:
-
Field Summary
Fields inherited from class io.permazen.encoding.AbstractEncoding
encodingId, typeToken
Fields inherited from interface io.permazen.encoding.Encoding
MAX_ARRAY_DIMENSIONS
-
Constructor Summary
ModifierConstructorDescriptionprotected
TupleEncoding
(EncodingId encodingId, TypeToken<T> typeToken, Encoding<?>... encodings) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionint
Order two field values.protected abstract T
createTuple
(Object[] values) fromString
(String string) Parse a non-null value previously encoded bytoString(T)
.int
getSize()
Get the number of component encodings in this encoding.boolean
Determine whether any of this encoding's encoded values start with a0x00
byte.boolean
Determine whether any of this encoding's encoded values start with a0xff
byte.read
(ByteReader reader) Read a value from the given input.void
skip
(ByteReader reader) Read and discard abyte[]
encoded value from the given input.Encode a non-null value as aString
for later decoding byfromString()
.void
write
(ByteWriter writer, T tuple) Write a value to the given output.Methods inherited from class io.permazen.encoding.AbstractEncoding
equals, getDefaultValueObject, getEncodingId, getTypeToken, hashCode, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface io.permazen.encoding.Encoding
convert, decode, encode, getDefaultValue, getKeyRange, sortsNaturally, supportsNull, validate, validateAndWrite, withEncodingId
-
Constructor Details
-
TupleEncoding
Constructor.- Parameters:
encodingId
- encoding ID, or null for an anonymous instancetypeToken
- this encoding's composite value typeencodings
- encodings to concatenate- Throws:
IllegalArgumentException
- iftypeToken
orencodings
is null
-
-
Method Details
-
getSize
public int getSize()Get the number of component encodings in this encoding.- Returns:
- number of component encodings
-
read
Description copied from interface:Encoding
Read a value from the given input.- Parameters:
reader
- byte input- Returns:
- field value (possibly null)
-
write
Description copied from interface:Encoding
Write a value to the given output.- Parameters:
writer
- byte outputtuple
- value to write (possibly null)
-
skip
Description copied from interface:Encoding
Read and discard abyte[]
encoded value from the given input.- Parameters:
reader
- byte input
-
toString
Description copied from interface:Encoding
Encode a non-null value as aString
for later decoding byfromString()
.Each of the characters in the returned
String
must be one of the valid XML characters (tab, newline, carriage return,\u0020 - \ud7ff
, and\ue000 - \ufffd
).- Parameters:
tuple
- actual value, never null- Returns:
- string encoding of
value
acceptable tofromString()
- See Also:
-
fromString
Description copied from interface:Encoding
Parse a non-null value previously encoded bytoString(T)
.- Parameters:
string
- non-null value previously encoded as aString
bytoString(T)
- Returns:
- actual value
-
compare
Description copied from interface:Encoding
Order two field values.This method must provide a total ordering of all supported Java values that is consistent with the database ordering, i.e., the unsigned lexicographical ordering of the corresponding
byte[]
encoded field values.If null is a supported Java value, then the this method must accept null parameters without throwing an exception (note, this is a stronger requirement than the
Comparator
interface normally requires).Note: by convention, null values usually sort last.
-
hasPrefix0xff
public boolean hasPrefix0xff()Description copied from interface:Encoding
Determine whether any of this encoding's encoded values start with a0xff
byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.
The implementation in
Encoding
returnstrue
.- Returns:
- true if an encoded value starting with
0xff
exists
-
hasPrefix0x00
public boolean hasPrefix0x00()Description copied from interface:Encoding
Determine whether any of this encoding's encoded values start with a0x00
byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.
The implementation in
Encoding
returnstrue
.- Returns:
- true if an encoded value starting with
0x00
exists
-
createTuple
-