Record Class AttrOption<T>

java.lang.Object
java.lang.Record
com.iohao.net.common.kit.attr.AttrOption<T>
Type Parameters:
T - The type of the attribute value
All Implemented Interfaces:
Serializable

public record AttrOption<T>(String name, T defaultValue, Supplier<T> supplier) extends Record implements Serializable
Type-safe attribute key for use with AttrOptionDynamic. Supports default values and lazy initialization via Supplier.
Author:
渔民小镇
See Also:
date:
2022-01-31
  • Constructor Summary

    Constructors
    Constructor
    Description
    AttrOption(String name, T defaultValue, Supplier<T> supplier)
    Creates an instance of a AttrOption record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the defaultValue record component.
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns a hash code value for this object.
    Returns the value of the name record component.
    Returns the value of the supplier record component.
    final String
    Returns a string representation of this record class.
    static <T> AttrOption<T>
    Create an attribute option with no default value.
    static <T> AttrOption<T>
    valueOf(String name, Supplier<T> supplier)
    Create an attribute option with a lazy default value supplier.
    static <T> AttrOption<T>
    valueOf(String name, T defaultValue)
    Create an attribute option with a static default value.

    Methods inherited from class Object

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

    • AttrOption

      public AttrOption(String name, T defaultValue, Supplier<T> supplier)
      Creates an instance of a AttrOption record class.
      Parameters:
      name - the value for the name record component
      defaultValue - the value for the defaultValue record component
      supplier - the value for the supplier record component
  • Method Details

    • valueOf

      public static <T> AttrOption<T> valueOf(String name)
      Create an attribute option with no default value.
      Type Parameters:
      T - the type of the attribute value
      Parameters:
      name - the unique name identifying this attribute option
      Returns:
      a new AttrOption instance with no default
    • valueOf

      public static <T> AttrOption<T> valueOf(String name, T defaultValue)
      Create an attribute option with a static default value.
      Type Parameters:
      T - the type of the attribute value
      Parameters:
      name - the unique name identifying this attribute option
      defaultValue - the default value returned when no explicit value is set
      Returns:
      a new AttrOption instance with the given default
    • valueOf

      public static <T> AttrOption<T> valueOf(String name, Supplier<T> supplier)
      Create an attribute option with a lazy default value supplier.
      Type Parameters:
      T - the type of the attribute value
      Parameters:
      name - the unique name identifying this attribute option
      supplier - supplier invoked to produce the default value when none is set
      Returns:
      a new AttrOption instance with the given supplier
    • equals

      public 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.
    • hashCode

      public 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
    • 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
    • name

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

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

      public Supplier<T> supplier()
      Returns the value of the supplier record component.
      Returns:
      the value of the supplier record component