I
- The type of immutable value store, for self referencingH
- The type of ValueContainer
to restrict accessing of
values topublic interface ImmutableValueStore<I extends ImmutableValueStore<I,H>,H extends ValueContainer<?>> extends ValueContainer<I>
ValueContainer
that is immutable once created and
contains a various bundle of ValueContainer
s of type declared by
the extension that can be managed separately from this immutable value
store.Modifier and Type | Method and Description |
---|---|
<T extends H> |
get(Class<T> containerClass)
|
List<H> |
getContainers()
Gets an copied collection of all known
ValueContainer s
belonging to this ImmutableValueStore . |
<T extends H> |
getOrCreate(Class<T> containerClass)
|
I |
merge(I that)
Attempts to merge the
ImmutableValue s from this
ImmutableValueStore and the given ImmutableValueStore to
produce a new instance of the merged result. |
I |
merge(I that,
MergeFunction function)
Attempts to merge the
ImmutableValue s from this
ImmutableValueStore and the given ImmutableValueStore to
produce a new instance of the merged result. |
boolean |
supports(Class<? extends H> containerClass)
|
<E> Optional<I> |
transform(Key<? extends BaseValue<E>> key,
Function<E,E> function)
Applies a transformation on the provided
BaseValue such that
the return value of Function.apply(Object) will become the end
resulting value set into the newly created ImmutableValueStore . |
Optional<I> |
with(BaseValue<?> value)
Offers the given
value as defined by the provided Key
such that if the Key is supported, a new
ImmutableValueStore is created. |
Optional<I> |
with(H valueContainer)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to the newly created ImmutableValueStore . |
Optional<I> |
with(Iterable<H> valueContainers)
Gets an altered copy of this
ImmutableValueStore with the given
DataManipulator modified data. |
<E> Optional<I> |
with(Key<? extends BaseValue<E>> key,
E value)
Creates a new
ImmutableValueStore with the provided
value by Key . |
Optional<I> |
without(Class<? extends H> containerClass)
Gets an altered copy of this
ImmutableValueStore without the
given ValueContainer class. |
<T extends H> Optional<T> get(Class<T> containerClass)
Gets the desired ValueContainer
of type H
if the
ValueContainer
is compatible. Since the return type is an
Optional
, a short way of checking compatibility and presence
of the requested data is to mimic the following:
// MyCompositeValueStore extends
CompositeValueStore<MyCompositeValueStore,
DataManipulator<?>>
MyCompositeValueStore valueStore;
final Optional<DisplayNameData> displayOptional =
valueStore.get(DisplayNameData.class);
if (displayOptional.isPresent()) {
// We know that we have a present DataManipulator and it's supported
System.out.println(
displayOptional.get().displayName().get().toString());
}
This is the equivalent to performing the following:
MyCompositeValueStore valueStore;
if (valueStore.supports(DisplayNameData.class)) {
System.out.println(valueStore.getOrNull(DisplayNameData.class
).displayName().get().toString());
}
The advantage of this returning an Optional
is that the
ValueContainer
may be unsupported, the required data missing
and ignoring the possibility of null
s, it is a guarantee that if
the Optional.isPresent()
is true
, the
ValueContainer
not only is supported, but there is already pre-
existing data for the ValueContainer
.
If it is necessary to ignore the Optional
,
Optional.orElse(Object)
can be used to return a potentially
null
ValueContainer
.
T
- The type of ValueContainer
containerClass
- The container class<T extends H> Optional<T> getOrCreate(Class<T> containerClass)
Gets the desired ValueContainer
of type H
if the
ValueContainer
is compatible. If insufficient data is available
to provide a ValueContainer
with all ImmutableValue
s
preset, a new instance of the ValueContainer
is returned with
"default" values. Since the return type is an Optional
, a short
way of checking compatibility and presence of the requested data is to
mimic the following:
// MyCompositeValueStore extends
CompositeValueStore<MyCompositeValueStore,
DataManipulator<?>>
MyCompositeValueStore valueStore;
final Optional<DisplayNameData> displayOptional =
valueStore.getOrCreate(DisplayNameData.class);
if (displayOptional.isPresent()) {
// We know that we
have a present DataManipulator and it's supported
System.out.println(displayOptional.get().displayName().get().toString());
}
This is the equivalent to performing the following:
MyCompositeValueStore valueStore;
if (valueStore.supports(DisplayNameData.class)) {
System.out.println(valueStore.getOrNull(DisplayNameData.class
).displayName().get().toString());
}
The advantage of this returning an Optional
is that the
ValueContainer
may be unsupported, the required data missing
and ignoring the possibility of null
s, it is a guarantee that if
the Optional.isPresent()
is true
, the
ValueContainer
not only is supported, but there is already pre-
existing data for the ValueContainer
.
If it is necessary to ignore the Optional
,
Optional.orElse(Object)
can be used to return a potentially
null
ValueContainer
.
T
- The type of ValueContainer
containerClass
- The container classboolean supports(Class<? extends H> containerClass)
containerClass
- The container class<E> Optional<I> transform(Key<? extends BaseValue<E>> key, Function<E,E> function)
BaseValue
such that
the return value of Function.apply(Object)
will become the end
resulting value set into the newly created ImmutableValueStore
.E
- The type of valuekey
- The key linked tofunction
- The function to manipulate the value<E> Optional<I> with(Key<? extends BaseValue<E>> key, E value)
ImmutableValueStore
with the provided
value by Key
. If the key is supported by this value store,
the returned value store will be present.E
- The type of valuekey
- The key to the value to setvalue
- The value to setOptional<I> with(BaseValue<?> value)
value
as defined by the provided Key
such that if the Key
is supported, a new
ImmutableValueStore
is created.value
- The value to setOptional<I> with(H valueContainer)
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to the newly created ImmutableValueStore
.valueContainer
- The value to setOptional<I> with(Iterable<H> valueContainers)
ImmutableValueStore
with the given
DataManipulator
modified data. If the data is not compatible for
any reason, Optional.empty()
is returned.
This does not alter the current ImmutableValueStore
.
valueContainers
- The new manipulator containing dataOptional<I> without(Class<? extends H> containerClass)
ImmutableValueStore
without the
given ValueContainer
class. If the data represented by the
manipulator can not exist without a "default state" of the
ValueContainer
, the ValueContainer
is reset to the
"default" state.containerClass
- The value holders to ignoreI merge(I that)
ImmutableValue
s from this
ImmutableValueStore
and the given ImmutableValueStore
to
produce a new instance of the merged result.that
- The other immutable value store to gather values fromI merge(I that, MergeFunction function)
ImmutableValue
s from this
ImmutableValueStore
and the given ImmutableValueStore
to
produce a new instance of the merged result. Any overlapping
ValueContainer
s are merged through the MergeFunction
.that
- The other immutable value store to gather values fromfunction
- The function to resolve merge conflictsList<H> getContainers()
ValueContainer
s
belonging to this ImmutableValueStore
. An individual
ValueContainer
can be used for data processing for various
purposes.ValueContainer
s originating
from this value store