Package io.permazen.encoding
Class SimpleEncodingRegistry
java.lang.Object
io.permazen.encoding.SimpleEncodingRegistry
- All Implemented Interfaces:
EncodingRegistry
- Direct Known Subclasses:
DefaultEncodingRegistry
A straightforward
EncodingRegistry
implementation that creates object array types on demand.
The add()
method only accepts non-array types and primitive array types. All other
array types are automatically created on demand via buildArrayEncoding()
.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a newEncoding
to this registry.<T> boolean
addNullSafe
(EncodingId encodingId, Encoding<T> inner) Add a null-safe version of the given non-null supportingEncoding
to this registry.static <E> Encoding<E[]>
buildArrayEncoding
(Encoding<E> elementEncoding) Build an array encoding for the given element encoding using Permazen's default array encoding.Encoding<?>
getEncoding
(EncodingId encodingId) Get theEncoding
with the given encoding ID in this registry.getEncodings
(TypeToken<T> typeToken) Get all of theEncoding
s in this registry that supports values of the given Java type.protected void
register
(EncodingId encodingId, Encoding<?> encoding) Register a newEncoding
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.permazen.encoding.EncodingRegistry
aliasForId, getEncoding, getEncoding, idForAlias
-
Field Details
-
log
-
-
Constructor Details
-
SimpleEncodingRegistry
public SimpleEncodingRegistry()
-
-
Method Details
-
add
Add a newEncoding
to this registry.The type's encoding ID must not contain any array dimensions except for single dimension primitive array types.
- Parameters:
encoding
- theEncoding
to register- Returns:
- true if it was added, false if it was already registered
- Throws:
IllegalArgumentException
- ifencoding
is nullIllegalArgumentException
- ifencoding
's encoding ID is null (i.e.,encoding
is anonymous)IllegalArgumentException
- ifencoding
's encoding ID conflicts with an existing, but different, encodingIllegalArgumentException
- ifencoding
's encoding ID has one or more array dimensions
-
addNullSafe
Add a null-safe version of the given non-null supportingEncoding
to this registry.The
encoding
is wrapped in aNullSafeEncoding
to add null value support.- Parameters:
encodingId
- the ID for the newly added encodinginner
- the inner non-null supportingEncoding
- Returns:
- true if it was added, false if it was already registered
- Throws:
IllegalArgumentException
- ifinner
orencodingId
is nullIllegalArgumentException
- ifinner
's encoding ID conflicts with an existing, but different, encodingIllegalArgumentException
- ifinner
's encoding ID has one or more array dimensionsIllegalArgumentException
- ifinner
already supports null values
-
buildArrayEncoding
Build an array encoding for the given element encoding using Permazen's default array encoding.The element encoding must represent a non-primitive type. This method uses the generic array encoding provided by
ObjectArrayEncoding
, wrapped viaNullSafeEncoding
.If
elementEncoding
is anonymous, so will be the returned encoding, otherwise the returned encoding'sEncodingId
will be equal toelementEncoding.
getArrayId()
.- Parameters:
elementEncoding
- element encoding- Returns:
- corresponding array encoding
- Throws:
IllegalArgumentException
- ifelementEncoding
is nullIllegalArgumentException
- ifelementEncoding
encodes a primitive typeIllegalArgumentException
- ifelementEncoding
encodes an array type with 255 dimensions
-
getEncoding
Description copied from interface:EncodingRegistry
Get theEncoding
with the given encoding ID in this registry.- Specified by:
getEncoding
in interfaceEncodingRegistry
- Parameters:
encodingId
- encoding ID- Returns:
- corresponding
Encoding
, if any, otherwise null
-
getEncodings
Description copied from interface:EncodingRegistry
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.- Specified by:
getEncodings
in interfaceEncodingRegistry
- Type Parameters:
T
- encoding value type- Parameters:
typeToken
- encoding value type- Returns:
- unmodifiable list of
Encoding
s supporting Java values of typetypeToken
, possibly empty
-
register
Register a newEncoding
.- Parameters:
encodingId
- encoding ID under which to register the new encodingencoding
- the new encoding to register- Throws:
IllegalArgumentException
- if either parameter is nullIllegalArgumentException
- if there is already a encoding registered underencodingId
IllegalArgumentException
- ifencoding
is anonymous or has an encoding ID different fromencodingId
-