Class DataComponentMap

java.lang.Object
fr.fidorial.item.data.DataComponentMap

public final class DataComponentMap extends Object
An immutable patch over an item's default components.
Since:
0.1.0
  • Field Details

  • Method Details

    • builder

      public static DataComponentMap.Builder builder()
      Returns:
      a new builder starting from the empty patch
    • get

      public <T> @Nullable T get(DataComponentType<T> type)
      Looks up a component.
      Type Parameters:
      T - the component's value type
      Parameters:
      type - the component to read
      Returns:
      the patched value, or null if this patch neither sets nor removes it
    • getOrDefault

      public <T> T getOrDefault(DataComponentType<T> type, T fallback)
      Looks up a component, falling back when it is absent.
      Type Parameters:
      T - the component's value type
      Parameters:
      type - the component to read
      fallback - returned when the component is not set by this patch
      Returns:
      the patched value, or fallback
    • has

      public boolean has(DataComponentType<?> type)
      Parameters:
      type - the component to test
      Returns:
      true if this patch sets the component
    • isRemoved

      public boolean isRemoved(DataComponentType<?> type)
      Parameters:
      type - the component to test
      Returns:
      true if this patch explicitly removes the item's default
    • with

      public <T> DataComponentMap with(DataComponentType<T> type, T value)
      Sets a component, replacing any previous value and cancelling a pending removal.
      Type Parameters:
      T - the component's value type
      Parameters:
      type - the component to set
      value - the value to set it to
      Returns:
      a new patch
    • without

      public DataComponentMap without(DataComponentType<?> type)
      Removes the item's default for a component, and clears any value this patch set.

      This is not the same as reset(DataComponentType): the component ends up absent from the item, not merely back at its default.

      Parameters:
      type - the component to remove
      Returns:
      a new patch
    • reset

      public DataComponentMap reset(DataComponentType<?> type)
      Drops this patch's opinion on a component entirely, letting the item's default show through again.
      Parameters:
      type - the component to reset
      Returns:
      a new patch
    • entries

      public Set<Map.Entry<DataComponentType<?>, Object>> entries()
      Returns:
      the added/overridden components, in insertion order
    • removedTypes

      public Set<DataComponentType<?>> removedTypes()
      Returns:
      the component types this patch removes, in insertion order
    • size

      public int size()
      Returns:
      the number of added/overridden components
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this patch adds nothing and removes nothing
    • toBuilder

      public DataComponentMap.Builder toBuilder()
      Returns:
      a builder pre-populated with this patch
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object