Class RankedReducer<C,T extends Ranked>

java.lang.Object
org.microbean.bean.RankedReducer<C,T>
Type Parameters:
C - the type of criteria
T - a Ranked type
All Implemented Interfaces:
Reducer<C,T>

public final class RankedReducer<C,T extends Ranked> extends Object implements Reducer<C,T>
A Reducer implementation that works with Ranked objects.
Author:
Laird Nelson
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static final <C, T extends Ranked>
    Reducer<C,T>
    of()
    Returns a RankedReducer implementation.
    final T
    reduce(List<? extends T> elements, C c, BiFunction<? super List<? extends T>,? super C,? extends T> failureHandler)
    Performs some kind of reductive or filtering operation on the supplied List, according to the supplied criteria, and returns the single result, or, if reduction fails, invokes the supplied BiFunction with a sublist representing a partial reduction (or an empty list representing a reduction that simply could not be performed), along with the supplied criteria, and returns its result.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.microbean.bean.Reducer

    cached, reduce, reduce, reduce
  • Method Details

    • reduce

      public final T reduce(List<? extends T> elements, C c, BiFunction<? super List<? extends T>,? super C,? extends T> failureHandler)
      Description copied from interface: Reducer
      Performs some kind of reductive or filtering operation on the supplied List, according to the supplied criteria, and returns the single result, or, if reduction fails, invokes the supplied BiFunction with a sublist representing a partial reduction (or an empty list representing a reduction that simply could not be performed), along with the supplied criteria, and returns its result.

      Implementations of this method must return determinate values.

      Specified by:
      reduce in interface Reducer<C,T extends Ranked>
      Parameters:
      elements - an immutable List to reduce; must not be null; represents a successful selection from a larger collection of elements
      c - the criteria effectively describing the initial selection and the desired reduction; may be null to indicate no criteria; may be ignored if not needed by an implementation
      failureHandler - a BiFunction receiving a failed reduction (usually a portion of the supplied elements), and the selection and reduction criteria, that returns a substitute reduction (or, more commonly, throws an exception); must not be null; must be invoked if reduction fails or undefined behavior may result
      Returns:
      a single, possibly null, element normally drawn or computed from the supplied elements, or a synthetic value returned by an invocation of the supplied failureHandler's BiFunction.apply(Object, Object) method
      See Also:
    • of

      public static final <C, T extends Ranked> Reducer<C,T> of()
      Returns a RankedReducer implementation.
      Type Parameters:
      C - the type of criteria
      T - the type of the Ranked reduction
      Returns:
      a RankedReducer implementation; never null
      Idempotency:
      This method is idempotent and deterministic.
      Nullability:
      This method never returns null.
      Thread Safety:
      This method is safe for concurrent use by multiple threads.