diff options
Diffstat (limited to 'subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/tuple/VolatileMaskedTuple.java')
-rw-r--r-- | subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/tuple/VolatileMaskedTuple.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/tuple/VolatileMaskedTuple.java b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/tuple/VolatileMaskedTuple.java new file mode 100644 index 00000000..c47a1b89 --- /dev/null +++ b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/tuple/VolatileMaskedTuple.java | |||
@@ -0,0 +1,50 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2017, 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.tuple; | ||
10 | |||
11 | import tools.refinery.interpreter.matchers.util.Preconditions; | ||
12 | |||
13 | /** | ||
14 | * This class provides a volatile tuple view with a given mask of a given tuple instance. If the masked tuple changes, | ||
15 | * the view updates as well. | ||
16 | * | ||
17 | * @author Zoltan Ujhelyi | ||
18 | * @since 1.7 | ||
19 | * | ||
20 | */ | ||
21 | public class VolatileMaskedTuple extends VolatileTuple { | ||
22 | |||
23 | protected final TupleMask mask; | ||
24 | protected ITuple source; | ||
25 | |||
26 | public VolatileMaskedTuple(ITuple source, TupleMask mask) { | ||
27 | this.source = source; | ||
28 | this.mask = mask; | ||
29 | } | ||
30 | |||
31 | public VolatileMaskedTuple(TupleMask mask) { | ||
32 | this(null, mask); | ||
33 | } | ||
34 | |||
35 | public void updateTuple(ITuple newSource) { | ||
36 | source = newSource; | ||
37 | } | ||
38 | |||
39 | @Override | ||
40 | public Object get(int index) { | ||
41 | Preconditions.checkState(source != null, "Source tuple is not set."); | ||
42 | return mask.getValue(source, index); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public int getSize() { | ||
47 | return mask.getSize(); | ||
48 | } | ||
49 | |||
50 | } | ||