org.jfree.report.function
Class ItemSumFunction

java.lang.Object
  |
  +--org.jfree.report.function.AbstractExpression
        |
        +--org.jfree.report.function.AbstractFunction
              |
              +--org.jfree.report.function.ItemSumFunction
Direct Known Subclasses:
PageItemSumFunction

public class ItemSumFunction
extends AbstractFunction
implements java.io.Serializable

A report function that calculates the sum of one field (column) from the TableModel. 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:

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.

Author:
Thomas Morgner
See Also:
Serialized Form

Field Summary
protected static java.math.BigDecimal ZERO
          A useful constant representing zero.
 
Constructor Summary
ItemSumFunction()
          Constructs an unnamed function.
ItemSumFunction(java.lang.String name)
          Constructs a named function.
 
Method Summary
 java.lang.String getField()
          Returns the field used by the function.
 java.lang.String getGroup()
          Returns the group name.
 Expression getInstance()
          Return a completly separated copy of this function.
protected  java.math.BigDecimal getSum()
           
 java.lang.Object getValue()
          Returns the function value, in this case the running total of a specific column in the report's TableModel.
 void groupStarted(ReportEvent event)
          Receives notification that a new group is about to start.
 void itemsAdvanced(ReportEvent event)
          Receives notification that a row of data is being processed.
 void reportInitialized(ReportEvent event)
          Receives notification that a new report is about to start.
 void setField(java.lang.String field)
          Sets the field name for the function.
 void setGroup(java.lang.String name)
          Sets the group name.
protected  void setSum(java.math.BigDecimal sum)
           
 
Methods inherited from class org.jfree.report.function.AbstractFunction
clone, groupFinished, itemsFinished, itemsStarted, reportDone, reportFinished, reportStarted
 
Methods inherited from class org.jfree.report.function.AbstractExpression
getDataRow, getDependencyLevel, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, setActive, setDependencyLevel, setName, setRuntime
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

protected static final java.math.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(java.lang.String name)
Constructs a named function.

The field must be defined before using the function.

Parameters:
name - The function name.
Method Detail

reportInitialized

public void reportInitialized(ReportEvent event)
Receives notification that a new report is about to start.

Does nothing.

Overrides:
reportInitialized in class AbstractFunction
Parameters:
event - Information about the event.

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.
Overrides:
groupStarted in class AbstractFunction
Parameters:
event - Information about the event.

getGroup

public java.lang.String getGroup()
Returns the group name.
Returns:
The group name.

setGroup

public void setGroup(java.lang.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.

Parameters:
name - the group name (null permitted).

getField

public java.lang.String getField()
Returns the field used by the function.

The field name corresponds to a column name in the report's TableModel.

Returns:
The field name.

setField

public void setField(java.lang.String field)
Sets the field name for the function.

The field name corresponds to a column name in the report's TableModel.

Parameters:
field - the field name (null not permitted).

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 TableModel specified by the field name.

Overrides:
itemsAdvanced in class AbstractFunction
Parameters:
event - Information about the event.

getValue

public java.lang.Object getValue()
Returns the function value, in this case the running total of a specific column in the report's TableModel.
Returns:
The function value.

getSum

protected java.math.BigDecimal getSum()

setSum

protected void setSum(java.math.BigDecimal sum)

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.
Overrides:
getInstance in class AbstractExpression
Returns:
a copy of this function.