使用 Eclipse BIRT 扩展点:聚合
2010-03-30 00:00:00 来源:WEB开发网IAggrFunction 类具有两项任务:它将自身描述为工厂可以创建的聚合,它还会创建 Accumulator 类的实例来为您的聚合执行实际工作。清单 2 给出了代码。
清单 2. 完成后的聚合函数和 Accumulator 类
public class BasicWordcount implements IAggrFunction {
private final static String sDescription =
"This aggregation will count all words in a column and return the count.";
private final static String sName = "Word Count";
private final static String sDisplayName = "Basic Word Count Aggregator";
public int getDataType() {
return DataType.INTEGER_TYPE;
}
public Object getDefaultValue() {
return new Integer(0);
}
public String getDescription() {
return this.sDescription;
}
public String getDisplayName() {
return this.sDisplayName;
}
public String getName() {
return this.sName;
}
public int getNumberOfPasses() {
return 1;
}
public IParameterDefn[] getParameterDefn() {
IParameterDefn paramDef = new IParameterDefn() {
public boolean supportDataType(int paramType) {
if (paramType == DataType.STRING_TYPE)
{
return true;
}
return false;
}
public boolean isOptional() {
return false;
}
public boolean isDataField() {
return false;
}
public String getName() {
return "StringColumn";
}
public String getDisplayName() {
return "String Column";
}
public String getDescription() {
return "A column expression that is a String";
}
};
IParameterDefn[] parameterDefinitionArray = new IParameterDefn[]
{paramDef};
return parameterDefinitionArray;
}
public int getType() {
return IAggrFunction.SUMMARY_AGGR;
}
public boolean isDataOrderSensitive() {
return false;
}
public Accumulator newAccumulator() {
return new Accumulator()
{
int sum;
@Override
public Object getValue() throws DataException {
return new Integer(sum);
}
@Override
public void onRow(Object[] incomingStrings) throws DataException {
String localString = (String) incomingStrings[0];
sum += localString.split(" ").length;
}
};
}
}
更多精彩
赞助商链接