A report function that pre-computes the largest item in a group. The Items must be mutually comparable
among each other or the function will fail. Comparing dates with strings will not work.
Like all Total-Functions, this function produces a precomputed grand total. The function's result
is precomputed once and will not change later. Printing the result of this function in a group header
returns the same value as printed in the group-footer.
A group can be defined using the property "group". If the group property is not set, the function will process the
whole report.
| Method from org.jfree.report.function.TotalItemMaxFunction Detail: |
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;
}
Returns the name of the group for which the minimum should be computed. |
public Expression getInstance() {
final TotalItemMaxFunction function = (TotalItemMaxFunction) super.getInstance();
function.results = new HashMap();
return function;
}
Return a completly separated copy of this function. The copy does no longer share any
changeable objects with the original function. |
public Object getValue() {
return max;
}
Returns the computed maximum value. |
public void groupStarted(ReportEvent event) {
if (FunctionUtilities.isDefinedGroup(getGroup(), event) == false)
{
// wrong group ...
return;
}
groupStateKey = event.getState().getProcessKey();
if (FunctionUtilities.isDefinedPrepareRunLevel(this, event))
{
this.max = null;
results.put(globalStateKey, max);
results.put(groupStateKey, max);
}
else
{
// Activate the current group, which was filled in the prepare run.
max = (Integer) results.get(groupStateKey);
}
}
Receives notification that a group has started. |
public void itemsAdvanced(ReportEvent event) {
if (FunctionUtilities.isDefinedPrepareRunLevel(this, event) == false)
{
return;
}
final Object fieldValue = event.getDataRow().get(getField());
if (fieldValue instanceof Comparable == false)
{
return;
}
try
{
final Comparable compare = (Comparable) fieldValue;
if (max == null)
{
max = compare;
}
else if (max.compareTo(compare) < 0)
{
max = compare;
}
}
catch (Exception e)
{
TotalItemMaxFunction.logger.error("TotalItemMaxFunction.advanceItems(): problem comparing values.");
}
results.put(globalStateKey, max);
if (groupStateKey != null)
{
results.put(groupStateKey, max);
}
}
Receives notification that a row of data is being processed. |
public void reportInitialized(ReportEvent event) {
globalStateKey = event.getState().getProcessKey();
if (FunctionUtilities.isDefinedPrepareRunLevel(this, event))
{
results.clear();
this.max = null;
results.put(globalStateKey, null);
}
else
{
this.max = (Comparable) results.get(globalStateKey);
}
}
Receives notification that the report has started. |
public void setField(String field) {
this.field = 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 group) {
this.group = group;
}
Defines the name of the group to be totalled. If the name is null, the minimum for the whole report is computed. |