From 92d4704dd69b8d73fb486103dcae13fc366e0518 Mon Sep 17 00:00:00 2001 From: aivanov Date: Tue, 29 Sep 2015 14:49:04 +0300 Subject: [PATCH] fixed averageSeries function --- .../graphite/functions/AverageSeriesFunction.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/iponweb/disthene/reader/graphite/functions/AverageSeriesFunction.java b/src/main/java/net/iponweb/disthene/reader/graphite/functions/AverageSeriesFunction.java index 70d01c6d..eb90f150 100644 --- a/src/main/java/net/iponweb/disthene/reader/graphite/functions/AverageSeriesFunction.java +++ b/src/main/java/net/iponweb/disthene/reader/graphite/functions/AverageSeriesFunction.java @@ -27,7 +27,9 @@ public AverageSeriesFunction(String text) { @Override public List evaluate(TargetEvaluator evaluator) throws EvaluationException { List processedArguments = new ArrayList<>(); - processedArguments.addAll(evaluator.eval((Target) arguments.get(0))); + for (Object argument : arguments) { + processedArguments.addAll(evaluator.eval((Target) argument)); + } if (processedArguments.size() == 0) return new ArrayList<>(); @@ -60,7 +62,11 @@ public List evaluate(TargetEvaluator evaluator) throws EvaluationExc @Override public void checkArguments() throws InvalidArgumentException { - if (arguments.size() > 1 || arguments.size() == 0) throw new InvalidArgumentException("averageSeries: number of arguments is " + arguments.size() + ". Must be one."); - if (!(arguments.get(0) instanceof Target)) throw new InvalidArgumentException("averageSeries: argument is " + arguments.get(0).getClass().getName() + ". Must be series"); + if (arguments.size() == 0) throw new InvalidArgumentException("averageSeries: number of arguments is " + arguments.size() + ". Must be at least one."); + + for (int i = 0; i < arguments.size() - 1; i++) { + if (!(arguments.get(i) instanceof Target)) + throw new InvalidArgumentException("averageSeries: argument is " + arguments.get(i).getClass().getName() + ". Must be series"); + } } } \ No newline at end of file