org.jfree.report.function
Class TotalCalculationFunction

java.lang.Object
  extended byorg.jfree.report.function.AbstractFunction
      extended byorg.jfree.report.function.TotalCalculationFunction
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, Expression, Function, ReportListener, java.io.Serializable

public class TotalCalculationFunction
extends AbstractFunction
implements java.io.Serializable

A report function that stores the result of a calculation for a group or the complete report. The field value, that was read when the group finished, is stored and returned when the group gets active again in a higher processing level.

This function can be used to calculate total values for a group, f.I. a TotalMax for the group, which returns the maximum value encountered for that field in the current group. The computed values are available to all bands of the group.

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. This parameter is optional.

Author:
Thomas Morgner
See Also:
Serialized Form

Field Summary
static java.lang.String FIELD_PROPERTY
          Literal text for the 'field' property.
static java.lang.String GROUP_PROPERTY
          Literal text for the 'group' property.
 
Fields inherited from interface org.jfree.report.function.Expression
AUTOACTIVATE_PROPERTY
 
Constructor Summary
TotalCalculationFunction()
          Constructs a new function.
 
Method Summary
 java.lang.String getField()
          Returns the name of the group to be totalled.
 java.lang.String getGroup()
          Returns the name of the group to be totalled.
 java.lang.Object getValue()
          Return the current expression value.
 void groupFinished(ReportEvent event)
          Receives notification that a group has finished.
 void groupStarted(ReportEvent event)
          Receives notification that a group has started.
 void initialize()
          Checks that the function has been correctly initialized.
 void reportFinished(ReportEvent event)
          Receives notification that the report has finished.
 void reportInitialized(ReportEvent event)
          Receives notification that the report has started.
 void setField(java.lang.String field)
          Defines the name of the group to be totalled.
 void setGroup(java.lang.String group)
          Defines the name of the group to be totalled.
 
Methods inherited from class org.jfree.report.function.AbstractFunction
clone, getDataRow, getDependencyLevel, getInstance, getName, getProperties, getProperty, getProperty, isActive, itemsAdvanced, itemsFinished, itemsStarted, reportDone, reportStarted, setDataRow, setDependencyLevel, setName, setProperties, setProperty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_PROPERTY

public static final java.lang.String FIELD_PROPERTY
Literal text for the 'field' property.

See Also:
Constant Field Values

GROUP_PROPERTY

public static final java.lang.String GROUP_PROPERTY
Literal text for the 'group' property.

See Also:
Constant Field Values
Constructor Detail

TotalCalculationFunction

public TotalCalculationFunction()
Constructs a new function.

Initially the function has no name...be sure to assign one before using the function.

Method Detail

reportInitialized

public void reportInitialized(ReportEvent event)
Receives notification that the report has started.

Specified by:
reportInitialized in interface ReportListener
Overrides:
reportInitialized in class AbstractFunction
Parameters:
event - the event.

groupStarted

public void groupStarted(ReportEvent event)
Receives notification that a group has started.

Specified by:
groupStarted in interface ReportListener
Overrides:
groupStarted in class AbstractFunction
Parameters:
event - the event.

groupFinished

public void groupFinished(ReportEvent event)
Receives notification that a group has finished.

Specified by:
groupFinished in interface ReportListener
Overrides:
groupFinished in class AbstractFunction
Parameters:
event - the event.

reportFinished

public void reportFinished(ReportEvent event)
Receives notification that the report has finished.

Specified by:
reportFinished in interface ReportListener
Overrides:
reportFinished in class AbstractFunction
Parameters:
event - the event.

getGroup

public java.lang.String getGroup()
Returns the name of the group to be totalled.

Returns:
the group name.

setGroup

public void setGroup(java.lang.String group)
Defines the name of the group to be totalled. If the name is null, all groups are totalled.

Parameters:
group - the group name.

getField

public java.lang.String getField()
Returns the name of the group to be totalled.

Returns:
the group name.

setField

public void setField(java.lang.String field)
Defines the name of the group to be totalled. If the name is null, all groups are totalled.

Parameters:
field - the field name.

getValue

public java.lang.Object getValue()
Return the current expression value.

The value depends (obviously) on the expression implementation.

Specified by:
getValue in interface Expression
Returns:
the value of the function.

initialize

public void initialize()
                throws FunctionInitializeException
Checks that the function has been correctly initialized.

The only check performed at present is to make sure the name is not null.

Specified by:
initialize in interface Expression
Overrides:
initialize in class AbstractFunction
Throws:
FunctionInitializeException - in case the function is not initialized properly.