template.GroupByTemplate.vsl Maven / Gradle / Ivy
## Velocity Template.
package ${functionPackage};
#foreach( $import in $imports)
import $import;
#end
/**
* generated group by holder.
*
* target class : ${targetClass}
*
* @author Greg Higgins
*/
public final class ${functionClass} implements GroupBy<${targetClass}>{
@NoEventReference public Object resetNotifier;
#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<${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
#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 allMatched = instance.processSource( $velocityCount,#if(${source.initialiserRequired}) ${source.initialiserId}, #end event);
target = instance.target;
#foreach( $functionInfo in ${source.functionSet} )
{
${functionInfo.updateTarget}
}
#end
#if(${eventMethod})
if(allMatched){
target.${eventMethod}();
}
#end
return allMatched;
}
#end
## @OnEvent
## public boolean updated(){
## return true;
## }
##
#if(${eventCompleteMethod})
@OnEventComplete
public void onEventComplete(){
target.${eventCompleteMethod}();
}
#end
@Initialise
public void init(){
calcState = new GroupByTargetMap<>(${calcStateClass}.class);
#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
}
@Override
public ${targetClass} value(Object key) {
return calcState.getInstance(key).target;
}
@Override
public > Map, V> getMap() {
return (Map, V>) calcState.getInstanceMap();
}
@Override
public ${targetClass} event() {
return target;
}
@Override
public Class<${targetClass}> eventClass() {
return ${targetClass}.class;
}
public ${functionClass} resetNotifier(Object resetNotifier) {
this.resetNotifier = resetNotifier;
return this;
}
@OnParentUpdate("resetNotifier")
public void resetNotification(Object resetNotifier) {
init();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy