public class EnumType extends NonNullFieldType<EnumValue>
FieldType
for EnumFieldType
.
Binary encoding is via the UnsignedIntEncoder
-encoded ordinal value.
name, NAME_PATTERN, REFERENCE_TYPE_NAME, signature, typeToken
Modifier and Type | Method and Description |
---|---|
int |
compare(EnumValue value1,
EnumValue value2)
Order two field values.
|
boolean |
equals(Object obj) |
EnumValue |
fromParseableString(ParseContext context)
Parse a value previously encoded by
toParseableString() as a self-delimited String
and positioned at the start of the given parsing context. |
EnumValue |
fromString(String string)
Parse a non-null value previously encoded by
toString(T) . |
int |
hashCode() |
boolean |
hasPrefix0xff()
Determine whether any of this field type's encoded values start with a
0xff byte. |
EnumValue |
read(ByteReader reader)
Read a value from the given input.
|
void |
skip(ByteReader reader)
Read and discard a value from the given input.
|
String |
toParseableString(EnumValue value)
Encode a possibly null value as a
String for later decoding by fromParseableString() . |
String |
toString(EnumValue value)
Encode a non-null value as a
String for later decoding by fromString() . |
EnumValue |
validate(Object obj)
Verify the given object is a valid instance of this
FieldType 's Java type and cast it to that type. |
void |
write(ByteWriter writer,
EnumValue value)
Write a value to the given output.
|
convert, genericizeForIndex, getDefaultValue, getDefaultValueObject, getEncodingSignature, getKeyRange, getName, getTypeToken, hasPrefix0x00, toString, validateAndWrite
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public EnumValue read(ByteReader reader)
FieldType
public void write(ByteWriter writer, EnumValue value)
FieldType
public void skip(ByteReader reader)
FieldType
public String toString(EnumValue value)
FieldType
String
for later decoding by fromString()
.
Each of the characters in the returned String
must be one of the valid XML characters
(tab, newline, carriage return, \u0020 - \ud7ff
, and \ue000 - \fffdf
).
The implementation in FieldType
checks that value
is not null, then delegates to FieldType.toParseableString(T)
.
Subclasses that override this method should also override fromString()
.
toString
in class FieldType<EnumValue>
value
- actual value, never nullvalue
acceptable to fromString()
public EnumValue fromString(String string)
FieldType
toString(T)
.
The implementation in FieldType
creates a new ParseContext
based on string
,
delegates to FieldType.toParseableString(T)
to parse it, and verifies that all of string
was consumed
during the parse. Subclasses that override this method should also override toString(T)
.
fromString
in class FieldType<EnumValue>
string
- non-null value previously encoded as a String
by toString(T)
public String toParseableString(EnumValue value)
FieldType
String
for later decoding by fromParseableString()
.
The string value must be self-delimiting, i.e., decodable even when followed by arbitrary additional characters,
and must not start with whitespace or closing square bracket ("]"
).
In addition, each of the characters in the returned String
must be one of the valid XML characters
(tab, newline, carriage return, \u0020 - \ud7ff
, and \ue000 - \fffdf
).
toParseableString
in class FieldType<EnumValue>
value
- actual value (possibly null)value
acceptable to fromParseableString()
public EnumValue fromParseableString(ParseContext context)
FieldType
toParseableString()
as a self-delimited String
and positioned at the start of the given parsing context.fromParseableString
in class FieldType<EnumValue>
context
- parse context starting with a string previously encoded via toParseableString()
public int compare(EnumValue value1, EnumValue value2)
FieldType
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 returned Comparator
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.
public boolean hasPrefix0xff()
FieldType
0xff
byte.
Certain optimizations are possible when this is not the case. It is safe for this method to always return true.
Note: changing the return value of this method usually means changing the binary encoding, resulting in an incompatible type.
The implementation in FieldType
returns true
.
hasPrefix0xff
in class FieldType<EnumValue>
0xff
existspublic EnumValue validate(Object obj)
FieldType
FieldType
's Java type and cast it to that type.
Note that this method must throw IllegalArgumentException
, not ClassCastException
or NullPointerException
, if obj
does not have the correct type, or is an illegal null value.
This method is allowed to perform widening conversions of the object that lose no information, e.g.,
from Integer
to Long
.
The implementation in FieldType
simply casts the value using this instance's raw Java type.
Subclasses should override this method to implement any other restrictions, e.g., disallowing null values.
validate
in class NonNullFieldType<EnumValue>
obj
- object to validateobj
cast to this field's typeCopyright © 2022. All rights reserved.