
template.GroupByCalculationState.vsl Maven / Gradle / Ivy
## Velocity Template.
package ${functionPackage};
#foreach( $import in $imports)
import $import;
#end
/**
* Generated group by calculation state holder.
*
*
*
*
* - template file : ${currentTemplate}
*
- input class : target class : ${targetClass}
*
*
* @author Greg Higgins
*/
public final class ${functionClass} implements Wrapper<${targetClass}>{
private static final int SOURCE_COUNT = ${sourceCount};
final BitSet updateMap = new BitSet(SOURCE_COUNT);
private final MutableNumber tempNumber = new MutableNumber();
private int combineCount;
public ${targetClass} ${targetInstanceId};
#foreach( $source in $sourceMappingList)
#if (!${source.staticFunction})
public ${source.functionClassName} ${source.functionInstanceId}Function = new ${source.functionClassName}();
#end
public ${source.functionCalcReturnType} ${source.functionInstanceId};
#end
public ${functionClass}(){
${targetInstanceId} = new ${targetClass}();
#foreach( $optional in $optionals)
updateMap.set($optional);
#end
}
public boolean allMatched(){
return SOURCE_COUNT == updateMap.cardinality();
}
/**
*
* @param index
* @param initialiser
* @param source
* @return The first time this is a complete record is processed
*/
public boolean processSource(int index, GroupByIniitialiser initialiser, Object source) {
boolean prevMatched = allMatched();
if (!updateMap.get(index)) {
initialiser.apply(source, target);
}
updateMap.set(index);
return allMatched() ^ prevMatched;
}
/**
*
* @param index
* @param source
* @return The first time this is a complete record is processed
*/
public boolean processSource(int index, Object source) {
boolean prevMatched = allMatched();
updateMap.set(index);
return allMatched() ^ prevMatched;
}
@Override
public ${targetClass} event() {
return ${targetInstanceId};
}
@Override
public Class<${targetClass}> eventClass() {
return ${targetClass}.class;
}
@Override
public String toString() {
return event().toString();
}
public void combine(${functionClass} other) {
//list the combining operations
combineCount++;
#foreach( $source in $sourceMappingList)
#if (${source.statefulNumeric})
${source.functionInstanceId} = ${source.functionInstanceId}Function.combine(other.${source.functionInstanceId}Function, tempNumber).${source.functionCalcReturnType}Value();
#elseif (${source.stateful})
${source.functionInstanceId}Function.combine(other.${source.functionInstanceId}Function, tempNumber);
#end
#end
}
public void deduct(${functionClass} other) {
combineCount--;
#foreach( $source in $sourceMappingList)
#if (${source.statefulNumeric})
${source.functionInstanceId} = ${source.functionInstanceId}Function.deduct(other.${source.functionInstanceId}Function, tempNumber).${source.functionCalcReturnType}Value();
#elseif (${source.stateful})
${source.functionInstanceId}Function.deduct(other.${source.functionInstanceId}Function, tempNumber);
#end
#end
}
public void aggregateNonStateful(Collection<${functionClass}> states){
//TODO
}
public int getCombineCount() {
return combineCount;
}
public boolean isExpired(){
return combineCount < 1;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy