Record Class Property<T>

java.lang.Object
java.lang.Record
org.teleight.teleightbots.conversation.Property<T>
Type Parameters:
T - the type of the property value.
Record Components:
name - the name of the property. Cannot be null.
value - the value of the property.
required - whether the property is required or not.

public record Property<T>(@NotNull String name, T value, boolean required) extends Record
Represents a custom property that can be used in a conversation.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Property(@NotNull String name, T value, boolean required)
    Creates an instance of a Property record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    <A> A
    as(Class<? extends A> type)
    Returns the value of the property as a custom type.
    boolean
    Returns the value of the property as a boolean.
    float
    Returns the value of the property as a double.
    int
    Returns the value of the property as an integer.
    long
    Returns the value of the property as a long.
    Returns the value of the property as a string.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    @NotNull String
    Returns the value of the name record component.
    of(@NotNull String name)
    Creates a new property with the given name.
    static <T> Property<T>
    of(String name, T value)
    Creates a new property with the given name and value.
    boolean
    Returns the value of the required record component.
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Property

      public Property(@NotNull @NotNull String name, T value, boolean required)
      Creates an instance of a Property record class.
      Parameters:
      name - the value for the name record component
      value - the value for the value record component
      required - the value for the required record component
  • Method Details

    • of

      public static Property<Integer> of(@NotNull @NotNull String name)
      Creates a new property with the given name. The returned property will have a null value and will be required.
      Parameters:
      name - the name of the property. Cannot be null.
      Returns:
      a new property with the given name.
    • of

      public static <T> Property<T> of(String name, T value)
      Creates a new property with the given name and value.
      Parameters:
      name - the name of the property. Cannot be null.
      value - the value of the property.
      Returns:
      a new property with the given name and value.
    • asString

      public String asString()
      Returns the value of the property as a string.
      Returns:
      the value of the property as a string.
    • asInt

      public int asInt()
      Returns the value of the property as an integer.
      Returns:
      the value of the property as an integer.
      Throws:
      ClassCastException - if the value cannot be cast to an integer.
    • asBool

      public boolean asBool()
      Returns the value of the property as a boolean.
      Returns:
      the value of the property as a boolean.
      Throws:
      ClassCastException - if the value cannot be cast to a boolean.
    • asLong

      public long asLong()
      Returns the value of the property as a long.
      Returns:
      the value of the property as a long.
      Throws:
      ClassCastException - if the value cannot be cast to a long.
    • asFloat

      public float asFloat()
      Returns the value of the property as a double.
      Returns:
      the value of the property as a double.
      Throws:
      ClassCastException - if the value cannot be cast to a double.
    • as

      public <A> A as(Class<? extends A> type)
      Returns the value of the property as a custom type.
      Returns:
      the value of the property as a custom type.
      Throws:
      ClassCastException - if the value cannot be cast to a custom type.
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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

      @NotNull public @NotNull String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • value

      public T value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • required

      public boolean required()
      Returns the value of the required record component.
      Returns:
      the value of the required record component