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 aValuewhere any modifications of the underlying value result in a new instance of anValue.Immutableand/or theValueContainerif theValueContainertoo 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.Immutablealways has aValueContainer, it is recommended that the owningValueContainertoo is immutable, unless theValue.Immutableis being passed around for data processing. The underlying value of anValue.Immutablemay be itself mutable, however utilizing any provided methods by any of theValue.Immutableclasses 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.Mutablefor 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.Immutableand applies the givenFunctiononto that value, after which, the product is sent to a newValue.Immutablereplacing this one.Value.Immutable<E>with(E value)Creates a newValue.Immutablewith the givenEtyped value, such that if the owningValueContaineris immutable, theValueContainertoo is recreated as a new instance with the newValue.Immutable.
-
-
-
Method Detail
-
with
Value.Immutable<E> with(E value)
Creates a newValue.Immutablewith the givenEtyped value, such that if the owningValueContaineris immutable, theValueContainertoo 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.Immutableand applies the givenFunctiononto that value, after which, the product is sent to a newValue.Immutablereplacing this one.If the
ValueContainertoo is immutable, a new instance of theValueContainermay be created. If theValueContaineris mutable, the same instance of theValueContaineris 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.Mutablefor thisValue.Immutable.
-
asMutableCopy
default Value.Mutable<E> asMutableCopy()
Description copied from interface:ValueRetrieves a copy in the mutable form of this value. The new is created with the same key and values.- Specified by:
asMutableCopyin interfaceValue<E>- Returns:
- A mutable value
-
asImmutable
default Value.Immutable<E> asImmutable()
Description copied from interface:ValueRetrieves an immutable form of this value. Due to the vague nature of the value itself, some cases can already provide aValue.Immutableinstance where this would simply return itself. In other cases, where the retrieved value is aValue.Mutableinstance, a new immutable value is created with the same key and values.- Specified by:
asImmutablein interfaceValue<E>- Returns:
- An immutable value
-
-