diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/ISetMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/ISetMemory.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/ISetMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/ISetMemory.java new file mode 100644 index 00000000..0c03da48 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/util/ISetMemory.java | |||
@@ -0,0 +1,37 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2018, Gabor Bergmann, IncQueryLabs 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.viatra.runtime.matchers.util; | ||
10 | |||
11 | import java.util.function.BiConsumer; | ||
12 | |||
13 | /** | ||
14 | * An {@link IMemory} that always contains values with a 0 or +1 multiplicity. | ||
15 | * | ||
16 | * <p> In case a write operation causes underflow or overflow, an {@link IllegalStateException} is thrown. | ||
17 | * | ||
18 | * @author Gabor Bergmann | ||
19 | * @since 2.0 | ||
20 | */ | ||
21 | public interface ISetMemory<T> extends IMemory<T> { | ||
22 | |||
23 | @Override | ||
24 | default void forEachEntryWithMultiplicities(BiConsumer<T, Integer> entryConsumer) { | ||
25 | for (T t : this.distinctValues()) entryConsumer.accept(t, 1); | ||
26 | } | ||
27 | |||
28 | |||
29 | @Override | ||
30 | default boolean removeOne(T value) { | ||
31 | if (!removeOneOrNop(value)) | ||
32 | throw new IllegalStateException(); | ||
33 | return true; | ||
34 | } | ||
35 | |||
36 | |||
37 | } | ||