a(PUBLIC, FINAL),
makeClassName(metadata.getName() + accumulatorInterface.getSimpleName()),
type(Object.class),
type(accumulatorInterface));
CallSiteBinder callSiteBinder = new CallSiteBinder();
AccumulatorStateSerializer<?> stateSerializer = metadata.getStateSerializer();
AccumulatorStateFactory<?> stateFactory = metadata.getStateFactory();
FieldDefinition stateSerializerField = definition.declareField(a(PRIVATE, FINAL), "stateSerializer", AccumulatorStateSerializer.class);
FieldDefinition stateFactoryField = definition.declareField(a(PRIVATE, FINAL), "stateFactory", AccumulatorStateFactory.class);
FieldDefinition inputChannelsField = definition.declareField(a(PRIVATE, FINAL), "inputChannels", type(List.class, Integer.class));
FieldDefinition maskChannelField = definition.declareField(a(PRIVATE, FINAL), "maskChannel", type(Optional.class, Integer.class));
FieldDefinition sampleWeightChannelField = null;
FieldDefinition confidenceField = null;
if (approximate) {
sampleWeightChannelField = definition.declareField(a(PRIVATE, FINAL), "sampleWeightChannel", type(Optional.class, Integer.class));
confidenceField = definition.declareField(a(PRIVATE, FINAL), "confidence", double.class);
}
FieldDefinition stateField = definition.declareField(a(PRIVATE, FINAL), "state", grouped ? stateFactory.getGroupedStateClass() : stateFactory.getSingleStateClass());
// Generate constructor
generateConstructor(
definition,
stateSerializerField,
stateFactoryField,
inputChannelsField,
maskChannelField,
sampleWeightChannelField,
confidenceField,
stateField,
grouped);
// Generate methods
generateAddInput(definition, stateField, inputChannelsField, maskChannelField, sampleWeightChannelField, metadata.getInputMetadata(), metadata.getInputFunction(), callSiteBinder, grouped);
generateGetEstimatedSize(definition, stateField);
MethodDefinition getIntermediateType = generateGetIntermediateType(definition, callSiteBinder, stateSerializer.getSerializedType());
MethodDefinition getFinalType = generateGetFinalType(definition, callSiteBinder, metadata.getOutputType());
if (metadata.getIntermediateInputFunction() == null) {
generateAddIntermediateAsCombine(definition, stateField, stateSerializerField, stateFactoryField, metadata.getCombineFunction(), stateFactory.getSingleStateClass(), grouped);
}
else {
generateAddIntermediateAsIntermediateInput(definition, stateField, metadata.getIntermediateInputMetadata(), metadata.getIntermediateInputFunction(), callSiteBinder, grouped);
}
if (grouped) {
generateGroupedEvaluateIntermediate(definition, stateSerializerField, stateField);
}
else {
generateEvaluateIntermediate(definition, getIntermediateType, stateSerializerField, stateField);
}
if (grouped) {
generateGroupedEvaluateFinal(definition, confidenceField, stateSerializerField, stateField, metadata.getOutputFunction(), metadata.isApproximate());
}
else {
generateEvaluateFinal(definition, getFinalType, confidenceField, stateSerializerField, stateField, metadata.getOutputFunction(), metadata.isApproximate());
}
return defineClass(definition, accumulatorInterface, callSiteBinder.getBindings(), classLoader);
}