Class ReferenceEncoding
- All Implemented Interfaces:
Encoding<ObjId>,NaturalSortAware,Serializable,Comparator<ObjId>
Encoding for ReferenceFields. 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_SENTINELFields inherited from class io.permazen.encoding.AbstractEncoding
encodingId, typeTokenFields inherited from interface io.permazen.encoding.Encoding
MAX_ARRAY_DIMENSIONS -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.ReferenceEncoding(Schema schema, Set<ObjType> objectTypes) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncheckAllowed(ObjId id) Verify the reference target is permitted by this instance.<S> ObjIdbooleanGet the object types this encoding is allowed to reference, if so restricted.inthashCode()toString()Verify the given object is a valid instance of thisEncoding's Java type and cast it to that type.voidwrite(ByteData.Writer 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, toStringMethods inherited from class io.permazen.encoding.AbstractEncoding
getDefaultValue, getDefaultValueBytes, getEncodingId, getTypeTokenMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongMethods inherited from interface io.permazen.encoding.Encoding
decode, encode, 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- ifschemais 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:EncodingWrite a value to the given output. -
validate
Description copied from interface:EncodingVerify 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, notClassCastExceptionorNullPointerException, ifobjdoes 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
IntegertoLong.The implementation in
Encodingfirst 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:
objcast to this encoding's type
-
checkAllowed
Verify the reference target is permitted by this instance.- Parameters:
id- reference value- Returns:
idafter successful validation- Throws:
InvalidReferenceException- ifidhas a storage ID that is not allowed by this instance
-
convert
Attempt to convert a value from the givenEncodinginto a value of thisEncoding.The only conversion supported by
ReferenceEncodingis to/fromObjId. -
toString
- Overrides:
toStringin classAbstractEncoding<ObjId>
-
equals
- Specified by:
equalsin interfaceComparator<ObjId>- Overrides:
equalsin classNullSafeEncoding<ObjId>
-
hashCode
public int hashCode()- Overrides:
hashCodein classNullSafeEncoding<ObjId>
-