@FunctionalInterface public interface MergeFunction
Function
that attempts to merge
two separate ValueContainer
s into a singular ValueContainer
.
A merge function is similar to a Function
such that it can be reused
for multiple purposes and should be "stateless" on its own.Modifier and Type | Field and Description |
---|---|
static MergeFunction |
FORCE_NOTHING
Represents a
MergeFunction that forces no merges and uses the
original, or proposed replacement if the original is null . |
static MergeFunction |
IGNORE_ALL
Represents a
MergeFunction that ignores all merges and uses the
replacement, or the original if the replacement is null . |
Modifier and Type | Method and Description |
---|---|
default MergeFunction |
andThen(MergeFunction that)
Creates a new
MergeFunction chaining this current merge function
with the provided merge function. |
<C extends ValueContainer<?>> |
merge(C original,
C replacement)
Performs a merge of a type of
ValueContainer such that a merge
of the contained BaseValue s has been performed and the resulting
merged ValueContainer is returned. |
static final MergeFunction IGNORE_ALL
MergeFunction
that ignores all merges and uses the
replacement, or the original if the replacement is null
.static final MergeFunction FORCE_NOTHING
MergeFunction
that forces no merges and uses the
original, or proposed replacement if the original is null
.<C extends ValueContainer<?>> C merge(@Nullable C original, @Nullable C replacement)
ValueContainer
such that a merge
of the contained BaseValue
s has been performed and the resulting
merged ValueContainer
is returned. It is suffice to say that
only one of the ValueContainer
containers may be null
,
such that
if (original == null) {
return checkNotNull(replacement);
} else if (replacement == null) {
return original;
} else {
// do something merging the necessary values
}
It can be therefor discerned that both values are passed in as copies
and therefor either one can be modified and returned.
Since
CompositeValueStore.copyFrom(CompositeValueStore, MergeFunction)
accepts only a single MergeFunction
, and a
CompositeValueStore
may have multiple ValueContainer
s,
as provided by CompositeValueStore.getContainers()
, the merge
function may be called for every single number of ValueContainer
.
This way, a MergeFunction
can be fully customized to merge
specific ValueContainer
s of matching types.
C
- The type of ValueContainer
original
- The original ValueContainer
from the value storereplacement
- The replacing value containerValueContainer
default MergeFunction andThen(MergeFunction that)
MergeFunction
chaining this current merge function
with the provided merge function. The order of the merge is this
performs merge(ValueContainer, ValueContainer)
then, the
provided MergeFunction
merges the returned merged
ValueContainer
and the replacement
. This can be used to
apply a custom merge strategy after a pre-defined MergeFunction
is applied.that
- The MergeFunction
to chainMergeFunction