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, OffsetDateTimeEncoding, OffsetTimeEncoding, PeriodEncoding, PrimitiveEncoding, StringEncoding, TupleEncoding, UnsignedIntEncoding, UUIDEncoding, YearEncoding, YearMonthEncoding, ZonedDateTimeEncoding, ZoneOffsetEncoding

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

Instances are Serializable if their default values are (typically the default value is null, making this the case).

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, T defaultValue)
      Constructor.
      Parameters:
      encodingId - encoding ID for this encoding, or null to be anonymous
      typeToken - Java type for the field's values
      defaultValue - default value for this encoding
      Throws:
      IllegalArgumentException - if any parameter is null
      IllegalArgumentException - if name is invalid
    • AbstractEncoding

      protected AbstractEncoding(EncodingId encodingId, Class<T> type, T defaultValue)
      Constructor.
      Parameters:
      encodingId - encoding ID for this encoding, or null to be anonymous
      type - Java type for the field's values
      defaultValue - default value for this encoding
      Throws:
      IllegalArgumentException - if any parameter is null
      IllegalArgumentException - if name is invalid
  • 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
    • getDefaultValueObject

      public final T getDefaultValueObject()
      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:
      getDefaultValueObject in interface Encoding<T>
      Returns:
      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