Record Class ItemMarker<P,C>

java.lang.Object
java.lang.Record
com.ultikits.ultitools.item.ItemMarker<P,C>
Type Parameters:
P - primitive storage type
C - complex value type
Record Components:
key - persistent-data key
type - value codec
value - value to store

public record ItemMarker<P,C>(org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<P,C> type, C value) extends Record
A persistent-data value written onto the rendered stack (ItemStack#editPersistentDataContainer).

Deeply immutable and value-equal: an array value (of any component type) is copied in the constructor and on every value() call; a List value is copied with List.copyOf after its elements are frozen the same way. Equality and hash code compare array contents deeply and lists element by element. A PersistentDataContainer value, an array of them, or a list containing one is rejected, because a container is mutable and has no value equality; store a key or a byte array instead. A value of a module-defined complex type must itself be immutable with value equals; otherwise equal specs compare unequal and a GUI re-renders.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.bukkit.NamespacedKey
    The field for the key record component.
    private final org.bukkit.persistence.PersistentDataType<P,C>
    The field for the type record component.
    private final C
    The field for the value record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ItemMarker(org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<P,C> type, C value)
    Rejects nulls and container values, and freezes supported aggregate values.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static <T> T
    copy(T value)
     
    boolean
    equals(Object other)
    Compares array contents deeply and list elements by value.
    private static boolean
    equalValues(Object first, Object second)
     
    private static Object
    freeze(Object value)
     
    private static Object
     
    private static List<Object>
    freezeList(List<?> list)
     
    int
    Returns a content-based hash matching equals(Object).
    org.bukkit.NamespacedKey
    key()
    Returns the value of the key record component.
    Returns record-style diagnostics with array contents rather than array identities.
    org.bukkit.persistence.PersistentDataType<P,C>
    Returns the value of the type record component.
    Returns the value, defensively copying arrays and aggregate elements on every call.
    private static int
     
    private static String
     

    Methods inherited from class Object

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

    • key

      private final org.bukkit.NamespacedKey key
      The field for the key record component.
    • type

      private final org.bukkit.persistence.PersistentDataType<P,C> type
      The field for the type record component.
    • value

      private final C value
      The field for the value record component.
  • Constructor Details

    • ItemMarker

      public ItemMarker(org.bukkit.NamespacedKey key, org.bukkit.persistence.PersistentDataType<P,C> type, C value)
      Rejects nulls and container values, and freezes supported aggregate values.
      Throws:
      IllegalArgumentException - for a container value
  • Method Details

    • value

      public C value()
      Returns the value, defensively copying arrays and aggregate elements on every call.
    • equals

      public boolean equals(Object other)
      Compares array contents deeply and list elements by value.
      Specified by:
      equals in class Record
    • hashCode

      public int hashCode()
      Returns a content-based hash matching equals(Object).
      Specified by:
      hashCode in class Record
    • toString

      public String toString()
      Returns record-style diagnostics with array contents rather than array identities.
      Specified by:
      toString in class Record
    • copy

      private static <T> T copy(T value)
    • freeze

      private static Object freeze(Object value)
    • freezeList

      private static List<Object> freezeList(List<?> list)
    • freezeArray

      private static Object freezeArray(Object value)
    • equalValues

      private static boolean equalValues(Object first, Object second)
    • valueHash

      private static int valueHash(Object value)
    • valueText

      private static String valueText(Object value)
    • key

      public org.bukkit.NamespacedKey key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • type

      public org.bukkit.persistence.PersistentDataType<P,C> type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component