T
- type of reduced values@FunctionalInterface public interface ValueReducer<T>
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 |
ReductionStrategy
,
ReducingAggregateLoader
Modifier and Type | Method and Description |
---|---|
default T |
convert(Supplier<T> self)
Reduce a single value (self value of attribute for current row).
|
default T |
merge(Supplier<T> self,
List<T> list)
Calculates reduction of tree node where
self is value of the current row and list represents values passed from children (it
may be or be not values of children rows depending on strategy type). |
default T |
merge(Supplier<T> self,
Supplier<T> reduced)
Calculates reduction of tree node where
self is value of the current row, and reduced is result of flat reduction. |
T |
reduce(List<T> list)
Reduces the list of values to one value.
|
@Nullable T reduce(@NotNull List<T> list)
merge
methods if not overridden. Can be called from convert
methodlist
- list of values, every item can be null@Nullable default T convert(@NotNull Supplier<T> self)
self
- can return null@Nullable default T merge(@NotNull Supplier<T> self, @NotNull Supplier<T> reduced)
self
is value of the current row, and reduced
is 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 other merge
method if not optimized.@Nullable default T merge(Supplier<T> self, List<T> list)
self
is value of the current row and list
represents 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).Copyright © 2024 Tempo Software. All Rights Reserved.