blob: 69ff2e75cedb23ed72d85f6bbadfdf79df2c9a45 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
/*******************************************************************************
* Copyright (c) 2010-2016, Zoltan Ujhelyi, IncQuery Labs Ltd.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-v20.html.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package tools.refinery.viatra.runtime.matchers.aggregators;
import tools.refinery.viatra.runtime.matchers.psystem.aggregations.AggregatorType;
import tools.refinery.viatra.runtime.matchers.psystem.aggregations.BoundAggregator;
import tools.refinery.viatra.runtime.matchers.psystem.aggregations.IAggregatorFactory;
/**
* This aggregator calculates the sum of the values of a selected aggregate parameter of a called pattern. The aggregate
* parameter is selected with the '#' symbol; the aggregate parameter must not be used outside the aggregator call. The
* other parameters of the call might be bound or unbound; bound parameters limit the matches to consider for the
* summation.
*
* @since 1.4
*
*/
@AggregatorType(
parameterTypes = {Integer.class, Double.class, Long.class},
returnTypes = {Integer.class, Double.class, Long.class})
public final class sum implements IAggregatorFactory {
@Override
public BoundAggregator getAggregatorLogic(Class<?> domainClass) {
if (Integer.class.equals(domainClass))
return new BoundAggregator(IntegerSumOperator.INSTANCE, Integer.class, Integer.class);
if (Double.class.equals(domainClass))
return new BoundAggregator(DoubleSumOperator.INSTANCE, Double.class, Double.class);
if (Long.class.equals(domainClass))
return new BoundAggregator(LongSumOperator.INSTANCE, Long.class, Long.class);
else throw new IllegalArgumentException();
}
}
|