S
- The type of composite store, for self referencingH
- The type of ValueContainer
to restrict accessing of
values topublic interface CompositeValueStore<S extends CompositeValueStore<S,H>,H extends ValueContainer<?>> extends ValueContainer<S>
ValueContainer
that contains a various bundle of
ValueContainer
s of type declared by the extension that can be
manipulated separately from this CompositeValueStore
.Modifier and Type | Method and Description |
---|---|
default DataTransactionResult |
copyFrom(S that)
Performs an absolute copy of all
Value s and
ValueContainer s to this CompositeValueStore such that
any overlapping Value s are offered for replacement. |
DataTransactionResult |
copyFrom(S that,
MergeFunction function)
Performs an absolute copy of all
Value s and
ValueContainer s to this CompositeValueStore such that
any overlapping Value s are offered for replacement. |
<T extends H> |
get(Class<T> containerClass)
|
Collection<H> |
getContainers()
Gets an copied collection of all known
ValueContainer s
belonging to this CompositeValueStore . |
<T extends H> |
getOrCreate(Class<T> containerClass)
|
default <E> DataTransactionResult |
offer(BaseValue<E> value)
Offers the given
BaseValue as defined by the provided
Key such that a DataTransactionResult is returned for
any successful, rejected, and replaced BaseValue s from this
CompositeValueStore . |
default DataTransactionResult |
offer(H valueContainer)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to this CompositeValueStore . |
DataTransactionResult |
offer(H valueContainer,
MergeFunction function)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to this CompositeValueStore . |
default DataTransactionResult |
offer(Iterable<H> valueContainers)
Offers all provided
ValueContainer s to this
CompositeValueStore much like offer(ValueContainer)
except all in a single batch. |
default DataTransactionResult |
offer(Iterable<H> valueContainers,
MergeFunction function)
Offers all provided
ValueContainer s to this
CompositeValueStore much like offer(ValueContainer)
except all in a single batch. |
<E> DataTransactionResult |
offer(Key<? extends BaseValue<E>> key,
E value)
Offers the given
value as defined by the provided Key
such that a DataTransactionResult is returned for any
successful, rejected, and replaced BaseValue s from this
CompositeValueStore . |
default DataTransactionResult |
remove(BaseValue<?> value)
Attempts to remove the provided
BaseValue . |
DataTransactionResult |
remove(Class<? extends H> containerClass)
Attempts to remove all
Value s associated with the class of the
provided ValueContainer class. |
DataTransactionResult |
remove(Key<?> key)
Attempts to remove the data associated with the provided
Key . |
default <T extends H> |
require(Class<T> containerClass)
|
boolean |
supports(Class<? extends H> holderClass)
|
default <E> DataTransactionResult |
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 this CompositeValueStore . |
default <E> DataTransactionResult |
tryOffer(BaseValue<E> value)
Offers the given
value as defined by the provided Key
such that a DataTransactionResult is returned for any
successful BaseValue s from this CompositeValueStore . |
default DataTransactionResult |
tryOffer(H valueContainer)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to this CompositeValueStore . |
default DataTransactionResult |
tryOffer(H valueContainer,
MergeFunction function)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to this CompositeValueStore . |
default <E> DataTransactionResult |
tryOffer(Key<? extends BaseValue<E>> key,
E value)
Offers the given
value as defined by the provided Key
such that a DataTransactionResult is returned for any
successful BaseValue s from this CompositeValueStore . |
DataTransactionResult |
undo(DataTransactionResult result)
Attempts to "revert" a
DataTransactionResult such that any
of the DataTransactionResult.getReplacedData() are offered
back, and any DataTransactionResult.getSuccessfulData() are
removed if they were not the same types as any exising in the
replaced values. |
<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 classdefault <T extends H> T require(Class<T> containerClass)
ValueContainer
of type H
if the
ValueContainer
is compatible.
If the container class is not supported or
available, NoSuchElementException
will be thrown.
T
- The type of ValueContainer
containerClass
- The container classNoSuchElementException
- If the value is not supported or present<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 Value
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.get(DisplayNameData.class
).get().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 some default values
can be generated to create the desired 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> holderClass)
holderClass
- The container classdefault <E> DataTransactionResult 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 this CompositeValueStore
. It is not
necessary that the input is actually present, in which case the
Key
ed data is compatible, but not necessarily present. Writing
a Function
to properly handle the potential for a null input
is required for this method to execute without exception.E
- The type of valuekey
- The key linked tofunction
- The function to manipulate the value<E> DataTransactionResult offer(Key<? extends BaseValue<E>> key, E value)
value
as defined by the provided Key
such that a DataTransactionResult
is returned for any
successful, rejected, and replaced BaseValue
s from this
CompositeValueStore
.E
- The type of valuekey
- The key to the value to setvalue
- The value to setdefault <E> DataTransactionResult offer(BaseValue<E> value)
BaseValue
as defined by the provided
Key
such that a DataTransactionResult
is returned for
any successful, rejected, and replaced BaseValue
s from this
CompositeValueStore
.E
- The type of the element wrapped by the valuevalue
- The value to setdefault DataTransactionResult offer(H valueContainer)
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to this CompositeValueStore
. The end result of the values
successfully offered, rejected, and replaced are stored in the returned
DataTransactionResult
.valueContainer
- The value to setDataTransactionResult offer(H valueContainer, MergeFunction function)
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to this CompositeValueStore
. The end result of the values
successfully offered, rejected, and replaced are stored in the returned
DataTransactionResult
. Any overlaps of data are merged via
the MergeFunction
.valueContainer
- The value to setfunction
- The merge functiondefault DataTransactionResult offer(Iterable<H> valueContainers)
ValueContainer
s to this
CompositeValueStore
much like offer(ValueContainer)
except all in a single batch. The end result of the values successfully
offered, rejected, and replaced are stored in the returned
DataTransactionResult
.valueContainers
- The values to setdefault DataTransactionResult offer(Iterable<H> valueContainers, MergeFunction function)
ValueContainer
s to this
CompositeValueStore
much like offer(ValueContainer)
except all in a single batch. The end result of the values successfully
offered, rejected, and replaced are stored in the returned
DataTransactionResult
. Any merge conflicts are resolved through
the MergeFunction
.valueContainers
- The values to setfunction
- The function to resolve the valuesdefault <E> DataTransactionResult tryOffer(Key<? extends BaseValue<E>> key, E value) throws IllegalArgumentException
value
as defined by the provided Key
such that a DataTransactionResult
is returned for any
successful BaseValue
s from this CompositeValueStore
.
Intentionally, however, this differs from offer(Key, Object)
as it will intentionally throw an exception if the result was a failure.E
- The type of valuekey
- The key to the value to setvalue
- The value to setIllegalArgumentException
- If the result is a failure likely due to
incompatibilitydefault <E> DataTransactionResult tryOffer(BaseValue<E> value) throws IllegalArgumentException
value
as defined by the provided Key
such that a DataTransactionResult
is returned for any
successful BaseValue
s from this CompositeValueStore
.
Intentionally, however, this differs from offer(Key, Object)
as it will intentionally throw an exception if the result was a failure.E
- The type of valuevalue
- The value to setIllegalArgumentException
- If the result is a failure likely due to
incompatibilitydefault DataTransactionResult tryOffer(H valueContainer)
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to this CompositeValueStore
. Intentionally, however, this differs
from offer(ValueContainer)
as it will intentionally throw an
exception if the result was a failure.valueContainer
- The value to setIllegalArgumentException
- If the result is a failure likely due to
incompatibilitydefault DataTransactionResult tryOffer(H valueContainer, MergeFunction function) throws IllegalArgumentException
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to this CompositeValueStore
. Any overlaps of data are merged via
the MergeFunction
. Intentionally, however, this differs
from offer(ValueContainer)
as it will intentionally throw an
exception if the result was a failure.valueContainer
- The value to setfunction
- The merge functionIllegalArgumentException
- If the result is a failure likely due to
incompatibilityDataTransactionResult remove(Class<? extends H> containerClass)
Value
s associated with the class of the
provided ValueContainer
class. All values that were successfully
removed will be provided in
DataTransactionResult.getReplacedData()
. If the data can not be
removed, the result will be an expected
DataTransactionResult.Type.FAILURE
.containerClass
- The container classdefault DataTransactionResult remove(BaseValue<?> value)
BaseValue
. All values that were
successfully removed will be provided in
DataTransactionResult.getReplacedData()
. If the data can not be
removed, the result will be an expected
DataTransactionResult.Type.FAILURE
.value
- The value to removeDataTransactionResult remove(Key<?> key)
Key
.
All values that were successfully removed will be provided in
DataTransactionResult.getReplacedData()
. If the data can not be
removed, the result will be an expected
DataTransactionResult.Type.FAILURE
.key
- The key of the dataDataTransactionResult undo(DataTransactionResult result)
DataTransactionResult
such that any
of the DataTransactionResult.getReplacedData()
are offered
back, and any DataTransactionResult.getSuccessfulData()
are
removed if they were not the same types as any exising in the
replaced values.result
- The result to undodefault DataTransactionResult copyFrom(S that)
Value
s and
ValueContainer
s to this CompositeValueStore
such that
any overlapping Value
s are offered for replacement. The
result is provided as a DataTransactionResult
.that
- The other CompositeValueStore
to copy values fromDataTransactionResult copyFrom(S that, MergeFunction function)
Value
s and
ValueContainer
s to this CompositeValueStore
such that
any overlapping Value
s are offered for replacement. The
result is provided as a DataTransactionResult
.that
- The other CompositeValueStore
to copy values fromfunction
- The function to resolve merge conflictsCollection<H> getContainers()
ValueContainer
s
belonging to this CompositeValueStore
. An individual
ValueContainer
can be used for data processing for various
purposes.ValueContainer
s originating
from this value store