com.jrefinery.report.function
Class ItemPercentageFunction

java.lang.Object
  extended bycom.jrefinery.report.function.AbstractFunction
      extended bycom.jrefinery.report.function.ItemPercentageFunction
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, Expression, Function, ReportListener, java.io.Serializable

public class ItemPercentageFunction
extends AbstractFunction
implements java.io.Serializable

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

Field Summary
static java.lang.String FIELD_PROPERTY
          Literal text for the 'field' property.
static java.lang.String GROUP_PROPERTY
          Literal text for the 'group' property.
 
Fields inherited from interface com.jrefinery.report.function.Expression
AUTOACTIVATE_PROPERTY
 
Constructor Summary
ItemPercentageFunction()
          Creates a new ItemPercentageFunction.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of the function.
 java.lang.String getField()
          Returns the field used by the function.
 java.lang.String getGroup()
          Returns the name of the group to be counted.
 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 setField(java.lang.String field)
          Sets the field name for the function.
 void setGroup(java.lang.String group)
          Defines the name of the group to be counted (if the name is null, all groups are counted).
 void setProperty(java.lang.String name, java.lang.String value)
          Sets a property for the function.
 
Methods inherited from class com.jrefinery.report.function.AbstractFunction
getDataRow, getDependencyLevel, getName, getProperties, getProperty, getProperty, groupFinished, isActive, itemsFinished, itemsStarted, pageFinished, pageStarted, reportDone, reportFinished, reportStarted, setDataRow, setDependencyLevel, setName, setProperties
 
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

FIELD_PROPERTY

public static final java.lang.String FIELD_PROPERTY
Literal text for the 'field' property.

See Also:
Constant Field Values
Constructor Detail

ItemPercentageFunction

public ItemPercentageFunction()
Creates a new ItemPercentageFunction.

Method Detail

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 default implementation checks that the function name is not null, and calls the isInitialized() method (now deprecated).

Specified by:
initialize in interface Expression
Overrides:
initialize in class AbstractFunction
Throws:
FunctionInitializeException - if the function name is not set or the call to isInitialized returns false.

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 java.lang.Object getValue()
Return the current function value.

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

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

getGroup

public java.lang.String getGroup()
Returns the name of the group to be counted. This is stored in the 'group' property.

Returns:
the group name.

setGroup

public void setGroup(java.lang.String group)
Defines the name of the group to be counted (if the name is null, all groups are counted).

Parameters:
group - the name of the group (null permitted).

getField

public java.lang.String getField()
Returns the field used by the function.

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

Returns:
The field name.

setField

public void setField(java.lang.String field)
Sets the field name for the function.

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

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

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Sets a property for the function.

Overrides:
setProperty in class AbstractFunction
Parameters:
name - The property name.
value - The property value.

clone

public java.lang.Object clone()
                       throws java.lang.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 Function
Overrides:
clone in class AbstractFunction
Returns:
A clone of the function.
Throws:
java.lang.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 AbstractFunction
Returns:
a copy of this function.