
template.GroupByTemplate.vsl Maven / Gradle / Ivy
## Velocity Template.
package ${functionPackage};
#foreach( $import in $imports)
import $import;
#end
#importslf4j
/**
* Generated group by aggregation
*
*
*
* - template file : ${currentTemplate}
*
- target class : {@link ${targetClass}}
#foreach( $source in $sourceMappingList)
#if(${source.wrapped})
*
- input class : {@link ${source.sourceInfo.wrapperType}}
#else
*
- input class : {@link ${source.sourceInfo.type}}
#end
#end
*
*
* @author Greg Higgins
*/
public final class ${functionClass} implements GroupBy<${targetClass}>{
#slf4j(${functionClass})
@NoEventReference
public Object resetNotifier;
@SepNode
@PushReference
public ArrayListWrappedCollection<${targetClass}> wrappedList;
private boolean allMatched;
private MutableNumber number = new MutableNumber();
#foreach( $source in $sourceMappingList)
#if($!{source.eventClass})
#elseif(${source.wrapped})
public ${source.sourceInfo.wrapperType} ${source.sourceInfo.id};
#else
public ${source.sourceInfo.type} ${source.sourceInfo.id};
#end
#end
private ${targetClass} target;
private GroupByTargetMap<${keyClass}, ${targetClass}, ${calcStateClass}> calcState;
#if(${isMultiKey})
private ${multiKeyClassName} multiKey;
#end
#foreach( $source in $sourceMappingList)
#if(${source.initialiserRequired})
private GroupByIniitialiser<${source.sourceInfo.type}, ${targetClass}> ${source.initialiserId};
#end
#foreach( $functionInfo in ${source.functionSet} )
#if( ${functionInfo.stateless} && ${functionInfo.instanceFunction} )
private ${functionInfo.functionClassName} ${functionInfo.functionInstanceId};
#end
#end
#end
private SerializableBiConsumer<${targetClass},${targetClass}> initFromCopy;
public ${functionClass}(){
wrappedList = new ArrayListWrappedCollection<>();
}
@Override
public void setTargetCollecion(ArrayListWrappedCollection<${targetClass}> targetCollection) {
this.wrappedList = targetCollection;
}
#foreach( $source in $sourceMappingList)
#set( $id = ${source.sourceInfo.id} )
#set( $type = ${source.sourceInfo.type} )
#set( $wrapperType = ${source.sourceInfo.wrapperType} )
#if(${source.eventClass})
@EventHandler
#else
@OnParentUpdate( "$id")
#end
#if(${source.wrapped})
public boolean update$id($wrapperType eventWrapped){
$type event = ($type)eventWrapped.event();
#else
public boolean update$id($type event){
#end
#if(${isMultiKey})
multiKey.setKey(event);
${calcStateClass} instance = calcState.getOrCreateInstance(multiKey);
#else
${calcStateClass} instance = calcState.getOrCreateInstance(event.${source.keyMethod}());
#end
boolean firstMatched = instance.processSource( $velocityCount,#if(${source.initialiserRequired}) ${source.initialiserId}, #end event);
allMatched = instance.allMatched();
target = instance.target;
#foreach( $functionInfo in ${source.functionSet} )
{
${functionInfo.updateTarget}
}
#end
#if(${source.eventClass})
// updated();
#end
if (firstMatched) {
wrappedList.addItem(target);
}
#if(${eventMethod})
if(allMatched){
target.${eventMethod}();
}
#end
return allMatched;
}
#end
@OnEvent
public boolean updated() {
boolean updated = allMatched;
allMatched = false;
return updated;
}
## @OnEvent
## public boolean updated(){
## return true;
## }
##
#if(${eventCompleteMethod})
@OnEventComplete
public void onEventComplete(){
if (target != null) {
target.${eventCompleteMethod}();
}
}
#end
@Initialise
public void init(){
calcState = new GroupByTargetMap<>(${calcStateClass}::new);
wrappedList.init();
allMatched = false;
target = null;
number.set(0);
#if(${isMultiKey})
multiKey = new ${multiKeyClassName}();
#end
#foreach( $source in $sourceMappingList)
#if(${source.initialiserRequired})
${source.initialiserId} = new GroupByIniitialiser<${source.sourceInfo.type}, ${targetClass}>() {
@Override
public void apply(${source.sourceInfo.type} source, ${targetClass} target) {
#foreach( $initialserInfo in ${source.initialiserSet} )
${initialserInfo.initialiseFunction};
#end
}
};
#end
#foreach( $functionInfo in ${source.functionSet} )
#if( ${functionInfo.stateless} && ${functionInfo.instanceFunction} )
${functionInfo.functionInstanceId} = new ${functionInfo.functionClassName}();
#end
#end
#end
initFromCopy = ${initCopy};
}
#if(${isMultiKey})
//multikey finder
@Override
public ${targetClass} value(Object o){
if(o instanceof ${keyClass}){
return calcState.getInstance((${keyClass})o).target;
}
#foreach( $srcInfo in $multiKeyFunctionSet.entrySet() )
if(o instanceof ${srcInfo.key}){
return value((${srcInfo.key}) o);
}
#end
return null;
}
#foreach( $srcInfo in $multiKeyFunctionSet.entrySet() )
public ${targetClass} value(${srcInfo.key} source){
multiKey.setKey(source);
return value(multiKey);
}
#end
#else
@Override
public ${targetClass} value(Object key) {
return calcState.getInstance((${keyClass})key).target;
}
#end
@Override
public Collection<${targetClass}> collection() {
return wrappedList==null?Collections.EMPTY_LIST:wrappedList.collection();
}
@Override
public © 2015 - 2025 Weber Informatics LLC | Privacy Policy