Class AbstractEncoding<T>

java.lang.Object
io.permazen.encoding.AbstractEncoding<T>
Type Parameters:
T - The associated Java type
All Implemented Interfaces:
Encoding<T>, NaturalSortAware, Serializable, Comparator<T>
Direct Known Subclasses:
ArrayEncoding, BigDecimalEncoding, BigIntegerEncoding, BitSetEncoding, ConvertedEncoding, DateEncoding, DurationEncoding, Inet4AddressEncoding, Inet6AddressEncoding, InetAddressEncoding, InstantEncoding, LocalDateEncoding, LocalDateTimeEncoding, LocalTimeEncoding, MonthDayEncoding, NullSafeEncoding, ObjIdEncoding, PeriodEncoding, PrimitiveEncoding, StringEncoding, TupleEncoding, UnsignedIntEncoding, UUIDEncoding, YearEncoding, YearMonthEncoding, ZoneOffsetEncoding

public abstract class AbstractEncoding<T> extends Object implements Encoding<T>, Serializable
Support superclass for Encoding implementations.

Instances are Serializable if their default value suppliers are.

See Also:
  • Field Details

    • encodingId

      protected final EncodingId encodingId
    • typeToken

      protected final TypeToken<T> typeToken
  • Constructor Details

    • AbstractEncoding

      protected AbstractEncoding(EncodingId encodingId, TypeToken<T> typeToken, Supplier<? extends T> defaultValueSupplier)
      Constructor.
      Parameters:
      encodingId - encoding ID for this encoding, or null to be anonymous
      typeToken - Java type for this encoding's values
      defaultValueSupplier - supplies the default value for this encoding; must supply null if this encoding supports nulls; may be null if this encoding has no default value
      Throws:
      IllegalArgumentException - if typeToken is null
    • AbstractEncoding

      protected AbstractEncoding(EncodingId encodingId, Class<T> type, Supplier<? extends T> defaultValueSupplier)
      Constructor.
      Parameters:
      encodingId - encoding ID for this encoding, or null to be anonymous
      type - Java type for this encoding's values
      defaultValueSupplier - supplies the default value for this encoding; must supply null if this encoding supports nulls; may be null if this encoding has no default value
      Throws:
      IllegalArgumentException - if type is null
    • AbstractEncoding

      protected AbstractEncoding(TypeToken<T> type)
      Constructor for anonymous encodings with no default value.
      Parameters:
      type - Java type for this encoding's values
      Throws:
      IllegalArgumentException - if type is null
    • AbstractEncoding

      protected AbstractEncoding(Class<T> type)
      Constructor for anonymous encodings with no default value.
      Parameters:
      type - Java type for this encoding's values
      Throws:
      IllegalArgumentException - if type is null
  • Method Details

    • getEncodingId

      public final EncodingId getEncodingId()
      Description copied from interface: Encoding
      Get the globally unique encoding ID that identifies this encoding, if any.

      Once associated with a specific encoding, an encoding ID must never be changed or reused. If an Encoding's encoding changes in any way, then its encoding ID must also change. This applies only to the encoding itself, and not the associated Java type. For example, an Encoding's associated Java type can change over time, e.g., if the Java class changes package or class name.

      Specified by:
      getEncodingId in interface Encoding<T>
      Returns:
      this encoding's unique ID, or null if this encoding is anonymous
    • getTypeToken

      public final TypeToken<T> getTypeToken()
      Description copied from interface: Encoding
      Get the Java type corresponding to this encoding's values.
      Specified by:
      getTypeToken in interface Encoding<T>
      Returns:
      the Java type used to represent this encoding's values
    • getDefaultValue

      public final T getDefaultValue()
      Description copied from interface: Encoding
      Get the default value for this encoding.

      If this encoding supports null values, then this must return null.

      Specified by:
      getDefaultValue in interface Encoding<T>
      Returns:
      default value
    • getDefaultValueBytes

      public byte[] getDefaultValueBytes()
      Description copied from interface: Encoding
      Get the default value for this encoding encoded as a byte[] array.

      The implementation in Encoding returns the binary encoding of the value returned by Encoding.getDefaultValue().

      Specified by:
      getDefaultValueBytes in interface Encoding<T>
      Returns:
      encoded default value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Comparator<T>
      Overrides:
      equals in class Object