Class ItemSumFunction

  • All Implemented Interfaces:
    Serializable, Cloneable, EventListener, ReportListener, AggregationFunction, Expression, FieldAggregationFunction, Function
    Direct Known Subclasses:
    ConditionalItemSumFunction, PageItemSumFunction

    public class ItemSumFunction
    extends AbstractFunction
    implements FieldAggregationFunction
    A report function that calculates the sum of one field (column) from the data-row. This function produces a running total, no global total. For a global sum, use the TotalGroupSumFunction function. The function can be used in two ways:
    • to calculate a sum for the entire report;
    • to calculate a sum within a particular group;
    This function expects its input values to be either java.lang.Number instances or Strings that can be parsed to java.lang.Number instances using a java.text.DecimalFormat.

    The function undestands two parameters, the field parameter is required and denotes the name of an ItemBand-field which gets summed up.

    The parameter group denotes the name of a group. When this group is started, the counter gets reseted to null.

    Thomas Morgner
    See Also:
    Serialized Form
    • Field Detail

      • ZERO

        protected static final BigDecimal ZERO
        A useful constant representing zero.
    • Constructor Detail

      • ItemSumFunction

        public ItemSumFunction()
        Constructs an unnamed function. Make sure to set a Name or function initialisation will fail.
      • ItemSumFunction

        public ItemSumFunction​(String name)
        Constructs a named function.

        The field must be defined before using the function.

        name - The function name.
    • Method Detail

      • clear

        protected void clear()
      • groupStarted

        public void groupStarted​(ReportEvent event)
        Receives notification that a new group is about to start. If this is the group defined for the function, then the running total is reset to zero.
        Specified by:
        groupStarted in interface ReportListener
        groupStarted in class AbstractFunction
        event - Information about the event.
      • setGroup

        public void setGroup​(String name)
        Sets the group name.

        If a group is defined, the running total is reset to zero at the start of every instance of this group.

        Specified by:
        setGroup in interface AggregationFunction
        name - the group name (null permitted).
      • getField

        public String getField()
        Returns the field used by the function. The field name corresponds to a column name in the report's data-row.
        Specified by:
        getField in interface FieldAggregationFunction
        The field name.
      • setField

        public void setField​(String field)
        Sets the field name for the function. The field name corresponds to a column name in the report's data-row.
        Specified by:
        setField in interface FieldAggregationFunction
        field - the field name.
      • itemsAdvanced

        public void itemsAdvanced​(ReportEvent event)
        Receives notification that a row of data is being processed. Reads the data from the field defined for this function and adds it to the running total.

        This function assumes that it will find an instance of the Number class in the column of the data-row specified by the field name.

        Specified by:
        itemsAdvanced in interface ReportListener
        itemsAdvanced in class AbstractFunction
        event - Information about the event.
      • getValue

        public Object getValue()
        Returns the function value, in this case the running total of a specific column in the report's data-row.
        Specified by:
        getValue in interface Expression
        The function value.
      • getInstance

        public Expression getInstance()
        Return a completly separated copy of this function. The copy does no longer share any changeable objects with the original function.
        Specified by:
        getInstance in interface Expression
        getInstance in class AbstractExpression
        a copy of this function.
      • clone

        public Object clone()
        Description copied from class: AbstractExpression
        Clones the expression. The expression should be reinitialized after the cloning.

        Expressions maintain no state, cloning is done at the beginning of the report processing to disconnect the expression from any other object space.

        Specified by:
        clone in interface Expression
        clone in class AbstractExpression
        a clone of this expression.