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

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

public class ItemPercentageFunction
extends AbstractFunction

Calculates the percentage value of a numeric field. The total sum is taken and divided by the number of items counted.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
ItemPercentageFunction()
          Creates a new ItemPercentageFunction.
 
Method Summary
 Object clone()
          Returns a clone of the function.
 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()
          Return the current function value.
 void groupStarted(ReportEvent event)
          Receives notification that a group has started.
 boolean isScaleToHundred()
          Returns whether the returned value should be scaled to 100.
 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 reportStarted(ReportEvent event)
          Receives notification that the report has started.
 void setDependencyLevel(int level)
          Sets the dependency level for the expression.
 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 setRuntime(ExpressionRuntime runtime)
          Defines the ExpressionRune used in this expression.
 void setScale(int scale)
          Defines the scale for the divide-operation.
 void setScaleToHundred(boolean scaleToHundred)
          Defines whether the returned value should be scaled to 100.
 
Methods inherited from class org.pentaho.reporting.engine.classic.core.function.AbstractFunction
groupFinished, itemsFinished, itemsStarted, reportDone, reportFinished
 
Methods inherited from class org.pentaho.reporting.engine.classic.core.function.AbstractExpression
getDataRow, getDependencyLevel, 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, getName, getReportConfiguration, getResourceBundleFactory, getRuntime, isActive, isDeepTraversing, isPreserve, setName
 

Constructor Detail

ItemPercentageFunction

public ItemPercentageFunction()
Creates a new ItemPercentageFunction.

Method Detail

isScaleToHundred

public boolean isScaleToHundred()
Returns whether the returned value should be scaled to 100.

Returns:
true, if the value should be scaled to 100, false otherwise.

setScaleToHundred

public void setScaleToHundred(boolean scaleToHundred)
Defines whether the returned value should be scaled to 100.

Parameters:
scaleToHundred - true, if the value should be scaled to 100, false otherwise.

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.

getGroup

public String getGroup()
Returns the group name.

Returns:
The group name.

setGroup

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

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

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.

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.

Parameters:
field - the field name.

reportStarted

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

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

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.

getValue

public Object getValue()
Return the current function value.

Don not count on the correctness of this function until the preparerun has finished.

Returns:
The value of the function.

clone

public Object clone()
             throws CloneNotSupportedException
Returns a clone of the function.

Be aware, this does not create a deep copy. If you have complex strucures contained in objects, you have to overwrite this function.

Specified by:
clone in interface Expression
Overrides:
clone in class AbstractExpression
Returns:
A clone of the function.
Throws:
CloneNotSupportedException - this should never happen.

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.

setDependencyLevel

public void setDependencyLevel(int level)
Description copied from class: AbstractExpression
Sets the dependency level for the expression.

The dependency level controls the order of evaluation for expressions and functions. Higher level expressions are evaluated before lower level expressions. Any level in the range 0 to Integer.MAX_VALUE is allowed. Negative values are reserved for system functions (printing and layouting).

Specified by:
setDependencyLevel in interface Expression
Overrides:
setDependencyLevel in class AbstractExpression
Parameters:
level - the level (must be greater than or equal to 0).

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.

This updates the internal TotalItemSumFunction.

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