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>
public static interface Value.Immutable<E> extends Value<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.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 aValueContainer
, it is recommended that the owningValueContainer
too is immutable, unless theValue.Immutable
is being passed around for data processing. The underlying value of anValue.Immutable
may be itself mutable, however utilizing any provided methods by any of theValue.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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Value.Immutable<E>
asImmutable()
Retrieves an immutable form of this value.Value.Mutable<E>
asMutable()
Creates a mutableValue.Mutable
for thisValue.Immutable
.default Value.Mutable<E>
asMutableCopy()
Retrieves a copy in the mutable form of this value.Value.Immutable<E>
transform(java.util.function.Function<E,E> function)
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.Value.Immutable<E>
with(E value)
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 Detail
-
with
Value.Immutable<E> with(E value)
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
Value.Immutable<E> transform(java.util.function.Function<E,E> function)
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
default Value.Mutable<E> 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
default Value.Immutable<E> 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
-
-