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, aValue
is a "wrapper" around an actual value from aValueContainer
. The actual value may come from various sources of theValueContainer
, but usually it's a generic dynamic system for being able to fetch values from object fields without having to know the type ofClass
of theValueContainer
, 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 anEntity
,Living
, etc., all that is required is
where the container is simply acontainer.supports(Keys.HEALTH) ? container.get(Keys.HEALTH).get() : 0
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 aValue.Mutable
for something so primitive as the current health of aLiving
entity, the power is wielded when aValue.Mutable
can be offered up to multipleValueContainer
s without worrying about whether it's supported or not, or getting the right cast information.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Value.Factory
static interface
Value.Immutable<E>
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
Value.Mutable<E>
Represents a type ofValue
that is mutable.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Value.Immutable<E>
asImmutable()
Retrieves an immutable form of this value.Value.Mutable<E>
asMutable()
Retrieves a mutable form of this value.Value.Mutable<E>
asMutableCopy()
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)
E
get()
Gets the held value.static <E> ListValue.Immutable<E>
immutableOf(java.util.function.Supplier<? extends Key<? extends ListValue<E>>> key, java.util.List<E> element)
static <K,V>
MapValue.Immutable<K,V>immutableOf(java.util.function.Supplier<? extends Key<? extends MapValue<K,V>>> key, java.util.Map<K,V> element)
static <E> SetValue.Immutable<E>
immutableOf(java.util.function.Supplier<? extends Key<? extends SetValue<E>>> key, java.util.Set<E> element)
static <E> Value.Immutable<E>
immutableOf(java.util.function.Supplier<? extends Key<? extends Value<E>>> key, E element)
static <E> WeightedCollectionValue.Immutable<E>
immutableOf(java.util.function.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, java.util.List<E> element)
static <K,V>
MapValue.Immutable<K,V>immutableOf(Key<? extends MapValue<K,V>> key, java.util.Map<K,V> element)
static <E> SetValue.Immutable<E>
immutableOf(Key<? extends SetValue<E>> key, java.util.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<? extends Value<E>>
key()
Gets the key for thisValue
.static <E> ListValue.Mutable<E>
mutableOf(java.util.function.Supplier<? extends Key<? extends ListValue<E>>> key, java.util.List<E> element)
static <K,V>
MapValue.Mutable<K,V>mutableOf(java.util.function.Supplier<? extends Key<? extends MapValue<K,V>>> key, java.util.Map<K,V> element)
static <E> SetValue.Mutable<E>
mutableOf(java.util.function.Supplier<? extends Key<? extends SetValue<E>>> key, java.util.Set<E> element)
static <E> Value.Mutable<E>
mutableOf(java.util.function.Supplier<? extends Key<? extends Value<E>>> key, E element)
static <E> WeightedCollectionValue.Mutable<E>
mutableOf(java.util.function.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>
mutableOf(Key<? extends ListValue<E>> key, java.util.List<E> element)
static <K,V>
MapValue.Mutable<K,V>mutableOf(Key<? extends MapValue<K,V>> key, java.util.Map<K,V> element)
static <E> SetValue.Mutable<E>
mutableOf(Key<? extends SetValue<E>> key, java.util.Set<E> element)
static <E> Value.Mutable<E>
mutableOf(Key<? extends Value<E>> key, E element)
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 Detail
-
mutableOf
static <E> Value.Mutable<E> mutableOf(Key<? extends Value<E>> key, E element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> Value.Mutable<E> mutableOf(java.util.function.Supplier<? extends Key<? extends Value<E>>> key, E element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
static <E> Value.Immutable<E> immutableOf(Key<? extends Value<E>> key, E element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> Value.Immutable<E> immutableOf(java.util.function.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
static <E> ListValue.Mutable<E> mutableOf(Key<? extends ListValue<E>> key, java.util.List<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> ListValue.Mutable<E> mutableOf(java.util.function.Supplier<? extends Key<? extends ListValue<E>>> key, java.util.List<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
static <E> ListValue.Immutable<E> immutableOf(Key<? extends ListValue<E>> key, java.util.List<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> ListValue.Immutable<E> immutableOf(java.util.function.Supplier<? extends Key<? extends ListValue<E>>> key, java.util.List<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
mutableOf
static <E> SetValue.Mutable<E> mutableOf(Key<? extends SetValue<E>> key, java.util.Set<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
mutableOf
static <E> SetValue.Mutable<E> mutableOf(java.util.function.Supplier<? extends Key<? extends SetValue<E>>> key, java.util.Set<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed mutable value
-
immutableOf
static <E> SetValue.Immutable<E> immutableOf(Key<? extends SetValue<E>> key, java.util.Set<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
immutableOf
static <E> SetValue.Immutable<E> immutableOf(java.util.function.Supplier<? extends Key<? extends SetValue<E>>> key, java.util.Set<E> element)
- Type Parameters:
E
- The element type- Parameters:
key
- The keyelement
- The element- Returns:
- The constructed immutable value
-
mutableOf
static <K,V> MapValue.Mutable<K,V> mutableOf(Key<? extends MapValue<K,V>> key, java.util.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
-
mutableOf
static <K,V> MapValue.Mutable<K,V> mutableOf(java.util.function.Supplier<? extends Key<? extends MapValue<K,V>>> key, java.util.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, java.util.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(java.util.function.Supplier<? extends Key<? extends MapValue<K,V>>> key, java.util.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(java.util.function.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(java.util.function.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
static <V extends Value<E>,E> V genericMutableOf(Key<V> key, E element)
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
static <V extends Value<E>,E> V genericImmutableOf(Key<V> key, E element)
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
-
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
-
-