Class DataComponentMap
java.lang.Object
fr.fidorial.item.data.DataComponentMap
An immutable patch over an item's default components.
- Since:
- 0.1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAccumulates several component changes without allocating a patch per step. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic DataComponentMap.Builderbuilder()Set<Map.Entry<DataComponentType<?>, Object>> entries()boolean<T> @Nullable Tget(DataComponentType<T> type) Looks up a component.<T> TgetOrDefault(DataComponentType<T> type, T fallback) Looks up a component, falling back when it is absent.booleanhas(DataComponentType<?> type) inthashCode()booleanisEmpty()booleanisRemoved(DataComponentType<?> type) Set<DataComponentType<?>> reset(DataComponentType<?> type) Drops this patch's opinion on a component entirely, letting the item's default show through again.intsize()toString()<T> DataComponentMapwith(DataComponentType<T> type, T value) Sets a component, replacing any previous value and cancelling a pending removal.without(DataComponentType<?> type) Removes the item's default for a component, and clears any value this patch set.
-
Field Details
-
EMPTY
-
-
Method Details
-
builder
- Returns:
- a new builder starting from the empty patch
-
get
Looks up a component.- Type Parameters:
T- the component's value type- Parameters:
type- the component to read- Returns:
- the patched value, or
nullif this patch neither sets nor removes it
-
getOrDefault
Looks up a component, falling back when it is absent.- Type Parameters:
T- the component's value type- Parameters:
type- the component to readfallback- returned when the component is not set by this patch- Returns:
- the patched value, or
fallback
-
has
- Parameters:
type- the component to test- Returns:
trueif this patch sets the component
-
isRemoved
- Parameters:
type- the component to test- Returns:
trueif this patch explicitly removes the item's default
-
with
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 setvalue- the value to set it to- Returns:
- a new patch
-
without
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
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
- Returns:
- the added/overridden components, in insertion order
-
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:
trueif this patch adds nothing and removes nothing
-
toBuilder
- Returns:
- a builder pre-populated with this patch
-
equals
-
hashCode
-
toString
-