Package org.spongepowered.api.data.value
Interface Value<E>
- Type Parameters:
E
- The type of element wrapped by this value
- All Known Subinterfaces:
CollectionValue<E,
,C> CollectionValue.Immutable<E,
,C, I, M> CollectionValue.Mutable<E,
,C, M, I> ListValue<E>
,ListValue.Immutable<E>
,ListValue.Mutable<E>
,MapValue<K,
,V> MapValue.Immutable<K,
,V> MapValue.Mutable<K,
,V> SetValue<E>
,SetValue.Immutable<E>
,SetValue.Mutable<E>
,Value.Immutable<E>
,Value.Mutable<E>
,WeightedCollectionValue<E>
,WeightedCollectionValue.Immutable<E>
,WeightedCollectionValue.Mutable<E>
public interface Value<E>
The abstract base interface for all of the "Value API". In short, a
Value
is a "wrapper" around an actual value from a
ValueContainer
. The actual value may come from various sources of
the ValueContainer
, but usually it's a generic dynamic system for
being able to fetch values from object fields without having to know the
type of Class
of the ValueContainer
, the getters and
setters for that particular value. The driving force behind this is that
instead of having a traditional hierarchical structure of data that is
possible to be retrieved from an Entity
, Living
, etc.,
all that is required is container.supports(Keys.HEALTH) ?
container.get(Keys.HEALTH).get() : 0
where the container is simply
a ValueContainer
, nothing more, nothing less.
The advantage of this is that now, these various known and unknown
Value.Mutable
s can be retrieved by simple java generics:
ValueContainer.getValue(Key)
. While having a Value.Mutable
for
something so primitive as the current health of a Living
entity,
the power is wielded when a Value.Mutable
can be offered up to multiple
ValueContainer
s without worrying about whether it's supported or not,
or getting the right cast information.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
static interface
Represents an immutable representation of aValue
where any modifications of the underlying value result in a new instance of anValue.Immutable
and/or theValueContainer
if theValueContainer
too is immutable.static interface
Represents a type ofValue
that is mutable. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves an immutable form of this value.Retrieves a mutable form of this value.Retrieves a copy in the mutable form of this value.static <V extends Value<E>,
E>
VgenericImmutableOf
(Key<V> key, E element) static <V extends Value<E>,
E>
VgenericMutableOf
(Key<V> key, E element) get()
Gets the held value.static <E> ListValue.Immutable<E>
immutableOf
(Supplier<? extends Key<? extends ListValue<E>>> key, List<E> element) static <K,
V> MapValue.Immutable<K, V> immutableOf
(Supplier<? extends Key<? extends MapValue<K, V>>> key, Map<K, V> element) static <E> SetValue.Immutable<E>
immutableOf
(Supplier<? extends Key<? extends SetValue<E>>> key, Set<E> element) static <E> Value.Immutable<E>
immutableOf
(Supplier<? extends Key<? extends Value<E>>> key, E element) static <E> WeightedCollectionValue.Immutable<E>
immutableOf
(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element) Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.static <E> ListValue.Immutable<E>
immutableOf
(Key<? extends ListValue<E>> key, List<E> element) static <K,
V> MapValue.Immutable<K, V> immutableOf
(Key<? extends MapValue<K, V>> key, Map<K, V> element) static <E> SetValue.Immutable<E>
immutableOf
(Key<? extends SetValue<E>> key, Set<E> element) static <E> Value.Immutable<E>
immutableOf
(Key<? extends Value<E>> key, E element) static <E> WeightedCollectionValue.Immutable<E>
immutableOf
(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element) Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.key()
Gets the key for thisValue
.static <E> ListValue.Mutable<E>
static <K,
V> MapValue.Mutable<K, V> static <E> SetValue.Mutable<E>
static <E> Value.Mutable<E>
static <E> WeightedCollectionValue.Mutable<E>
mutableOf
(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element) Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.static <E> ListValue.Mutable<E>
static <K,
V> MapValue.Mutable<K, V> static <E> SetValue.Mutable<E>
static <E> Value.Mutable<E>
static <E> WeightedCollectionValue.Mutable<E>
mutableOf
(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element) Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.
-
Method Details
-
mutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> Value.Immutable<E> immutableOf(Supplier<? extends Key<? extends Value<E>>> key, E element) - Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
mutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> ListValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends ListValue<E>>> key, List<E> element) - Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> ListValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends ListValue<E>>> key, List<E> element) - Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
mutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> SetValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends SetValue<E>>> key, Set<E> element) - Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> SetValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends SetValue<E>>> key, Set<E> element) - Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
mutableOf
- Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <K,V> MapValue.Mutable<K,V> mutableOf(Supplier<? extends Key<? extends MapValue<K, V>>> key, Map<K, V> element) - Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
static <K,V> MapValue.Immutable<K,V> immutableOf(Key<? extends MapValue<K, V>> key, Map<K, V> element) - Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <K,V> MapValue.Immutable<K,V> immutableOf(Supplier<? extends Key<? extends MapValue<K, V>>> key, Map<K, V> element) - Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
mutableOf
static <E> WeightedCollectionValue.Mutable<E> mutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element) Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> WeightedCollectionValue.Mutable<E> mutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element) Constructs a mutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
static <E> WeightedCollectionValue.Immutable<E> immutableOf(Key<? extends WeightedCollectionValue<E>> key, WeightedTable<E> element) Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> WeightedCollectionValue.Immutable<E> immutableOf(Supplier<? extends Key<? extends WeightedCollectionValue<E>>> key, WeightedTable<E> element) Constructs an immutableWeightedCollectionValue
of the appropriate type based on the givenKey
and the element.- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
genericMutableOf
Constructs aValue
of the appropriate type based on the givenKey
and the element. The returnedValue
is guaranteedValue.Mutable
, this means that callingasMutable()
will return itself.- Type Parameters:
V
- The value typeE
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
genericImmutableOf
Constructs aValue
of the appropriate type based on the givenKey
and the element. The returnedValue
is guaranteedValue.Immutable
, this means that callingasImmutable()
will return itself.- Type Parameters:
V
- The value typeE
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
get
E get()Gets the held value.- Returns:
- The held value
-
key
Gets the key for thisValue
.- Returns:
- The key for this value
-
asMutable
Value.Mutable<E> asMutable()Retrieves a mutable form of this value. Due to the vague nature of the value itself, some cases can already provide aValue.Mutable
instance where this would simply return itself. In other cases, where the retrieved value is anValue.Immutable
instance, a new mutable value is created with the same key and values.- Returns:
- A mutable value
-
asMutableCopy
Value.Mutable<E> asMutableCopy()Retrieves a copy in the mutable form of this value. The new is created with the same key and values.- Returns:
- A mutable value
-
asImmutable
Value.Immutable<E> asImmutable()Retrieves an immutable form of this value. Due to the vague nature of the value itself, some cases can already provide aValue.Immutable
instance where this would simply return itself. In other cases, where the retrieved value is aValue.Mutable
instance, a new immutable value is created with the same key and values.- Returns:
- An immutable value
-