Record Class BlockProperty.Choice<E extends Enum<E>>

java.lang.Object
java.lang.Record
fr.fidorial.world.block.BlockProperty.Choice<E>
Type Parameters:
E - the enum
Record Components:
name - the property name
type - the enum
values - the accepted constants, in state order
All Implemented Interfaces:
BlockProperty<E>
Enclosing interface:
BlockProperty<T>

public static record BlockProperty.Choice<E extends Enum<E>>(String name, Class<E extends Enum<E>> type, List<E extends Enum<E>> values) extends Record implements BlockProperty<E>
A property taking some constants of an enum, each written as its lowercased name.
Since:
0.1.0
  • Constructor Details

    • Choice

      public Choice(String name, Class<E> type, List<E> values)
      Creates an instance of a Choice record class.
      Parameters:
      name - the value for the name record component
      type - the value for the type record component
      values - the value for the values record component
  • Method Details

    • of

      public static <E extends Enum<E>> BlockProperty.Choice<E> of(String name, Class<E> type)
      Returns a property accepting every constant of an enum.
      Type Parameters:
      E - the enum
      Parameters:
      name - the property name
      type - the enum
      Returns:
      a property accepting every constant of an enum
      Since:
      0.1.0
    • of

      @SafeVarargs public static <E extends Enum<E>> BlockProperty.Choice<E> of(String name, Class<E> type, E... values)
      Returns a property accepting some constants of an enum.
      Type Parameters:
      E - the enum
      Parameters:
      name - the property name
      type - the enum
      values - the accepted constants, in state order
      Returns:
      a property accepting some constants of an enum
      Since:
      0.1.0
    • nameOf

      public String nameOf(E value)
      Description copied from interface: BlockProperty
      Returns the name a value is written as.
      Specified by:
      nameOf in interface BlockProperty<E extends Enum<E>>
      Parameters:
      value - an accepted value
      Returns:
      the name a value is written as
    • parse

      public @Nullable E parse(String name)
      Description copied from interface: BlockProperty
      Returns the value written as a name, null if none is.
      Specified by:
      parse in interface BlockProperty<E extends Enum<E>>
      Parameters:
      name - the written value
      Returns:
      the value written as a name, null if none is
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Specified by:
      name in interface BlockProperty<E extends Enum<E>>
      Returns:
      the value of the name record component
    • type

      public Class<E> type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • values

      public List<E> values()
      Returns the value of the values record component.
      Specified by:
      values in interface BlockProperty<E extends Enum<E>>
      Returns:
      the value of the values record component