Calculates the percentage value of a numeric field. The total sum is taken and divided by the number of items
counted.
| Method from org.jfree.report.function.ItemPercentageFunction Detail: |
public Object clone() throws CloneNotSupportedException {
final ItemPercentageFunction clone = (ItemPercentageFunction) super.clone();
clone.totalSumFunction = (TotalGroupSumFunction) totalSumFunction.clone();
return clone;
}
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. |
public String getField() {
return field;
}
Returns the field used by the function. The field name corresponds to a column name in the report's data-row. |
public String getGroup() {
return group;
}
|
public Expression getInstance() {
final ItemPercentageFunction function = (ItemPercentageFunction) super.getInstance();
function.totalSumFunction = (TotalGroupSumFunction) totalSumFunction.getInstance();
function.currentValue = ItemPercentageFunction.ZERO;
return function;
}
Return a completly separated copy of this function. The copy does no longer share any changeable objects with the
original function. |
public int getRoundingMode() {
return roundingMode;
}
Returns the defined rounding mode. This influences the precision of the divide-operation. |
public int getScale() {
return scale;
}
Returns the scale for the divide-operation. The scale influences the precision of the division. |
public Object getValue() {
final BigDecimal total = (BigDecimal) totalSumFunction.getValue();
if (total == null || total.longValue() == 0)
{
return null;
}
if (scaleToHundred)
{
return currentValue.multiply(ItemPercentageFunction.HUNDRED).divide(total, scale, roundingMode);
}
else
{
return currentValue.divide(total, scale, roundingMode);
}
}
|
public void groupStarted(ReportEvent event) {
totalSumFunction.groupStarted(event);
final Object fieldValue = event.getDataRow().get(getField());
if (fieldValue == null)
{
// No add, field is null
currentValue = ItemPercentageFunction.ZERO;
return;
}
try
{
final Number n = (Number) fieldValue;
currentValue = new BigDecimal(n.toString());
}
catch (Exception e)
{
ItemPercentageFunction.logger.error("ItemPercentageFunction.groupStarted(): problem adding number.");
}
}
Receives notification that a group has started. |
public boolean isScaleToHundred() {
return scaleToHundred;
}
Returns whether the returned value should be scaled to 100. |
public void itemsAdvanced(ReportEvent event) {
totalSumFunction.itemsAdvanced(event);
final Object fieldValue = event.getDataRow().get(getField());
if (fieldValue == null)
{
// No add, field is null
currentValue = ItemPercentageFunction.ZERO;
return;
}
try
{
final Number n = (Number) fieldValue;
currentValue = new BigDecimal(n.toString());
}
catch (Exception e)
{
ItemPercentageFunction.logger.error("ItemPercentageFunction.advanceItems(): problem adding number.");
}
}
Receives notification that a row of data is being processed. |
public void reportInitialized(ReportEvent event) {
totalSumFunction.reportInitialized(event);
currentValue = ItemPercentageFunction.ZERO;
}
Receives notification that the report has started. |
public void reportStarted(ReportEvent event) {
totalSumFunction.reportStarted(event);
final Object fieldValue = event.getDataRow().get(getField());
if (fieldValue == null)
{
// No add, field is null
currentValue = ItemPercentageFunction.ZERO;
return;
}
try
{
final Number n = (Number) fieldValue;
currentValue = new BigDecimal(n.toString());
}
catch (Exception e)
{
ItemPercentageFunction.logger.error("ItemPercentageFunction.reportStarted(): problem adding number.");
}
}
Receives notification that the report has started. |
public void setDependencyLevel(int level) {
super.setDependencyLevel(level);
totalSumFunction.setDependencyLevel(level);
}
|
public void setField(String field) {
this.field = field;
this.totalSumFunction.setField(field);
}
Sets the field name for the function. The field name corresponds to a column name in the report's data-row. |
public void setGroup(String name) {
this.group = name;
this.totalSumFunction.setGroup(group);
}
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. |
public void setRoundingMode(int roundingMode) {
this.roundingMode = roundingMode;
}
Defines the rounding mode. This influences the precision of the divide-operation. |
public void setRuntime(ExpressionRuntime runtime) {
super.setRuntime(runtime);
totalSumFunction.setRuntime(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. |
public void setScale(int scale) {
this.scale = scale;
}
Defines the scale for the divide-operation. The scale influences the precision of the division. |
public void setScaleToHundred(boolean scaleToHundred) {
this.scaleToHundred = scaleToHundred;
}
Defines whether the returned value should be scaled to 100. |