Package io.permazen.encoding
Class AbstractEncoding<T>
java.lang.Object
io.permazen.encoding.AbstractEncoding<T>
- Type Parameters:
T
- The associated Java type
- All Implemented Interfaces:
Encoding<T>
,NaturalSortAware
,Serializable
,Comparator<T>
- Direct Known Subclasses:
ArrayEncoding
,BigDecimalEncoding
,BigIntegerEncoding
,BitSetEncoding
,ConvertedEncoding
,DateEncoding
,DurationEncoding
,Inet4AddressEncoding
,Inet6AddressEncoding
,InetAddressEncoding
,InstantEncoding
,LocalDateEncoding
,LocalDateTimeEncoding
,LocalTimeEncoding
,MonthDayEncoding
,NullSafeEncoding
,ObjIdEncoding
,PeriodEncoding
,PrimitiveEncoding
,StringEncoding
,TupleEncoding
,UnsignedIntEncoding
,UUIDEncoding
,YearEncoding
,YearMonthEncoding
,ZoneOffsetEncoding
Support superclass for
Encoding
implementations.
Instances are Serializable
if their default value suppliers are.
- See Also:
-
Field Summary
Fields inherited from interface io.permazen.encoding.Encoding
MAX_ARRAY_DIMENSIONS
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractEncoding
(TypeToken<T> type) Constructor for anonymous encodings with no default value.protected
AbstractEncoding
(EncodingId encodingId, TypeToken<T> typeToken, Supplier<? extends T> defaultValueSupplier) Constructor.protected
AbstractEncoding
(EncodingId encodingId, Class<T> type, Supplier<? extends T> defaultValueSupplier) Constructor.protected
AbstractEncoding
(Class<T> type) Constructor for anonymous encodings with no default value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
final T
Get the default value for this encoding.byte[]
Get the default value for this encoding encoded as abyte[]
array.final EncodingId
Get the globally unique encoding ID that identifies this encoding, if any.Get the Java type corresponding to this encoding's values.int
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
compare, convert, decode, encode, fromString, getFixedWidth, getKeyRange, hasPrefix0x00, hasPrefix0xff, read, skip, supportsNull, toString, validate, validateAndWrite, write
Methods inherited from interface io.permazen.util.NaturalSortAware
sortsNaturally
-
Field Details
-
encodingId
-
typeToken
-
-
Constructor Details
-
AbstractEncoding
protected AbstractEncoding(EncodingId encodingId, TypeToken<T> typeToken, Supplier<? extends T> defaultValueSupplier) Constructor.- Parameters:
encodingId
- encoding ID for this encoding, or null to be anonymoustypeToken
- Java type for this encoding's valuesdefaultValueSupplier
- supplies the default value for this encoding; must supply null if this encoding supports nulls; may be null if this encoding has no default value- Throws:
IllegalArgumentException
- iftypeToken
is null
-
AbstractEncoding
protected AbstractEncoding(EncodingId encodingId, Class<T> type, Supplier<? extends T> defaultValueSupplier) Constructor.- Parameters:
encodingId
- encoding ID for this encoding, or null to be anonymoustype
- Java type for this encoding's valuesdefaultValueSupplier
- supplies the default value for this encoding; must supply null if this encoding supports nulls; may be null if this encoding has no default value- Throws:
IllegalArgumentException
- iftype
is null
-
AbstractEncoding
Constructor for anonymous encodings with no default value.- Parameters:
type
- Java type for this encoding's values- Throws:
IllegalArgumentException
- iftype
is null
-
AbstractEncoding
Constructor for anonymous encodings with no default value.- Parameters:
type
- Java type for this encoding's values- Throws:
IllegalArgumentException
- iftype
is null
-
-
Method Details
-
getEncodingId
Description copied from interface:Encoding
Get the globally unique encoding ID that identifies this encoding, if any.Once associated with a specific encoding, an encoding ID must never be changed or reused. If an
Encoding
's encoding changes in any way, then its encoding ID must also change. This applies only to the encoding itself, and not the associated Java type. For example, anEncoding
's associated Java type can change over time, e.g., if the Java class changes package or class name.- Specified by:
getEncodingId
in interfaceEncoding<T>
- Returns:
- this encoding's unique ID, or null if this encoding is anonymous
-
getTypeToken
Description copied from interface:Encoding
Get the Java type corresponding to this encoding's values.- Specified by:
getTypeToken
in interfaceEncoding<T>
- Returns:
- the Java type used to represent this encoding's values
-
getDefaultValue
Description copied from interface:Encoding
Get the default value for this encoding.If this encoding supports null values, then this must return null.
- Specified by:
getDefaultValue
in interfaceEncoding<T>
- Returns:
- default value
-
getDefaultValueBytes
public byte[] getDefaultValueBytes()Description copied from interface:Encoding
Get the default value for this encoding encoded as abyte[]
array.The implementation in
Encoding
returns the binary encoding of the value returned byEncoding.getDefaultValue()
.- Specified by:
getDefaultValueBytes
in interfaceEncoding<T>
- Returns:
- encoded default value
-
toString
-
hashCode
public int hashCode() -
equals
- Specified by:
equals
in interfaceComparator<T>
- Overrides:
equals
in classObject
-