Interface ReductionStrategy<T>
- Type Parameters:
T- type of reduced data
- All Known Implementing Classes:
ReductionStrategy.AbstractReductionStrategy,ReductionStrategy.ChildrenReductionStrategy,ReductionStrategy.LeavesReductionStrategy,ReductionStrategy.StrictReductionStrategy,ReductionStrategy.SubtreeReductionStrategy
Describes a part of subtree to be used for calculating aggregate values. Subtree type can be:
- subtree: full subtree (default),
- strict: subtree without root node,
- children: direct children only,
- leaves: leaves only.
The way it works is that apply(java.util.function.Supplier<com.almworks.jira.structure.api.attribute.AttributeValue<T>>, java.util.List<com.almworks.jira.structure.api.attribute.AttributeValue<T>>, com.almworks.jira.structure.api.attribute.loader.reduce.ValueReducer<T>) is called from AttributeLoader.Aggregate.loadValue,
and it passes the values corresponding to the specific part of the subtree to a ValueReducer.
Implementations provide the way to effectively calculate reduction on given subtree.
They may use (but may ignore) AttributeValue.value of the current row.
They may also use AttributeValue.loaderData for intermediate calculations.
Every implementation defines its own contract for attribute value and loader data.
If an implementation uses loader data, it should check for errors.
It doesn't need to check for errors in attribute values because the check should be performed by the caller code.
This class is intended to be an inner utility of ReducingAggregateLoader and similar classes.
First an ReductionStrategy instance is retrieved using forAttributeSpec(com.almworks.jira.structure.api.attribute.AttributeSpec<?>),
which looks at SharedAttributeSpecs.Param.TYPE parameter in the attribute specification.
Default recognized subtree types are described in forStrategyType(java.lang.String).
Typical usage is to implement aggregation modifiers in formulas.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic classMain value: the aggregation based only on children.static classMain value: the aggregation based only on leaves.static classMain value: the aggregation based on the whole subtree without self row.static classMain value: the aggregation based only on all children. -
Method Summary
Modifier and TypeMethodDescriptionapply(Supplier<AttributeValue<T>> selfSupplier, List<AttributeValue<T>> children, ValueReducer<T> reducer) Reduce value of the current node and children values to the single value using the specifiedValueReducer.static <T> ReductionStrategy<T>forAttributeSpec(AttributeSpec<?> attributeSpec) Look for strategy type from the spec and try to return default strategy for known types.static <T> ReductionStrategy<T>forStrategyType(String strategyType) Try to return default strategy for known types.static StringgetStrategyType(AttributeSpec<?> attributeSpec) Look for known strategy type from the spec and return default (SUBTREE) value if not found.
-
Method Details
-
apply
@NotNull AttributeValue<T> apply(@NotNull Supplier<AttributeValue<T>> selfSupplier, @NotNull List<AttributeValue<T>> children, @NotNull ValueReducer<T> reducer) Reduce value of the current node and children values to the single value using the specifiedValueReducer. This method is designed to be used fromAttributeLoader.Aggregate. Reduction can be performed over any subtree and it's assumed that everyReductionStrategydescribes in this method a reduction for a single known subtree type.- Parameters:
selfSupplier- supplier for value of current row. Supplier can be or be not called from this method depending on type of subtree this strategy describes. It's assumed that calling supplier can be heavy operation so it shouldn't be called more than once for each row from this method.children- values of direct children rows supplied byAttributeLoader.Aggregate.loadValuereducer- instance that is responsible for reducing but can ignore actual form of handled subtree- Returns:
- reduced subtree value
-
getStrategyType
Look for known strategy type from the spec and return default (SUBTREE) value if not found.- Parameters:
attributeSpec- spec to search for strategy type- Returns:
- strategy type
-
forAttributeSpec
Look for strategy type from the spec and try to return default strategy for known types.- Parameters:
attributeSpec- spec to search for strategy type- Returns:
- reduction strategy
- Throws:
IllegalArgumentException- iff strategy type is unknown
-
forStrategyType
Try to return default strategy for known types.- Parameters:
strategyType- strategy type- Returns:
- reduction strategy
- Throws:
IllegalArgumentException- iff strategy type is unknown
-