use of com.srotya.sidewinder.core.functions.iterative.FunctionIteratorFactory.FunctionTemplate in project sidewinder by srotya.
the class MiscUtils method createIteratorChain.
public static FunctionIteratorFactory createIteratorChain(String[] parts, int startIndex) throws Exception {
List<FunctionTemplate> templates = new ArrayList<>();
for (int k = startIndex; k < parts.length; k++) {
String[] args = parts[k].split(",");
Class<? extends FunctionIterator> lookupFunction = FunctionIteratorTable.get().lookupFunction(args[0]);
if (lookupFunction == null) {
throw new BadRequestException("Unknown function:" + args[0]);
}
FunctionIterator instance = FunctionIterator.getDummyInstance(lookupFunction);
if (args.length - 1 < instance.getNumberOfArgs()) {
throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1));
}
Object[] ary = new Object[args.length - 1];
for (int i = 1; i < args.length; i++) {
Matcher matcher = NUMBER.matcher(args[i]);
if (matcher.matches()) {
if (matcher.group(1) != null) {
ary[i - 1] = Double.parseDouble(args[i]);
} else {
ary[i - 1] = Integer.parseInt(args[i]);
}
} else {
ary[i - 1] = args[i];
}
}
instance.init(ary);
templates.add(new FunctionTemplate(lookupFunction, ary));
}
return new FunctionIteratorFactory(templates);
}
Aggregations