public abstract class PrimitiveType<T> extends NonNullFieldType<T>
name, NAME_PATTERN, REFERENCE_TYPE_NAME, signature, typeToken
Modifier | Constructor and Description |
---|---|
protected |
PrimitiveType(Primitive<T> primitive) |
Modifier and Type | Method and Description |
---|---|
int |
compare(T value1,
T value2)
Order two field values.
|
<S> T |
convert(FieldType<S> type,
S value)
|
protected abstract T |
convertNumber(Number value) |
boolean |
equals(Object obj) |
T |
fromParseableString(ParseContext ctx)
Parse a value previously encoded by
toParseableString() as a self-delimited String
and positioned at the start of the given parsing context. |
int |
hashCode() |
String |
toParseableString(T value)
Encode a possibly null value as a
String for later decoding by fromParseableString() . |
T |
validate(Object obj)
Verify the given object is a valid instance of this
FieldType 's Java type and cast it to that type. |
fromString, genericizeForIndex, getDefaultValue, getDefaultValueObject, getEncodingSignature, getKeyRange, getName, getTypeToken, hasPrefix0x00, hasPrefix0xff, read, skip, toString, toString, validateAndWrite, write
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 T fromParseableString(ParseContext ctx)
FieldType
toParseableString()
as a self-delimited String
and positioned at the start of the given parsing context.fromParseableString
in class FieldType<T>
ctx
- parse context starting with a string previously encoded via toParseableString()
public String toParseableString(T 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<T>
value
- actual value (possibly null)value
acceptable to fromParseableString()
public T 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<T>
obj
- object to validateobj
cast to this field's typepublic int compare(T value1, T 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 <S> T convert(FieldType<S> type, S value)
FieldType
FieldType
into a value of this FieldType
.
For a non-null value
, the implementation in FieldType
first checks whether the value
is already
a valid value for this type; if so, the value is returned. Otherwise, it invokes type.
toString(value)
to convert value
into a String
, and then attempts to parse that string via
this.
fromString()
; if the parse fails, an IllegalArgumentException
is thrown.
If value
is null, the implementation in FieldType
returns null, unless this type does not support null
values, in which case an IllegalArgumentException
is thrown.
Special handling also exists for certain conversions between built-in types:
value != 0
char
and a String
of length one are convertible (other String
s are not)char[]
array and a String
are convertibleCopyright © 2022. All rights reserved.