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
Represents a unique form of Function that attempts to merge two separate Values into a singular Value. A merge function is similar to a Function such that it can be reused for multiple purposes and should be "stateless" on its own.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MergeFunction
    Represents a MergeFunction that will preferr the original's value if it is not null over the replacement.
    static final MergeFunction
    Represents a MergeFunction that ignores all merges and uses the replacement, or the original if the replacement is null.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new MergeFunction chaining this current merge function with the provided merge function.
    <V extends Value<E>, E>
    V
    merge(@Nullable V original, @Nullable V replacement)
    Performs a merge of a type of Value such that a merge has been performed and the resulting merged Value is returned.
  • Field Details

    • REPLACEMENT_PREFERRED

      static final MergeFunction REPLACEMENT_PREFERRED
      Represents a MergeFunction that ignores all merges and uses the replacement, or the original if the replacement is null.
    • ORIGINAL_PREFERRED

      static final MergeFunction ORIGINAL_PREFERRED
      Represents a MergeFunction that will preferr the original's value if it is not null over the replacement.
  • Method Details

    • merge

      <V extends Value<E>, E> V merge(@Nullable V original, @Nullable V replacement)
      Performs a merge of a type of Value such that a merge has been performed and the resulting merged Value is returned. It is suffice to say that only one of the Values 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.
      Type Parameters:
      V - The type of Value being passed in
      E - The type of value for the Value
      Parameters:
      original - The original Value from the value store
      replacement - The replacing value container
      Returns:
      The "merged" Value
    • andThen

      default MergeFunction andThen(MergeFunction that)
      Creates a new MergeFunction chaining this current merge function with the provided merge function. The order of the merge is this performs merge(Value, Value) 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.
      Parameters:
      that - The MergeFunction to chain
      Returns:
      The new MergeFunction