Record Class TypedKey<T>

java.lang.Object
java.lang.Record
fr.fidorial.registry.TypedKey<T>
Type Parameters:
T - the type of the entry
Record Components:
registry - the registry the key belongs to
key - the key of the entry

public record TypedKey<T>(RegistryKey<T> registry, Key key) extends Record
A key bound to the registry it belongs to, so lookups are type-safe.
Since:
0.1.0
  • Constructor Details

    • TypedKey

      public TypedKey(RegistryKey<T> registry, Key key)
      Validates the components.
  • Method Details

    • create

      public static <T> TypedKey<T> create(RegistryKey<T> registry, Key key)
      Returns a key of the given registry.
      Type Parameters:
      T - the type of the entry
      Parameters:
      registry - the registry
      key - the key of the entry
      Returns:
      a key of the given registry
      Since:
      0.1.0
    • create

      public static <T> TypedKey<T> create(RegistryKey<T> registry, @KeyPattern String key)
      Returns a key of the given registry.
      Type Parameters:
      T - the type of the entry
      Parameters:
      registry - the registry
      key - the key of the entry, for instance minecraft:stone
      Returns:
      a key of the given registry
      Since:
      0.1.0
    • toString

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

      public RegistryKey<T> registry()
      Returns the value of the registry record component.
      Returns:
      the value of the registry record component
    • key

      public Key key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component