Class ReferenceEncoding
- All Implemented Interfaces:
Encoding<ObjId>
,NaturalSortAware
,Serializable
,Comparator<ObjId>
Encoding
for ReferenceField
s. Instances support object type restriction.
Binary encoding uses the value from ObjId.getBytes()
, or 0xff
to represent null.
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
ConstructorDescriptionConstructor.ReferenceEncoding
(Schema schema, Set<ObjType> objectTypes) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncheckAllowed
(ObjId id) Verify the reference target is permitted by this instance.<S> ObjId
boolean
Get the object types this encoding is allowed to reference, if so restricted.int
hashCode()
toString()
Verify the given object is a valid instance of thisEncoding
's Java type and cast it to that type.void
write
(ByteWriter writer, ObjId id) Write a value to the given output.Methods inherited from class io.permazen.encoding.NullSafeEncoding
compare, fromString, getFixedWidth, getInnerEncoding, hasPrefix0x00, hasPrefix0xff, read, skip, sortsNaturally, supportsNull, toString
Methods inherited from class io.permazen.encoding.AbstractEncoding
getDefaultValue, getDefaultValueBytes, getEncodingId, getTypeToken
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, validateAndWrite
-
Constructor Details
-
ReferenceEncoding
public ReferenceEncoding()Constructor.No restrictions will be placed on encoded references.
-
ReferenceEncoding
Constructor.- Parameters:
schema
- associated schemaobjectTypes
- allowed object type storage IDs, or null for no restriction- Throws:
IllegalArgumentException
- ifschema
is null
-
-
Method Details
-
getObjectTypes
Get the object types this encoding is allowed to reference, if so restricted.- Returns:
- allowed object types, or null if there is no restriction
-
write
Description copied from interface:Encoding
Write a value to the given output. -
validate
Description copied from interface:Encoding
Verify the given object is a valid instance of thisEncoding
's Java type and cast it to that type.Note that this method must throw
IllegalArgumentException
, notClassCastException
orNullPointerException
, ifobj
does not have the correct type, or is an unsupported value - including null if null is not supported.This method is allowed to perform widening conversions of the object that lose no information, e.g., from
Integer
toLong
.The implementation in
Encoding
first verifies the value is not null if this instance does not allow null values, and then attempts to cast the value using this instance's raw Java type. Subclasses should override this method to implement any other restrictions.- Parameters:
obj
- object to validate- Returns:
obj
cast to this encoding's type
-
checkAllowed
Verify the reference target is permitted by this instance.- Parameters:
id
- reference value- Returns:
id
after successful validation- Throws:
InvalidReferenceException
- ifid
has a storage ID that is not allowed by this instance
-
convert
Attempt to convert a value from the givenEncoding
into a value of thisEncoding
.The only conversion supported by
ReferenceEncoding
is to/fromObjId
. -
toString
- Overrides:
toString
in classAbstractEncoding<ObjId>
-
equals
- Specified by:
equals
in interfaceComparator<ObjId>
- Overrides:
equals
in classNullSafeEncoding<ObjId>
-
hashCode
public int hashCode()- Overrides:
hashCode
in classNullSafeEncoding<ObjId>
-