public interface DataFunction
extends java.lang.Cloneable, java.io.Serializable
addData(Object)
method onec or several times to add data into the function,invoke getResult()
method
to get the result.
the code below is the source code of (SumFunction
) :
public class SumFunction extends AbstractDataFunction { private double sumResult; public void reset() { sumResult = 0; } public void addData(Object data) { if (data == null) { return; } //number value. if (data instanceof Number) { sumResult += ((Number) data).doubleValue(); } else if (data instanceof Boolean) { if(((Boolean)data).booleanValue()) { sumResult += 1; } } else { try { sumResult += Double.valueOf(data.toString()).doubleValue(); } catch (NumberFormatException exp) { } } } public Object getResult() { return new Double(sumResult); } }
These code demonstrates how to caculate by using DataFunction
:
DataFunction function = new SumFunction(); function.addData(new Double(1)); function.addData(new Double(2)); function.addData("3"); //Print the result, 1 + 2 + 3 = 6 Object result = function.getResult(); System.out.println("Result=" + result);
限定符和类型 | 方法和说明 |
---|---|
void |
addData(java.lang.Object data)
Adds data to the function.
|
void |
cal_after_traverse_result(GroupList gl) |
void |
cal_when_traverse_result(GroupList gl,
java.lang.Object value) |
java.lang.Object |
clone()
Clone.
|
boolean |
equals(java.lang.Object obj)
Equals.
|
java.lang.String |
getFormula() |
java.lang.Object |
getResult()
Gets the calculated result of the function.
|
void |
reset()
Reset the result of DataFunction, restart to add data to DataFunction.
|
void reset()
void addData(java.lang.Object data)
Object
java.lang.Object getResult()
Object
void cal_when_traverse_result(GroupList gl, java.lang.Object value)
void cal_after_traverse_result(GroupList gl)
boolean equals(java.lang.Object obj)
equals
在类中 java.lang.Object
java.lang.Object clone() throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
java.lang.String getFormula()