Class EnumPreferenceType<E extends Enum<E>>

java.lang.Object
dev.mintychochip.mint.preferences.types.EnumPreferenceType<E>
Type Parameters:
E - the enum type
All Implemented Interfaces:
PreferenceType<E>

@Experimental @AvailableSince("1.3") public final class EnumPreferenceType<E extends Enum<E>> extends Object implements PreferenceType<E>
A preference type for enum values.

Serializes enum values as their constant names and provides support for selection dialogs in the UI.

Since:
1.3
  • Constructor Details

    • EnumPreferenceType

      @AvailableSince("1.3") public EnumPreferenceType(Class<E> enumClass)
      Creates a new enum preference type for the specified enum class.
      Parameters:
      enumClass - the enum class, must not be null and must be an enum type
      Throws:
      IllegalArgumentException - if enumClass is null or not an enum
  • Method Details

    • deserialize

      @AvailableSince("1.3") public E deserialize(byte[] object)
      Description copied from interface: PreferenceType
      Deserializes a byte array into an object.
      Specified by:
      deserialize in interface PreferenceType<E extends Enum<E>>
      Parameters:
      object - the byte array to deserialize
      Returns:
      the deserialized value
    • serialize

      @AvailableSince("1.3") public byte[] serialize(E object)
      Description copied from interface: PreferenceType
      Serializes an object into a byte array.
      Specified by:
      serialize in interface PreferenceType<E extends Enum<E>>
      Parameters:
      object - the object to serialize
      Returns:
      the serialized byte array
    • preferenceClass

      @AvailableSince("1.3") public Class<E> preferenceClass()
      Description copied from interface: PreferenceType
      Gets the class this preference type handles.
      Specified by:
      preferenceClass in interface PreferenceType<E extends Enum<E>>
      Returns:
      the preference class