Class ItemPercentageFunction
- java.lang.Object
-
- org.pentaho.reporting.engine.classic.core.function.AbstractExpression
-
- org.pentaho.reporting.engine.classic.core.function.AbstractFunction
-
- 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
Constructors Constructor Description ItemPercentageFunction()
Creates a new ItemPercentageFunction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
clone()
Returns a clone of the function.String
getCrosstabFilterGroup()
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
setCrosstabFilterGroup(String crosstabFilterGroup)
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, summaryRowSelection
-
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, finalize, 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
-
-
-
-
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).
-
getCrosstabFilterGroup
public String getCrosstabFilterGroup()
-
setCrosstabFilterGroup
public void setCrosstabFilterGroup(String crosstabFilterGroup)
-
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 interfaceReportListener
- Overrides:
reportStarted
in classAbstractFunction
- Parameters:
event
- the event.
-
groupStarted
public void groupStarted(ReportEvent event)
Receives notification that a group has started.- Specified by:
groupStarted
in interfaceReportListener
- Overrides:
groupStarted
in classAbstractFunction
- Parameters:
event
- the event.
-
itemsAdvanced
public void itemsAdvanced(ReportEvent event)
Receives notification that a row of data is being processed.- Specified by:
itemsAdvanced
in interfaceReportListener
- Overrides:
itemsAdvanced
in classAbstractFunction
- Parameters:
event
- the event.
-
reportInitialized
public void reportInitialized(ReportEvent event)
Receives notification that the report has started.- Specified by:
reportInitialized
in interfaceReportListener
- Overrides:
reportInitialized
in classAbstractFunction
- 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 interfaceExpression
- Overrides:
clone
in classAbstractExpression
- 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 interfaceExpression
- Overrides:
getInstance
in classAbstractExpression
- 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 interfaceExpression
- Overrides:
setDependencyLevel
in classAbstractExpression
- 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 interfaceExpression
- Overrides:
setRuntime
in classAbstractExpression
- Parameters:
runtime
- the runtime information for the expression
-
-