diff options
Diffstat (limited to 'subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/aggregators/avg.java')
-rw-r--r-- | subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/aggregators/avg.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/aggregators/avg.java b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/aggregators/avg.java new file mode 100644 index 00000000..0d0449d2 --- /dev/null +++ b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/aggregators/avg.java | |||
@@ -0,0 +1,39 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Zoltan Ujhelyi, IncQuery Labs Ltd. | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.interpreter.matchers.aggregators; | ||
10 | |||
11 | import tools.refinery.interpreter.matchers.psystem.aggregations.AggregatorType; | ||
12 | import tools.refinery.interpreter.matchers.psystem.aggregations.BoundAggregator; | ||
13 | import tools.refinery.interpreter.matchers.psystem.aggregations.IAggregatorFactory; | ||
14 | |||
15 | /** | ||
16 | * This aggregator calculates the average of the values of a selected aggregate parameter of a called pattern. The aggregate | ||
17 | * parameter is selected with the '#' symbol; the aggregate parameter must not be used outside the aggregator call. The | ||
18 | * other parameters of the call might be bound or unbound; bound parameters limit the matches to consider for the | ||
19 | * summation. | ||
20 | * | ||
21 | * @since 2.0 | ||
22 | * | ||
23 | */ | ||
24 | @AggregatorType( | ||
25 | parameterTypes = {Integer.class, Double.class, Long.class}, | ||
26 | returnTypes = {Double.class, Double.class, Double.class}) | ||
27 | public final class avg implements IAggregatorFactory { | ||
28 | |||
29 | @Override | ||
30 | public BoundAggregator getAggregatorLogic(Class<?> domainClass) { | ||
31 | if (Integer.class.equals(domainClass)) | ||
32 | return new BoundAggregator(IntegerAverageOperator.INSTANCE, Integer.class, Double.class); | ||
33 | if (Double.class.equals(domainClass)) | ||
34 | return new BoundAggregator(DoubleAverageOperator.INSTANCE, Double.class, Double.class); | ||
35 | if (Long.class.equals(domainClass)) | ||
36 | return new BoundAggregator(LongAverageOperator.INSTANCE, Long.class, Double.class); | ||
37 | else throw new IllegalArgumentException(); | ||
38 | } | ||
39 | } | ||