Interface Reducible<C,T>
- Type Parameters:
C- the type of criteriaT- the element type
- All Known Implementing Classes:
Beans
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A functional interface whose implementations can reduce an unspecified
notional collection of elements to a single element according to some criteria.
This interface is related to, but should not be confused with, the Reducer interface, implementations of
which can be used to build Reducible instances.
- Author:
- Laird Nelson
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <C,E> Reducible <C, E> of(Selectable<C, E> selectable, Reducer<C, E> r) Calls theof(Selectable, Reducer, BiFunction)method with the suppliedselectable, the suppliedr, and a reference to theReducer.fail(List, Object)method, and returns the result.static <C,E> Reducible <C, E> of(Selectable<C, E> selectable, Reducer<C, E> r, BiFunction<? super List<? extends E>, ? super C, ? extends E> failureHandler) static <C,E> Reducible <C, E> ofCaching(Selectable<C, E> selectable, Reducer<C, E> r) Calls theofCaching(Selectable, Reducer, BiFunction)method with the suppliedselectable, the suppliedr, the suppliedfailureHandler, and a reference to theReducer.fail(List, Object)method, and returns its result.static <C,E> Reducible <C, E> ofCaching(Selectable<C, E> selectable, Reducer<C, E> r, BiFunction<? super List<? extends E>, ? super C, ? extends E> fh) Calls theofCaching(Selectable, Reducer, BiFunction, BiFunction)method with the suppliedselectable, the suppliedr, the suppliedfh, and a reference to thecomputeIfAbsent(Object, Function)method of a newConcurrentHashMap, and returns its result.static <C,E> Reducible <C, E> ofCaching(Selectable<C, E> selectable, Reducer<C, E> r, BiFunction<? super List<? extends E>, ? super C, ? extends E> fh, BiFunction<? super C, Function<C, E>, ? extends E> cache) Returns aReducibleimplementation that uses the suppliedReducerfor its reduction operations and the suppliedcomputeIfAbsentBiFunctionfor its caching implementation.Given a criteria object, which may benull, returns an object that represents the reduction of a notional collection of objects.
-
Method Details
-
reduce
Given a criteria object, which may benull, returns an object that represents the reduction of a notional collection of objects.Most
Reducibleimplementations will return determine values from invocations of this method, but there is no requirement to do so.- Parameters:
criteria- the criteria; may benullto indicate no criteria- Returns:
- a single object, or
null - Throws:
ReductionException- if reduction could not occur or if an error occurs
-
of
Calls theof(Selectable, Reducer, BiFunction)method with the suppliedselectable, the suppliedr, and a reference to theReducer.fail(List, Object)method, and returns the result.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benullr- aReducer; must not benull- Returns:
- a
Reducible; nevernull - Throws:
NullPointerException- ifselectableorrisnull- See Also:
-
of
static <C,E> Reducible<C,E> of(Selectable<C, E> selectable, Reducer<C, E> r, BiFunction<? super List<? extends E>, ? super C, ? extends E> failureHandler) - Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benullr- aReducer; must not benullfailureHandler- aBiFunctionserving as the suppliedReducer's failure handler; must not benull- Returns:
- a
Reducible; nevernull - Throws:
NullPointerException- if any argument isnull- See Also:
-
ofCaching
Calls theofCaching(Selectable, Reducer, BiFunction)method with the suppliedselectable, the suppliedr, the suppliedfailureHandler, and a reference to theReducer.fail(List, Object)method, and returns its result.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benullr- aReducer; must not benull- Returns:
- a
Reducible; nevernull - Throws:
NullPointerException- if any argument isnull- See Also:
-
ofCaching
static <C,E> Reducible<C,E> ofCaching(Selectable<C, E> selectable, Reducer<C, E> r, BiFunction<? super List<? extends E>, ? super C, ? extends E> fh) Calls theofCaching(Selectable, Reducer, BiFunction, BiFunction)method with the suppliedselectable, the suppliedr, the suppliedfh, and a reference to thecomputeIfAbsent(Object, Function)method of a newConcurrentHashMap, and returns its result.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benullr- aReducer; must not benullfh- aBiFunctionserving as the suppliedReducer's failure handler; must not benull- Returns:
- a
Reducible; nevernull - Throws:
NullPointerException- if any argument isnull- See Also:
-
ofCaching
static <C,E> Reducible<C,E> ofCaching(Selectable<C, E> selectable, Reducer<C, E> r, BiFunction<? super List<? extends E>, ? super C, ? extends E> fh, BiFunction<? super C, Function<C, E>, ? extends E> cache) Returns aReducibleimplementation that uses the suppliedReducerfor its reduction operations and the suppliedcomputeIfAbsentBiFunctionfor its caching implementation.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benullr- aReducer; must not benullfh- aBiFunctionserving as the suppliedReducer's failure handler; must not benullcache- aBiFunctionwith the same semantics as theMap.computeIfAbsent(Object, java.util.function.Function)method; must not benull- Returns:
- a
Reducible; nevernull - Throws:
NullPointerException- if any argument isnull- See Also:
-