diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/aggregation/CountNode.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/aggregation/CountNode.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/aggregation/CountNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/aggregation/CountNode.java new file mode 100644 index 00000000..7c98de0d --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/aggregation/CountNode.java | |||
@@ -0,0 +1,38 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2009 Gabor Bergmann and Daniel Varro | ||
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 | |||
10 | package tools.refinery.viatra.runtime.rete.aggregation; | ||
11 | |||
12 | import java.util.Collection; | ||
13 | |||
14 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
15 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
16 | |||
17 | /** | ||
18 | * An aggregation node that simply counts the number of tuples conforming to the signature. | ||
19 | * | ||
20 | * @author Gabor Bergmann | ||
21 | * @since 1.4 | ||
22 | */ | ||
23 | public class CountNode extends IndexerBasedAggregatorNode { | ||
24 | |||
25 | public CountNode(ReteContainer reteContainer) { | ||
26 | super(reteContainer); | ||
27 | } | ||
28 | |||
29 | int sizeOf(Collection<Tuple> group) { | ||
30 | return group == null ? 0 : group.size(); | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public Object aggregateGroup(Tuple signature, Collection<Tuple> group) { | ||
35 | return sizeOf(group); | ||
36 | } | ||
37 | |||
38 | } | ||