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

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.ItemAvgFunction
All Implemented Interfaces:
Serializable, Cloneable, EventListener, ReportListener, AggregationFunction, Expression, FieldAggregationFunction, Function

public class ItemAvgFunction
extends AbstractFunction
implements FieldAggregationFunction

A report function that calculates the average of one field (column) from the TableModel. This function produces a running total, no global total. 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

Constructor Summary
ItemAvgFunction()
          Constructs an unnamed function.
ItemAvgFunction(String name)
          Constructs a named function.
 
Method Summary
 String getField()
          Returns the field used by the function.
 String getGroup()
          Returns the group name.
 Expression getInstance()
          Return a completly separated copy of this function.
 int getRoundingMode()
          Returns the defined rounding mode.
 int getScale()
          Returns the scale for the divide-operation.
 Object getValue()
          Returns the function value, in this case the average of all values 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(String field)
          Sets the field name for the function.
 void setGroup(String name)
          Sets the group name.
 void setRoundingMode(int roundingMode)
          Defines the rounding mode.
 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
clone, getDataRow, getDependencyLevel, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setActive, setDependencyLevel, setName, setPreserve, setRuntime
 
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.event.ReportListener
groupFinished, itemsFinished, itemsStarted, reportDone, reportFinished, reportStarted
 
Methods inherited from interface org.pentaho.reporting.engine.classic.core.function.Expression
clone, getDataRow, getDependencyLevel, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setDependencyLevel, setName, setRuntime
 

Constructor Detail

ItemAvgFunction

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


ItemAvgFunction

public ItemAvgFunction(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.

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

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

getGroup

public String getGroup()
Returns the group name.

Specified by:
getGroup in interface AggregationFunction
Returns:
The group name.

setGroup

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

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

Specified by:
setGroup in interface AggregationFunction
Parameters:
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
Returns:
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
Parameters:
field - the field name.

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.

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 - Information about the event.

getValue

public Object getValue()
Returns the function value, in this case the average of all values of a specific column in the report's TableModel.

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