org.jfree.report.function
Class TotalGroupSumQuotientFunction

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

public class TotalGroupSumQuotientFunction
extends AbstractFunction
implements java.io.Serializable

A report function that calculates the quotient of two summed fields (columns) from the TableModel. This function produces a global total. The total sum of the group is known when the group processing starts and the report is not performing a prepare-run. The sum is calculated in the prepare run and recalled in the printing run.

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 tree parameters. The dividend parameter is required and denotes the name of an ItemBand-field which gets summed up as dividend. The divisor parameter is required and denotes the name of an ItemBand-field which gets summed up as divisor.

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 DIVIDEND_PROPERTY
          Literal text for the 'dividend' property.
static java.lang.String DIVISOR_PROPERTY
          Literal text for the 'divisor' 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
TotalGroupSumQuotientFunction()
          Constructs a new function.
 
Method Summary
 java.lang.String getDividend()
          Returns the field used as dividend by the function.
 java.lang.String getDivisor()
          Returns the field used as divisor by the function.
 java.lang.String getGroup()
          Returns the name of the group to be totalled.
 Expression getInstance()
          Return a completly separated copy of this function.
 java.lang.Object getValue()
          Return the current function value.
 void groupStarted(ReportEvent event)
          Receives notification that a group has started.
 void initialize()
          Checks that the function has been correctly initialized.
 void itemsAdvanced(ReportEvent event)
          Receives notification that a row of data is being processed.
 void reportInitialized(ReportEvent event)
          Receives notification that the report has started.
 void setDividend(java.lang.String dividend)
          Sets the field name to be used as dividend for the function.
 void setDivisor(java.lang.String divisor)
          Sets the field name to be used as divisor for the function.
 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, getName, getProperties, getProperty, getProperty, groupFinished, isActive, itemsFinished, itemsStarted, reportDone, reportFinished, 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

GROUP_PROPERTY

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

See Also:
Constant Field Values

DIVIDEND_PROPERTY

public static final java.lang.String DIVIDEND_PROPERTY
Literal text for the 'dividend' property.

See Also:
Constant Field Values

DIVISOR_PROPERTY

public static final java.lang.String DIVISOR_PROPERTY
Literal text for the 'divisor' property.

See Also:
Constant Field Values
Constructor Detail

TotalGroupSumQuotientFunction

public TotalGroupSumQuotientFunction()
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.

itemsAdvanced

public void itemsAdvanced(ReportEvent event)
Receives notification that a row of data is being processed.

Specified by:
itemsAdvanced in interface ReportListener
Overrides:
itemsAdvanced 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.

getValue

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

The value depends (obviously) on the function implementation. For example, a page counting function will return the current page number.

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

getDividend

public java.lang.String getDividend()
Returns the field used as dividend by the function.

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

Returns:
The field name.

getDivisor

public java.lang.String getDivisor()
Returns the field used as divisor by the function.

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

Returns:
The field name.

setDividend

public void setDividend(java.lang.String dividend)
Sets the field name to be used as dividend for the function.

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

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

setDivisor

public void setDivisor(java.lang.String divisor)
Sets the field name to be used as divisor for the function.

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

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

initialize

public void initialize()
                throws FunctionInitializeException
Checks that the function has been correctly initialized. If there is a problem, this method throws a FunctionInitializeException.

The implementation checks that the Dividend and Divisor have been set.

Specified by:
initialize in interface Expression
Overrides:
initialize in class AbstractFunction
Throws:
FunctionInitializeException - if a required property was not set.

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