📄 printdatafunction.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.print;
import java.math.*;
import org.compiere.util.*;
/**
* Print Data Function
*
* @author Jorg Janke
* @version $Id: PrintDataFunction.java,v 1.3 2002/11/02 06:06:01 jjanke Exp $
*/
public class PrintDataFunction
{
/**
* Constructor
*/
public PrintDataFunction ()
{
} // PrintDataFunction
/** The Sum */
private BigDecimal m_sum = Env.ZERO;
/** The Count */
private int m_count = 0;
/** Total Count */
private int m_totalCount = 0;
static public final char F_SUM = 'S';
static public final char F_AVERAGE = 'A';
static public final char F_COUNT = 'C';
/** Function Keys */
static private final char[] FUNCTIONS = new char[]
{F_SUM, F_AVERAGE, F_COUNT};
/** Symbols */
static private final String[] FUNCTION_SYMBOLS = new String[]
{" \u2211", " \u00D8", " \u2116"};
/** AD_Message Names of Functions */
static private final String[] FUNCTION_NAMES = new String[]
{"Sum", "Average", "Count"};
/**
* Add Value to Counter
* @param bd data
*/
public void addValue (BigDecimal bd)
{
if (bd != null)
{
m_sum = m_sum.add(bd);
m_count++;
}
m_totalCount++;
} // addValue
/**
* Get Function Value
* @param function function
* @return function value
*/
public BigDecimal getValue(char function)
{
if (function == F_SUM)
return m_sum;
BigDecimal count = new BigDecimal((double)m_count);
if (function == F_COUNT)
return count;
// Average
if (m_count == 0)
return Env.ZERO;
BigDecimal result = m_sum.divide(count, BigDecimal.ROUND_HALF_UP);
if (result.scale() > 4)
result = result.setScale(4, BigDecimal.ROUND_HALF_UP);
return result;
} // getValue
/**
* Reset Value
*/
public void reset()
{
m_count = 0;
m_totalCount = 0;
m_sum = Env.ZERO;
} // reset
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("[");
sb.append("Count=").append(m_count).append(",Sum=").append(m_sum);
sb.append("]");
return sb.toString();
} // toString
/*************************************************************************/
/**
* Get Function Symbol of function
* @param function function
* @return function symbol
*/
static public String getFunctionSymbol (char function)
{
for (int i = 0; i < FUNCTIONS.length; i++)
{
if (FUNCTIONS[i] == function)
return FUNCTION_SYMBOLS[i];
}
return "UnknownFunction=" + function;
} // getFunctionSymbol
/**
* Get Function Name of function
* @param function function
* @return function name
*/
static public String getFunctionName (char function)
{
for (int i = 0; i < FUNCTIONS.length; i++)
{
if (FUNCTIONS[i] == function)
return FUNCTION_NAMES[i];
}
return "UnknownFunction=" + function;
} // getFunctionName
/**
* Get Funcuion Name of function
* @param function function
* @return function name
*/
static public int getFunctionDisplayType (char function)
{
if (function == F_SUM)
return DisplayType.Amount;
if (function == F_COUNT)
return DisplayType.Integer;
// Average
return DisplayType.Number;
} // getFunctionName
} // PrintDataFunction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -