diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-10-02 20:51:58 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-10-02 20:51:58 +0200 |
commit | 9b8236dd7499510577c32f0d87dfd52d34f6b023 (patch) | |
tree | d9e35fa5692e3b08d0bcf1fbbd538c65ed4b58e1 /store/src/main/java/org/eclipse/viatra/solver/data/model | |
parent | build: simplify Eclipse project generation (diff) | |
download | refinery-9b8236dd7499510577c32f0d87dfd52d34f6b023.tar.gz refinery-9b8236dd7499510577c32f0d87dfd52d34f6b023.tar.zst refinery-9b8236dd7499510577c32f0d87dfd52d34f6b023.zip |
chore: fix Java 17 Sonar warnings
Had to disable code coverage measurement in the Quality Gate, we should
switch it on again once we have a complete test suite.
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/model')
-rw-r--r-- | store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java | 26 | ||||
-rw-r--r-- | store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java | 47 |
2 files changed, 37 insertions, 36 deletions
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java index f5e3b141..a97fb27a 100644 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java | |||
@@ -1,7 +1,6 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | 1 | package org.eclipse.viatra.solver.data.model; |
2 | 2 | ||
3 | import java.util.HashMap; | 3 | import java.util.HashMap; |
4 | import java.util.HashSet; | ||
5 | import java.util.LinkedList; | 4 | import java.util.LinkedList; |
6 | import java.util.List; | 5 | import java.util.List; |
7 | import java.util.Map; | 6 | import java.util.Map; |
@@ -34,8 +33,7 @@ public class ModelStoreImpl implements ModelStore { | |||
34 | Map<SimilarRelationEquivalenceClass, List<Relation<?>>> symbolRepresentationsPerHashPerArity = new HashMap<>(); | 33 | Map<SimilarRelationEquivalenceClass, List<Relation<?>>> symbolRepresentationsPerHashPerArity = new HashMap<>(); |
35 | 34 | ||
36 | for (DataRepresentation<?, ?> dataRepresentation : dataRepresentations) { | 35 | for (DataRepresentation<?, ?> dataRepresentation : dataRepresentations) { |
37 | if (dataRepresentation instanceof Relation<?>) { | 36 | if (dataRepresentation instanceof Relation<?> symbolRepresentation) { |
38 | Relation<?> symbolRepresentation = (Relation<?>) dataRepresentation; | ||
39 | addOrCreate(symbolRepresentationsPerHashPerArity, | 37 | addOrCreate(symbolRepresentationsPerHashPerArity, |
40 | new SimilarRelationEquivalenceClass(symbolRepresentation), symbolRepresentation); | 38 | new SimilarRelationEquivalenceClass(symbolRepresentation), symbolRepresentation); |
41 | } else if (dataRepresentation instanceof AuxilaryData<?, ?>) { | 39 | } else if (dataRepresentation instanceof AuxilaryData<?, ?>) { |
@@ -58,10 +56,10 @@ public class ModelStoreImpl implements ModelStore { | |||
58 | List<Relation<?>> symbolGroup) { | 56 | List<Relation<?>> symbolGroup) { |
59 | final ContinousHashProvider<Tuple> hashProvider = symbolGroup.get(0).getHashProvider(); | 57 | final ContinousHashProvider<Tuple> hashProvider = symbolGroup.get(0).getHashProvider(); |
60 | final Object defaultValue = symbolGroup.get(0).getDefaultValue(); | 58 | final Object defaultValue = symbolGroup.get(0).getDefaultValue(); |
61 | 59 | ||
62 | List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl | 60 | List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl |
63 | .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue); | 61 | .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue); |
64 | 62 | ||
65 | for (int i = 0; i < symbolGroup.size(); i++) { | 63 | for (int i = 0; i < symbolGroup.size(); i++) { |
66 | result.put(symbolGroup.get(i), maps.get(i)); | 64 | result.put(symbolGroup.get(i), maps.get(i)); |
67 | } | 65 | } |
@@ -100,24 +98,20 @@ public class ModelStoreImpl implements ModelStore { | |||
100 | } | 98 | } |
101 | return new ModelImpl(this, maps); | 99 | return new ModelImpl(this, maps); |
102 | } | 100 | } |
103 | 101 | ||
104 | @Override | 102 | @Override |
105 | @SuppressWarnings("squid:S1751") | ||
106 | public synchronized Set<Long> getStates() { | 103 | public synchronized Set<Long> getStates() { |
107 | // if not empty, return first | 104 | var iterator = stores.values().iterator(); |
108 | for(VersionedMapStore<?, ?> store : stores.values()) { | 105 | if (iterator.hasNext()) { |
109 | return new HashSet<>(store.getStates()); | 106 | return Set.copyOf(iterator.next().getStates()); |
110 | } | 107 | } |
111 | // if empty | 108 | return Set.of(0l); |
112 | Set<Long> result = new HashSet<>(); | ||
113 | result.add(0l); | ||
114 | return result; | ||
115 | } | 109 | } |
116 | 110 | ||
117 | @Override | 111 | @Override |
118 | public synchronized ModelDiffCursor getDiffCursor(long from, long to) { | 112 | public synchronized ModelDiffCursor getDiffCursor(long from, long to) { |
119 | Map<DataRepresentation<?, ?>,DiffCursor<?,?>> diffcursors = new HashMap<>(); | 113 | Map<DataRepresentation<?, ?>, DiffCursor<?, ?>> diffcursors = new HashMap<>(); |
120 | for(Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : stores.entrySet()) { | 114 | for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : stores.entrySet()) { |
121 | DataRepresentation<?, ?> representation = entry.getKey(); | 115 | DataRepresentation<?, ?> representation = entry.getKey(); |
122 | DiffCursor<?, ?> diffCursor = entry.getValue().getDiffCursor(from, to); | 116 | DiffCursor<?, ?> diffCursor = entry.getValue().getDiffCursor(from, to); |
123 | diffcursors.put(representation, diffCursor); | 117 | diffcursors.put(representation, diffCursor); |
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java index aeccde9e..049c7eac 100644 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java | |||
@@ -1,42 +1,49 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | 1 | package org.eclipse.viatra.solver.data.model.representation; |
2 | 2 | ||
3 | public class TruthValue { | 3 | public enum TruthValue { |
4 | public static final TruthValue True = new TruthValue("true"); | 4 | TRUE("true"), |
5 | public static final TruthValue False = new TruthValue("false"); | 5 | |
6 | public static final TruthValue Unknown = new TruthValue("unknown"); | 6 | FALSE("false"), |
7 | public static final TruthValue Error = new TruthValue("error"); | 7 | |
8 | 8 | UNKNOWN("unknown"), | |
9 | |||
10 | ERROR("error"); | ||
11 | |||
9 | private final String name; | 12 | private final String name; |
10 | protected TruthValue(String name) { | 13 | |
14 | private TruthValue(String name) { | ||
11 | this.name = name; | 15 | this.name = name; |
12 | } | 16 | } |
13 | 17 | ||
14 | public String getName() { | 18 | public String getName() { |
15 | return name; | 19 | return name; |
16 | } | 20 | } |
17 | 21 | ||
18 | public static TruthValue toTruthValue(boolean value) { | 22 | public static TruthValue toTruthValue(boolean value) { |
19 | if(value) return True; | 23 | return value ? TRUE : FALSE; |
20 | else return False; | ||
21 | } | 24 | } |
25 | |||
22 | public boolean isConsistent() { | 26 | public boolean isConsistent() { |
23 | return this != Error; | 27 | return this != ERROR; |
24 | } | 28 | } |
29 | |||
25 | public boolean isComplete() { | 30 | public boolean isComplete() { |
26 | return this != Unknown; | 31 | return this != UNKNOWN; |
27 | } | 32 | } |
33 | |||
28 | public boolean must() { | 34 | public boolean must() { |
29 | return this == True || this == Error; | 35 | return this == TRUE || this == ERROR; |
30 | } | 36 | } |
37 | |||
31 | public boolean may() { | 38 | public boolean may() { |
32 | return this == True || this == Unknown; | 39 | return this == TRUE || this == UNKNOWN; |
33 | } | 40 | } |
34 | 41 | ||
35 | public TruthValue not() { | 42 | public TruthValue not() { |
36 | if(this == True) { | 43 | if (this == TRUE) { |
37 | return False; | 44 | return FALSE; |
38 | } else if(this == False) { | 45 | } else if (this == FALSE) { |
39 | return True; | 46 | return TRUE; |
40 | } else { | 47 | } else { |
41 | return this; | 48 | return this; |
42 | } | 49 | } |