org.pentaho.reporting.engine.classic.core.function
Class TotalGroupSumQuotientFunction

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.function.AbstractExpression
      extended by org.pentaho.reporting.engine.classic.core.function.AbstractFunction
          extended by org.pentaho.reporting.engine.classic.core.function.TotalGroupSumQuotientFunction
All Implemented Interfaces:
Serializable, Cloneable, EventListener, ReportListener, Expression, Function
Direct Known Subclasses:
TotalGroupSumQuotientPercentFunction

public class TotalGroupSumQuotientFunction
extends AbstractFunction

A report function that calculates the quotient of two summed fields (columns) from the report's data row. 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

Constructor Summary
TotalGroupSumQuotientFunction()
          Constructs a new function.
 
Method Summary
 Object clone()
          Clones the expression.
 String getDividend()
          Returns the field used as dividend by the function.
 String getDivisor()
          Returns the field used as divisor by the function.
 String getGroup()
          Returns the name of the group to be totalled.
 int getRoundingMode()
          Returns the defined rounding mode.
 int getScale()
          Returns the scale for the divide-operation.
 Object getValue()
          Return the current function value.
 void groupStarted(ReportEvent event)
          Receives notification that a group has started.
 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 setDependencyLevel(int level)
          Defines the function's dependency level.
 void setDividend(String dividend)
          Sets the field name to be used as dividend for the function.
 void setDivisor(String divisor)
          Sets the field name to be used as divisor for the function.
 void setGroup(String group)
          Defines the name of the group to be totalled.
 void setRoundingMode(int roundingMode)
          Defines the rounding mode.
 void setRuntime(ExpressionRuntime runtime)
          Defines the ExpressionRune used in this expression.
 void setScale(int scale)
          Defines the scale for the divide-operation.
 
Methods inherited from class org.pentaho.reporting.engine.classic.core.function.AbstractFunction
groupFinished, itemsFinished, itemsStarted, reportDone, reportFinished, reportStarted
 
Methods inherited from class org.pentaho.reporting.engine.classic.core.function.AbstractExpression
getDataRow, getDependencyLevel, getInstance, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setActive, setName, setPreserve
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pentaho.reporting.engine.classic.core.function.Expression
getDataRow, getDependencyLevel, getInstance, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setName
 

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 String getGroup()
Returns the name of the group to be totalled.

Returns:
the group name.

setGroup

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

Returns:
The value of the function.

getDividend

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

The field name corresponds to a column name in the report's data-row.

Returns:
The field name.

getDivisor

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

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

Returns:
The field name.

setDividend

public void setDividend(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 data-row.

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

setDivisor

public void setDivisor(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 data-row.

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

getRoundingMode

public int getRoundingMode()
Returns the defined rounding mode. This influences the precision of the divide-operation.

Returns:
the rounding mode.
See Also:
BigDecimal.divide(java.math.BigDecimal,int)

setRoundingMode

public void setRoundingMode(int roundingMode)
Defines the rounding mode. This influences the precision of the divide-operation.

Parameters:
roundingMode - the rounding mode.
See Also:
BigDecimal.divide(java.math.BigDecimal,int)

getScale

public int getScale()
Returns the scale for the divide-operation. The scale influences the precision of the division.

Returns:
the scale.

setScale

public void setScale(int scale)
Defines the scale for the divide-operation. The scale influences the precision of the division.

Parameters:
scale - the scale.

setDependencyLevel

public void setDependencyLevel(int level)
Defines the function's dependency level. This method forwards all calls to the interal functions.

Specified by:
setDependencyLevel in interface Expression
Overrides:
setDependencyLevel in class AbstractExpression
Parameters:
level - the dependency level.
See Also:
Expression.getDependencyLevel()

setRuntime

public void setRuntime(ExpressionRuntime runtime)
Defines the ExpressionRune used in this expression. The ExpressionRuntime is set before the expression receives events or gets evaluated and is unset afterwards. Do not hold references on the runtime or you will create memory-leaks.

Specified by:
setRuntime in interface Expression
Overrides:
setRuntime in class AbstractExpression
Parameters:
runtime - the runtime information for the expression

clone

public Object clone()
             throws CloneNotSupportedException
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
Overrides:
clone in class AbstractExpression
Returns:
a clone of this expression.
Throws:
CloneNotSupportedException - this should never happen.