diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/Bag.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/Bag.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/Bag.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/Bag.java new file mode 100644 index 00000000..4aef0f96 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/Bag.java | |||
@@ -0,0 +1,43 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2008 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.misc; | ||
11 | |||
12 | import java.util.Collection; | ||
13 | import java.util.LinkedList; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
16 | import tools.refinery.viatra.runtime.matchers.util.Direction; | ||
17 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
18 | import tools.refinery.viatra.runtime.rete.network.communication.Timestamp; | ||
19 | |||
20 | /** | ||
21 | * @author Gabor Bergmann | ||
22 | * | ||
23 | * A bag is a container that tuples can be dumped into. Does NOT propagate updates! Optimized for small contents | ||
24 | * size OR positive updates only. | ||
25 | */ | ||
26 | public class Bag extends SimpleReceiver { | ||
27 | |||
28 | public Collection<Tuple> contents; | ||
29 | |||
30 | public Bag(ReteContainer reteContainer) { | ||
31 | super(reteContainer); | ||
32 | contents = new LinkedList<Tuple>(); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public void update(Direction direction, Tuple updateElement, Timestamp timestamp) { | ||
37 | if (direction == Direction.INSERT) | ||
38 | contents.add(updateElement); | ||
39 | else | ||
40 | contents.remove(updateElement); | ||
41 | } | ||
42 | |||
43 | } | ||