Package org.spongepowered.api.data.value
Interface Value.Immutable<E>
- Type Parameters:
E
- The type of value
- All Superinterfaces:
Value<E>
- All Known Subinterfaces:
CollectionValue.Immutable<E,
,C, I, M> ListValue.Immutable<E>
,MapValue.Immutable<K,
,V> SetValue.Immutable<E>
,WeightedCollectionValue.Immutable<E>
Represents an immutable representation of a
Value
where any
modifications of the underlying value result in a new instance of an
Value.Immutable
and/or the ValueContainer
if the
ValueContainer
too is immutable.
The basis for immutability is that once created, the value can not be
changed for any reason. Change requires a new instance to be created. As the
Value.Immutable
always has a ValueContainer
, it is
recommended that the owning ValueContainer
too is immutable, unless
the Value.Immutable
is being passed around for data processing. The
underlying value of an Value.Immutable
may be itself mutable, however
utilizing any provided methods by any of the Value.Immutable
classes
is recommended.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.spongepowered.api.data.value.Value
Value.Factory, Value.Immutable<E>, Value.Mutable<E>
-
Method Summary
Modifier and TypeMethodDescriptiondefault Value.Immutable
<E> Retrieves an immutable form of this value.Creates a mutableValue.Mutable
for thisValue.Immutable
.default Value.Mutable
<E> Retrieves a copy in the mutable form of this value.Retrieves the underlying value for thisValue.Immutable
and applies the givenFunction
onto that value, after which, the product is sent to a newValue.Immutable
replacing this one.Creates a newValue.Immutable
with the givenE
typed value, such that if the owningValueContainer
is immutable, theValueContainer
too is recreated as a new instance with the newValue.Immutable
.
-
Method Details
-
with
Creates a newValue.Immutable
with the givenE
typed value, such that if the owningValueContainer
is immutable, theValueContainer
too is recreated as a new instance with the newValue.Immutable
.- Parameters:
value
- The value to replace- Returns:
- The owning
ValueContainer
, a new instance if it too is immutable
-
transform
Retrieves the underlying value for thisValue.Immutable
and applies the givenFunction
onto that value, after which, the product is sent to a newValue.Immutable
replacing this one.If the
ValueContainer
too is immutable, a new instance of theValueContainer
may be created. If theValueContainer
is mutable, the same instance of theValueContainer
is retained.- Parameters:
function
- The function to apply onto the existing value- Returns:
- The owning
ValueContainer
, a new instance if it too is immutable
-
asMutable
Value.Mutable<E> asMutable()Creates a mutableValue.Mutable
for thisValue.Immutable
. -
asMutableCopy
Description copied from interface:Value
Retrieves a copy in the mutable form of this value. The new is created with the same key and values.- Specified by:
asMutableCopy
in interfaceValue<E>
- Returns:
- A mutable value
-
asImmutable
Description copied from interface:Value
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.- Specified by:
asImmutable
in interfaceValue<E>
- Returns:
- An immutable value
-