📄 totalcalculationfunction.java
字号:
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner;
*
* (C) Copyright 2000-2002, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* -------------------------
* TextFormatExpression.java
* -------------------------
* (C)opyright 2002, by Simba Management Limited and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): -;
*
* $Id: TotalCalculationFunction.java,v 1.8.2.1 2003/08/24 14:18:08 taqua Exp $
*
* Changes
* -------
* 07-Mar-2003 : Initial version
*
*/
package com.jrefinery.report.function;
import java.io.Serializable;
import java.util.ArrayList;
import com.jrefinery.report.event.ReportEvent;
/**
* A report function that stores the result of a calculation for a group or the
* complete report. The field value, that was read when the group finished, is
* stored and returned when the group gets active again in a higher processing level.
* <p>
* This function can be used to calculate total values for a group, f.I. a TotalMax
* for the group, which returns the maximum value encountered for that field in the
* current group. The computed values are available to all bands of the group.
* <p>
* The function undestands two parameters, the <code>field</code> parameter is required and
* denotes the name of an ItemBand-field which gets summed up.
* <p>
* The parameter <code>group</code> denotes the name of a group. When this group is started,
* the counter gets reseted to null. This parameter is optional.
*
* @author Thomas Morgner
*/
public class TotalCalculationFunction extends AbstractFunction implements Serializable
{
/** Literal text for the 'group' property. */
public static final String GROUP_PROPERTY = "group";
/** A list of results. */
private ArrayList storedResults;
/** The current index. */
private int currentIndex;
/** The current object. */
private transient Object currentObject;
/**
* Constructs a new function.
* <P>
* Initially the function has no name...be sure to assign one before using the function.
*/
public TotalCalculationFunction()
{
storedResults = new ArrayList();
}
/**
* Receives notification that the report has started.
*
* @param event the event.
*/
public void reportInitialized(final ReportEvent event)
{
currentIndex = -1;
if (FunctionUtilities.isDefinedPrepareRunLevel(this, event))
{
storedResults.clear();
}
}
/**
* Receives notification that a group has started.
*
* @param event the event.
*/
public void groupStarted(final ReportEvent event)
{
if (FunctionUtilities.isDefinedGroup(getGroup(), event) == false)
{
// wrong group ...
return;
}
if (FunctionUtilities.isDefinedPrepareRunLevel(this, event))
{
currentObject = null;
}
else
{
// Activate the current group, which was filled in the prepare run.
if (event.getState().isPrepareRun() == false)
{
currentIndex += 1;
currentObject = storedResults.get(currentIndex);
}
}
}
/**
* Receives notification that a group has finished.
*
* @param event the event.
*/
public void groupFinished(final ReportEvent event)
{
if (FunctionUtilities.isDefinedGroup(getGroup(), event) == false)
{
// wrong group ...
return;
}
if (FunctionUtilities.isDefinedPrepareRunLevel(this, event))
{
storedResults.add(currentObject);
}
}
/**
* Returns the name of the group to be totalled.
*
* @return the group name.
*/
public String getGroup()
{
return getProperty(GROUP_PROPERTY);
}
/**
* Defines the name of the group to be totalled.
* If the name is null, all groups are totalled.
*
* @param group the group name.
*/
public void setGroup(final String group)
{
setProperty(GROUP_PROPERTY, group);
}
/**
* Return the current expression value.
* <P>
* The value depends (obviously) on the expression implementation.
*
* @return the value of the function.
*/
public Object getValue()
{
return currentObject;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -