Class EnumValueEncoding

All Implemented Interfaces:
Encoding<EnumValue>, NaturalSortAware, Serializable, Comparator<EnumValue>

public class EnumValueEncoding extends NullSafeEncoding<EnumValue>
The Encoding for EnumValue, which is the data type used by EnumField.

Each EnumValueEncoding instance has an ordered list of String identifiers; two EnumValueEncoding instances are not compatible unless they have identical identifier lists. The identifiers must be valid Java identifiers.

Note that whatever Enum type may be used to represent values at the Java layer is unimportant; only the ordered list of identifiers matters.

Null values are supported by this class.

See Also:
  • Field Details

  • Constructor Details

    • EnumValueEncoding

      public EnumValueEncoding(Class<T> enumType)
      Constructor that derives the type name and identifier list from the given Enum type.
      Type Parameters:
      T - enum type
      Parameters:
      enumType - Java Enum type from which to derive type name and ordered identifier list
      Throws:
      NullPointerException - if enumType is null
    • EnumValueEncoding

      public EnumValueEncoding(List<String> idents)
      Primary constructor.
      Parameters:
      idents - ordered list of identifiers
      Throws:
      IllegalArgumentException - if name is null or invalid
      IllegalArgumentException - if idents is null or contains a duplicate or invalid identifier
  • Method Details

    • getIdentifiers

      public List<String> getIdentifiers()
      Get the identifiers associated with this instance in ordinal order.
      Returns:
      unmodifiable, ordinally ordered list of identifiers
    • validateIdentifiers

      public static Map<String,EnumValue> validateIdentifiers(List<String> idents)
      Validate a list of enum identifiers and build a mapping from identifier to corresponding EnumValue. The returned mapping will iterate the EnumValues in ordinal order.
      Parameters:
      idents - enum identifiers
      Returns:
      ordinally ordered mapping from identifier to EnumValue
      Throws:
      IllegalArgumentException - if idents is null
      IllegalArgumentException - if any identifier in idents is null, duplicate, or not a valid Java identifier