Package io.permazen.core
Class EnumValueEncoding
- All Implemented Interfaces:
Encoding<EnumValue>
,NaturalSortAware
,Serializable
,Comparator<EnumValue>
The
Encoding
for EnumValue
, which is the data type used by EnumField
.
Each EnumValueEncoding
instance has an ordered list of String
identifiers; two EnumValueEncoding
instances are not compatible unless they have identical identifier lists. The identifiers must be valid Java identifiers.
Note that whatever Enum
type may be used to represent values at the Java layer is unimportant;
only the ordered list of identifiers matters.
Null values are supported by this class.
- See Also:
-
Field Summary
Fields inherited from class io.permazen.encoding.NullSafeEncoding
inner, NOT_NULL_SENTINEL, NULL_SENTINEL
Fields inherited from class io.permazen.encoding.AbstractEncoding
encodingId, typeToken
Fields inherited from interface io.permazen.encoding.Encoding
MAX_ARRAY_DIMENSIONS
-
Constructor Summary
ConstructorDescriptionEnumValueEncoding
(Class<T> enumType) Constructor that derives the type name and identifier list from the givenEnum
type.EnumValueEncoding
(List<String> idents) Primary constructor. -
Method Summary
Modifier and TypeMethodDescriptionGet the identifiers associated with this instance in ordinal order.validateIdentifiers
(List<String> idents) Validate a list of enum identifiers and build a mapping from identifier to correspondingEnumValue
.Methods inherited from class io.permazen.encoding.NullSafeEncoding
compare, convert, equals, fromString, getFixedWidth, getInnerEncoding, hashCode, hasPrefix0x00, hasPrefix0xff, read, skip, sortsNaturally, supportsNull, toString, write
Methods inherited from class io.permazen.encoding.AbstractEncoding
getDefaultValue, getDefaultValueBytes, getEncodingId, getTypeToken, 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
decode, encode, getKeyRange, validate, validateAndWrite
-
Field Details
-
IDENT_PATTERN
- See Also:
-
-
Constructor Details
-
EnumValueEncoding
Constructor that derives the type name and identifier list from the givenEnum
type.- Type Parameters:
T
- enum type- Parameters:
enumType
- JavaEnum
type from which to derive type name and ordered identifier list- Throws:
NullPointerException
- ifenumType
is null
-
EnumValueEncoding
Primary constructor.- Parameters:
idents
- ordered list of identifiers- Throws:
IllegalArgumentException
- ifname
is null or invalidIllegalArgumentException
- ifidents
is null or contains a duplicate or invalid identifier
-
-
Method Details
-
getIdentifiers
Get the identifiers associated with this instance in ordinal order.- Returns:
- unmodifiable, ordinally ordered list of identifiers
-
validateIdentifiers
Validate a list of enum identifiers and build a mapping from identifier to correspondingEnumValue
. The returned mapping will iterate theEnumValue
s in ordinal order.- Parameters:
idents
- enum identifiers- Returns:
- ordinally ordered mapping from identifier to
EnumValue
- Throws:
IllegalArgumentException
- ifidents
is nullIllegalArgumentException
- if any identifier inidents
is null, duplicate, or not a valid Java identifier
-