Interface ReductionStrategy<T>

Type Parameters:
T - type of reduced data
All Known Implementing Classes:
ReductionStrategy.AbstractReductionStrategy, ReductionStrategy.ChildrenReductionStrategy, ReductionStrategy.LeavesReductionStrategy, ReductionStrategy.StrictReductionStrategy, ReductionStrategy.SubtreeReductionStrategy

public interface ReductionStrategy<T>

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:
  • 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 specified 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.
      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 by AttributeLoader.Aggregate.loadValue
      reducer - instance that is responsible for reducing but can ignore actual form of handled subtree
      Returns:
      reduced subtree value
    • getStrategyType

      @NotNull static String getStrategyType(@NotNull AttributeSpec<?> attributeSpec)
      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

      @NotNull static <T> ReductionStrategy<T> forAttributeSpec(@NotNull AttributeSpec<?> attributeSpec)
      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

      @NotNull static <T> ReductionStrategy<T> forStrategyType(@NotNull String strategyType)
      Try to return default strategy for known types.
      Parameters:
      strategyType - strategy type
      Returns:
      reduction strategy
      Throws:
      IllegalArgumentException - iff strategy type is unknown