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 MergeFunctionORIGINAL_PREFERREDRepresents aMergeFunctionthat will preferr the original's value if it is notnullover the replacement.static MergeFunctionREPLACEMENT_PREFERREDRepresents aMergeFunctionthat 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 MergeFunctionandThen(MergeFunction that)Creates a newMergeFunctionchaining 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 aMergeFunctionthat ignores all merges and uses the replacement, or the original if the replacement isnull.
-
ORIGINAL_PREFERRED
static final MergeFunction ORIGINAL_PREFERRED
Represents aMergeFunctionthat will preferr the original's value if it is notnullover the replacement.
-
-
Method Detail
-
merge
<V extends Value<E>,E> V merge(@Nullable V original, @Nullable V replacement)
Performs a merge of a type ofValuesuch that a merge has been performed and the resulting mergedValueis returned. It is suffice to say that only one of theValues may benull, such that
It can be therefor discerned that both values are passed in as copies and therefor either one can be modified and returned.if (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 newMergeFunctionchaining this current merge function with the provided merge function. The order of the merge is this performsmerge(Value, Value)then, the providedMergeFunctionmerges the returned mergedValueContainerand thereplacement. This can be used to apply a custom merge strategy after a pre-definedMergeFunctionis applied.- Parameters:
that- TheMergeFunctionto chain- Returns:
- The new
MergeFunction
-
-