Interface ValueReducer<T>
- Type Parameters:
T- type of reduced values
- All Known Implementing Classes:
LongSumLoader,NumberSumLoader,ReducingAggregateLoader,SingleDependencyReducingAggregateLoader
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Describes how to combine the current value and values aggregated over the part of the subtree
(as defined by ReductionStrategy) during aggregate calculation.
It's intended for those attribute loaders that calculate values using only a part of subtree (examples: only direct children,
only leaves, subtree without root node).
The part of subtree to use is defined by ReductionStrategy, and this interface defines the reduction.
Following how AttributeLoader.Aggregate works, reduction is done by merging the current value with children values.
It provides multiple methods for strategies as they can only have a limited set of data on every tree node
processing.
One would want to implement this interface in case there's a need to aggregate over a custom part of a subtree.
For most cases, it's better to extend ReducingAggregateLoader.
It's sufficient to implement only reduce(java.util.List<T>), but one would normally want to implement other methods
too -- for either gaining performance benefit (see NumberSumLoader) or providing more meaningful result.
Methods are organized to cover the needs of existing ReductionStrategy instances.
This is the reason methods in ValueReducer roughly correspond to strategies in ReductionStrategy.
Correspondence table is given below:
| Method | Strategy |
|---|---|
reduce(List<T> list) | leaves, children, strict |
convert(Supplier<T> self) | leaves |
merge(Supplier<T> self, Supplier<T> reduced) | strict |
merge(Supplier<T> self, List<T> list) | subtree |
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault TReduce a single value (self value of attribute for current row).default TCalculates reduction of tree node whereselfis value of the current row, andreducedis result of flat reduction.default TCalculates reduction of tree node whereselfis value of the current row andlistrepresents values passed from children (it may be or be not values of children rows depending on strategy type).Reduces the list of values to one value.
-
Method Details
-
reduce
Reduces the list of values to one value. Describes 'flat' reduction of elements without hierarchy. Called reducing direct children values or frommergemethods if not overridden. Can be called fromconvertmethod- Parameters:
list- list of values, every item can be null- Returns:
- value after reduction, null means undefined
-
convert
Reduce a single value (self value of attribute for current row). If reduction describes any value conversion (null checks etc) it should be done here as well. The result must be equal to calling reduce() with one element.- Parameters:
self- can return null
-
merge
Calculates reduction of tree node whereselfis value of the current row, andreducedis result of flat reduction. Value modifications can be done here if one wants to build reduction that computes value based on depth in the structure. Called from strict subtree reduction strategy or from othermergemethod if not optimized. -
merge
Calculates reduction of tree node whereselfis value of the current row andlistrepresents values passed from children (it may be or be not values of children rows depending on strategy type). Value modifications can be done here if one wants to build reduction that computes value based on depth in the structure. Called from full subtree reduction strategy, that is default and the most frequently used strategy for most reducing aggregates (it makes this method the most probable target for optimization).
-