Interface EncodingRegistry
- All Known Implementing Classes:
DefaultEncodingRegistry
,SimpleEncodingRegistry
Encoding
s.
Encoding
s in an EncodingRegistry
can be looked up by EncodingId
or by Java type.
Multiple Encoding
s may support the same Java type, so only the EncodingId
lookup is
guaranteed to be unique.
Note: Enum
types are not directly handled in the core API layer; instead, the appropriate
EnumValueEncoding
must be used to encode values as EnumValue
s.
Instances must be thread safe.
-
Method Summary
Modifier and TypeMethodDescriptiondefault String
aliasForId
(EncodingId encodingId) Get the alias (or "nickname") for the given encoding ID in this registry, if any.default <T> Encoding<T>
getEncoding
(TypeToken<T> typeToken) Get the uniqueEncoding
in this registry that supports values of the given Java type.Encoding<?>
getEncoding
(EncodingId encodingId) Get theEncoding
with the given encoding ID in this registry.default <T> Encoding<T>
getEncoding
(Class<T> type) Get the uniqueEncoding
in this registry that supports values of the given Java type.getEncodings
(TypeToken<T> typeToken) Get all of theEncoding
s in this registry that supports values of the given Java type.default EncodingId
idForAlias
(String alias) Get the encoding ID corresponding to the given alias (or "nickname"), if any.
-
Method Details
-
getEncoding
Get theEncoding
with the given encoding ID in this registry.- Parameters:
encodingId
- encoding ID- Returns:
- corresponding
Encoding
, if any, otherwise null - Throws:
IllegalArgumentException
- ifencodingId
is null
-
idForAlias
Get the encoding ID corresponding to the given alias (or "nickname"), if any.See
aliasForId()
for details on aliases.If
alias
is a valid alias, this method should return the correspondingEncodingId
. Ifalias
is not a valid alias, but is a valid encoding ID in string form, this method should return the correspondingEncodingId
as if bynew EncodingId(alias)
. Otherwise, this method should throwIllegalArgumentException
.Note: the
EncodingId
corresponding to an alias does not need to be actually registered with this instance in order for the alias to be valid.The implementation in
EncodingRegistry
just invokesnew EncodingId(alias)
.- Parameters:
alias
- encoding ID alias- Returns:
- corresponding encoding ID, never null
- Throws:
IllegalArgumentException
- ifalias
is null or not a valid alias
-
aliasForId
Get the alias (or "nickname") for the given encoding ID in this registry, if any.An
EncodingRegistry
may support aliases for some of its encoding ID's. Aliases are simply more friendly names forEncodingId
strings, which are formatted as Uniform Resource Names (URNs).Whereas
EncodingId
's are globally unique, aliases are only meaningful to the particularEncodingRegistry
instance being queried. When a schema is recorded in a database, actualEncodingId
's are always used.In Permazen's
DefaultEncodingRegistry
, the built-in encodings all have aliases; for example,"int"
is an alias for"urn:fdc:permazen.io:2020:int"
. Permazen's built-in encoding aliases are available viaEncodingIds.aliasForId()
andEncodingIds.idForAlias()
.If no alias is known for
encodingId
, this method should returnEncodingId.getId()
.Note: an
EncodingId
does not need to be actually registered with this instance in order for it to have an alias.The implementation in
EncodingRegistry
always returnsEncodingId.getId()
.- Parameters:
encodingId
- encoding ID- Returns:
- corresponding alias, if any, otherwise
EncodingId.getId()
- Throws:
IllegalArgumentException
- ifencodingId
is null- See Also:
-
getEncodings
Get all of theEncoding
s in this registry that supports values of the given Java type.The Java type must exactly match the
Encoding
's supported Java type.- Type Parameters:
T
- encoding value type- Parameters:
typeToken
- encoding value type- Returns:
- unmodifiable list of
Encoding
s supporting Java values of typetypeToken
, possibly empty - Throws:
IllegalArgumentException
- iftypeToken
is null
-
getEncoding
Get the uniqueEncoding
in this registry that supports values of the given Java type.The Java type must exactly match the
Encoding
's supported Java type and there must be exactly one suchEncoding
, otherwise anIllegalArgumentException
is thrown.- Type Parameters:
T
- encoding value type- Parameters:
typeToken
- encoding value type- Returns:
Encoding
supporting Java values of typetypeToken
- Throws:
IllegalArgumentException
- iftypeToken
is nullIllegalArgumentException
- if noEncoding
s supportstypeToken
IllegalArgumentException
- if more than oneEncoding
supportstypeToken
-
getEncoding
Get the uniqueEncoding
in this registry that supports values of the given Java type.This is a convenience method, equivalent to:
getEncoding(TypeToken.of(type))
.- Type Parameters:
T
- encoding value type- Parameters:
type
- encoding value type- Returns:
Encoding
supporting Java values of typetype
- Throws:
IllegalArgumentException
- iftype
is nullIllegalArgumentException
- if noEncoding
s supportstype
IllegalArgumentException
- if more than oneEncoding
supportstype
-