Package net.kyori.adventure.util
Interface InheritanceAwareMap<C,V>
- Type Parameters:
C
- the base class typeV
- the value type
public interface InheritanceAwareMap<C,V>
A map type that will traverse class hierarchy to find a value for a key.
These maps are null-hostile, so both keys and values must not be null.
There is a concept of strict mode, where map values have to be strictly non-ambiguous. When this enabled (by default it is not), a value will not be added if any subtypes or supertypes are already registered to the map.
Inheritance aware maps are always immutable, so any mutation operations will apply any changes to a new, modified instance.
- Since:
- 4.17.0
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A builder for inheritance-aware maps. -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
E> @NotNull InheritanceAwareMap.Builder<K, E> builder()
Create a new builder for an inheritance aware map.static <K,
E> @NotNull InheritanceAwareMap.Builder<K, E> builder
(InheritanceAwareMap<? extends K, ? extends E> existing) Create a new builder for an inheritance aware map.boolean
containsKey
(@NotNull Class<? extends C> clazz) Check whether this map contains a value (direct or computed) for the provided class.static <K,
E> @NotNull InheritanceAwareMap<K, E> empty()
Get an empty inheritance aware map.Get the applicable value for the provided class.@NotNull InheritanceAwareMap<C,
V> Get an updated inheritance aware map with the provided key changed.@NotNull InheritanceAwareMap<C,
V> Get an updated inheritance aware map with the provided key removed.
-
Method Details
-
empty
Get an empty inheritance aware map.- Type Parameters:
K
- class type upper boundE
- value type- Returns:
- the map
- Since:
- 4.17.0
-
builder
Create a new builder for an inheritance aware map.- Type Parameters:
K
- class type upper boundE
- value type- Returns:
- a new builder
- Since:
- 4.17.0
-
builder
static <K,E> @NotNull InheritanceAwareMap.Builder<K,E> builder(InheritanceAwareMap<? extends K, ? extends E> existing) Create a new builder for an inheritance aware map.- Type Parameters:
K
- class type upper boundE
- value type- Parameters:
existing
- the existing map to populate the builder with- Returns:
- a new builder
- Since:
- 4.17.0
-
containsKey
Check whether this map contains a value (direct or computed) for the provided class.- Parameters:
clazz
- the class type to check- Returns:
- whether such a value is present
- Since:
- 4.17.0
-
get
Get the applicable value for the provided class.This can be either a direct or inherited value.
- Parameters:
clazz
- the class type- Returns:
- the value, if any is available
- Since:
- 4.17.0
-
with
@CheckReturnValue @NotNull @NotNull InheritanceAwareMap<C,V> with(@NotNull @NotNull Class<? extends C> clazz, @NotNull V value) Get an updated inheritance aware map with the provided key changed.- Parameters:
clazz
- the class typevalue
- the value to update to- Returns:
- the updated map
- Since:
- 4.17.0
-
without
@CheckReturnValue @NotNull @NotNull InheritanceAwareMap<C,V> without(@NotNull @NotNull Class<? extends C> clazz) Get an updated inheritance aware map with the provided key removed.- Parameters:
clazz
- the class type to remove a direct value for- Returns:
- the updated map
- Since:
- 4.17.0
-