All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.GroupByCalculationState.vsl Maven / Gradle / Ivy

## Velocity Template.
package ${functionPackage};

#foreach( $import in $imports)
import $import;
#end

/**
 * generated group by calculation state holder. This class holds the state of
 * a group by calculation.
 *
 * target class  : ${targetClass}
 * 
 * @author Greg Higgins
 */
public final class ${functionClass} implements Wrapper<${targetClass}>{

    private static final int SOURCE_COUNT = ${sourceCount};
    private final BitSet updateMap = new BitSet(SOURCE_COUNT);

    public ${targetClass} ${targetInstanceId};
#foreach( $source in $sourceMappingList)
#if (${source.stateful})
    public ${source.functionClassName} ${source.functionInstanceId}Function = new ${source.functionClassName}();
#end
    public ${source.functionCalcArgType} ${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();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy