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.Mutablefor thisValue.Immutable.default Value.Mutable<E>Retrieves a copy in the mutable form of this value.Retrieves the underlying value for thisValue.Immutableand applies the givenFunctiononto that value, after which, the product is sent to a newValue.Immutablereplacing this one.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 Details
-
with
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
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
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
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
-