Package org.spongepowered.api.data.value
Interface MergeFunction
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface MergeFunction
-
-
Field Summary
Fields Modifier and Type Field Description static MergeFunction
ORIGINAL_PREFERRED
Represents aMergeFunction
that will preferr the original's value if it is notnull
over the replacement.static MergeFunction
REPLACEMENT_PREFERRED
Represents aMergeFunction
that ignores all merges and uses the replacement, or the original if the replacement isnull
.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default MergeFunction
andThen(MergeFunction that)
Creates a newMergeFunction
chaining this current merge function with the provided merge function.<V extends Value<E>,E>
Vmerge(@Nullable V original, @Nullable V replacement)
-
-
-
Field Detail
-
REPLACEMENT_PREFERRED
static final MergeFunction REPLACEMENT_PREFERRED
Represents aMergeFunction
that ignores all merges and uses the replacement, or the original if the replacement isnull
.
-
ORIGINAL_PREFERRED
static final MergeFunction ORIGINAL_PREFERRED
Represents aMergeFunction
that will preferr the original's value if it is notnull
over the replacement.
-
-
Method Detail
-
merge
<V extends Value<E>,E> V merge(@Nullable V original, @Nullable V replacement)
Performs a merge of a type ofValue
such that a merge has been performed and the resulting mergedValue
is returned. It is suffice to say that only one of theValue
s may benull
, such thatif (original == null) { return checkNotNull(replacement); } else if (replacement == null) { return original; } else { // do something merging the necessary values }
-
andThen
default MergeFunction andThen(MergeFunction that)
Creates a newMergeFunction
chaining this current merge function with the provided merge function. The order of the merge is this performsmerge(Value, Value)
then, the providedMergeFunction
merges the returned mergedValueContainer
and thereplacement
. This can be used to apply a custom merge strategy after a pre-definedMergeFunction
is applied.- Parameters:
that
- TheMergeFunction
to chain- Returns:
- The new
MergeFunction
-
-