T
- type of reduced datapublic interface ReductionStrategy<T>
Describes a part of subtree to be used for calculating aggregate values. Subtree type can be:
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.
ValueReducer
,
ReducingAggregateLoader
Modifier and Type | Interface and Description |
---|---|
static class |
ReductionStrategy.AbstractReductionStrategy<T> |
static class |
ReductionStrategy.ChildrenReductionStrategy<T>
Main value: the aggregation based only on children.
|
static class |
ReductionStrategy.LeavesReductionStrategy<T>
Main value: the aggregation based only on leaves.
|
static class |
ReductionStrategy.StrictReductionStrategy<T>
Main value: the aggregation based on the whole subtree without self row.
|
static class |
ReductionStrategy.SubtreeReductionStrategy<T>
Main value: the aggregation based only on all children.
|
Modifier and Type | Method and Description |
---|---|
AttributeValue<T> |
apply(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 specified
ValueReducer . |
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 String |
getStrategyType(AttributeSpec<?> attributeSpec)
Look for known strategy type from the spec and return default (
SUBTREE ) value if not found. |
@NotNull AttributeValue<T> apply(@NotNull Supplier<AttributeValue<T>> selfSupplier, @NotNull List<AttributeValue<T>> children, @NotNull ValueReducer<T> reducer)
ValueReducer
.
This method is designed to be used from AttributeLoader.Aggregate
.
Reduction can be performed over any subtree and it's assumed that every ReductionStrategy
describes in this method a reduction for a single known subtree type.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 by AttributeLoader.Aggregate.loadValue
reducer
- instance that is responsible for reducing but can ignore actual form of handled subtree@NotNull static String getStrategyType(@NotNull AttributeSpec<?> attributeSpec)
SUBTREE
) value if not found.attributeSpec
- spec to search for strategy type@NotNull static <T> ReductionStrategy<T> forAttributeSpec(@NotNull AttributeSpec<?> attributeSpec)
attributeSpec
- spec to search for strategy typeIllegalArgumentException
- iff strategy type is unknown@NotNull static <T> ReductionStrategy<T> forStrategyType(@NotNull String strategyType)
strategyType
- strategy typeIllegalArgumentException
- iff strategy type is unknownCopyright © 2024 Tempo Software. All Rights Reserved.