diff options
author | 2021-08-10 19:17:22 +0200 | |
---|---|---|
committer | 2021-08-10 19:17:22 +0200 | |
commit | 5e911ac81a97fa87797003f8aedfa4ac865b3131 (patch) | |
tree | 3b4a4d41a20b9cc0ece943a7cb4efd69890bbe0f /model-data | |
parent | Key validation (diff) | |
download | refinery-5e911ac81a97fa87797003f8aedfa4ac865b3131.tar.gz refinery-5e911ac81a97fa87797003f8aedfa4ac865b3131.tar.zst refinery-5e911ac81a97fa87797003f8aedfa4ac865b3131.zip |
Model and model store interfaces and implementations
Diffstat (limited to 'model-data')
5 files changed, 257 insertions, 110 deletions
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Model.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Model.java index 18fab2bf..a19e4d5f 100644 --- a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Model.java +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Model.java | |||
@@ -1,60 +1,20 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | 1 | package org.eclipse.viatra.solver.data.model; |
2 | 2 | ||
3 | import java.util.Map; | ||
4 | import java.util.Set; | 3 | import java.util.Set; |
5 | 4 | ||
5 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
6 | import org.eclipse.viatra.solver.data.map.Versioned; | 6 | import org.eclipse.viatra.solver.data.map.Versioned; |
7 | import org.eclipse.viatra.solver.data.map.VersionedMap; | 7 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; |
8 | import org.eclipse.viatra.solver.data.model.symbols.Symbol; | 8 | |
9 | 9 | public interface Model extends Versioned{ | |
10 | public class Model implements Versioned { | 10 | @SuppressWarnings("squid:S1452") |
11 | private final ModelStore store; | 11 | Set<DataRepresentation<?, ?>> getDataRepresentations(); |
12 | private final Map<Symbol, VersionedMap<Tuple,Object>> maps; | 12 | |
13 | 13 | <K,V> V get(DataRepresentation<K,V> representation, K key); | |
14 | public Model(ModelStore store, Map<Symbol, VersionedMap<Tuple, Object>> maps) { | 14 | <K,V> Cursor<K,V> getAll(DataRepresentation<K,V> representation); |
15 | this.store = store; | 15 | <K,V> void put(DataRepresentation<K,V> representation, K key, V value); |
16 | this.maps = maps; | 16 | <K,V> void putAll(DataRepresentation<K,V> representation, Cursor<K,V> cursor); |
17 | } | 17 | <K,V> long getSize(DataRepresentation<K,V> representation); |
18 | 18 | ||
19 | public Set<Symbol> getSymbols() { | 19 | ModelDiffCursor getDiffCursor(long to); |
20 | return store.getSymbols(); | ||
21 | } | ||
22 | |||
23 | public Object get(Symbol symbol, int... key) { | ||
24 | if (maps.containsKey(symbol)) { | ||
25 | if (key.length == symbol.getArity()) { | ||
26 | return maps.get(symbol).get(Tuple.of(key)); | ||
27 | } else { | ||
28 | throw new IllegalArgumentException("The arity of symbol " + symbol.getName() + "is " + symbol.getArity() | ||
29 | + " and not " + key.length); | ||
30 | } | ||
31 | } else { | ||
32 | throw new IllegalArgumentException("Model does define symbol " + symbol.getName()); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | public void put(Symbol symbol, Object value, int... key) { | ||
37 | if (maps.containsKey(symbol)) { | ||
38 | if (key.length == symbol.getArity()) { | ||
39 | maps.get(symbol).put(Tuple.of(key),value); | ||
40 | } else { | ||
41 | throw new IllegalArgumentException("The arity of symbol " + symbol.getName() + "is " + symbol.getArity() | ||
42 | + " and not " + key.length); | ||
43 | } | ||
44 | } else { | ||
45 | throw new IllegalArgumentException("Model does define symbol " + symbol.getName()); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public long commit() { | ||
51 | // TODO Auto-generated method stub | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public void restore(long state) { | ||
57 | // TODO Auto-generated method stub | ||
58 | |||
59 | } | ||
60 | } | 20 | } |
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java index 53d69dc8..35ac72b5 100644 --- a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java | |||
@@ -2,13 +2,15 @@ package org.eclipse.viatra.solver.data.model; | |||
2 | 2 | ||
3 | import java.util.Set; | 3 | import java.util.Set; |
4 | 4 | ||
5 | import org.eclipse.viatra.solver.data.model.symbols.Symbol; | 5 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; |
6 | 6 | ||
7 | public interface ModelStore { | 7 | public interface ModelStore { |
8 | 8 | @SuppressWarnings("squid:S1452") | |
9 | Set<Symbol> getSymbols(); | 9 | Set<DataRepresentation<?, ?>> getDataRepresentations(); |
10 | |||
10 | Model createModel(); | 11 | Model createModel(); |
11 | Model createModel(long state); | 12 | Model createModel(long state); |
13 | |||
12 | Set<Long> getStates(); | 14 | Set<Long> getStates(); |
13 | 15 | ModelDiffCursor getDiffCursor(long from, long to); | |
14 | } \ No newline at end of file | 16 | } \ No newline at end of file |
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java index 81fe40f2..38aaccc1 100644 --- a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java | |||
@@ -1,7 +1,5 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | 1 | package org.eclipse.viatra.solver.data.model; |
2 | 2 | ||
3 | import java.util.Collection; | ||
4 | import java.util.Comparator; | ||
5 | import java.util.HashMap; | 3 | import java.util.HashMap; |
6 | import java.util.HashSet; | 4 | import java.util.HashSet; |
7 | import java.util.LinkedList; | 5 | import java.util.LinkedList; |
@@ -9,57 +7,63 @@ import java.util.List; | |||
9 | import java.util.Map; | 7 | import java.util.Map; |
10 | import java.util.Map.Entry; | 8 | import java.util.Map.Entry; |
11 | import java.util.Set; | 9 | import java.util.Set; |
12 | import java.util.TreeMap; | ||
13 | 10 | ||
11 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
12 | import org.eclipse.viatra.solver.data.map.DiffCursor; | ||
14 | import org.eclipse.viatra.solver.data.map.VersionedMap; | 13 | import org.eclipse.viatra.solver.data.map.VersionedMap; |
15 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | 14 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; |
16 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; | 15 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; |
17 | import org.eclipse.viatra.solver.data.model.symbols.IntegerSymbol; | 16 | import org.eclipse.viatra.solver.data.model.internal.ModelImpl; |
18 | import org.eclipse.viatra.solver.data.model.symbols.PredicateSymbol; | 17 | import org.eclipse.viatra.solver.data.model.internal.SymbolRepresentationEquivalenceClass; |
19 | import org.eclipse.viatra.solver.data.model.symbols.RealSymbol; | 18 | import org.eclipse.viatra.solver.data.model.representation.AuxilaryDataRepresentation; |
20 | import org.eclipse.viatra.solver.data.model.symbols.Symbol; | 19 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; |
21 | import org.eclipse.viatra.solver.data.model.values.TruthValue; | 20 | import org.eclipse.viatra.solver.data.model.representation.SymbolRepresentation; |
22 | 21 | ||
23 | public class ModelStoreImpl implements ModelStore { | 22 | public class ModelStoreImpl implements ModelStore { |
24 | |||
25 | private final Map<Symbol, VersionedMapStore<Tuple, Object>> stores; | ||
26 | private final Set<Long> states = new HashSet<>(); | ||
27 | 23 | ||
28 | public ModelStoreImpl(Set<Symbol> symbols) { | 24 | private final Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> stores; |
29 | stores = initStores(symbols); | 25 | |
26 | public ModelStoreImpl(Set<DataRepresentation<?, ?>> dataRepresentations) { | ||
27 | stores = initStores(dataRepresentations); | ||
30 | } | 28 | } |
31 | 29 | ||
32 | private Map<Symbol, VersionedMapStore<Tuple, Object>> initStores(Set<Symbol> symbols) { | 30 | private Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> initStores( |
33 | Map<Symbol, VersionedMapStore<Tuple, Object>> result = new TreeMap<>(Symbol.symbolComparator); | 31 | Set<DataRepresentation<?, ?>> dataRepresentations) { |
34 | 32 | Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> result = new HashMap<>(); | |
35 | Map<Integer, List<PredicateSymbol>> predicateSymbols = new HashMap<>(); | 33 | |
36 | Map<Integer, List<IntegerSymbol>> integerSymbols = new HashMap<>(); | 34 | Map<SymbolRepresentationEquivalenceClass, List<SymbolRepresentation<?>>> symbolRepresentationsPerHashPerArity = new HashMap<>(); |
37 | Map<Integer, List<RealSymbol>> realSymbols = new HashMap<>(); | 35 | |
38 | for (Symbol symbol : symbols) { | 36 | for (DataRepresentation<?, ?> dataRepresentation : dataRepresentations) { |
39 | if (symbol instanceof PredicateSymbol) { | 37 | if (dataRepresentation instanceof SymbolRepresentation<?>) { |
40 | ModelStoreImpl.addOrCreate(predicateSymbols, symbol.getArity(), (PredicateSymbol) symbol); | 38 | SymbolRepresentation<?> symbolRepresentation = (SymbolRepresentation<?>) dataRepresentation; |
41 | } else if (symbol instanceof IntegerSymbol) { | 39 | addOrCreate(symbolRepresentationsPerHashPerArity, |
42 | ModelStoreImpl.addOrCreate(integerSymbols, symbol.getArity(), (IntegerSymbol) symbol); | 40 | new SymbolRepresentationEquivalenceClass(symbolRepresentation), symbolRepresentation); |
43 | } else if (symbol instanceof RealSymbol) { | 41 | } else if (dataRepresentation instanceof AuxilaryDataRepresentation<?, ?>) { |
44 | ModelStoreImpl.addOrCreate(realSymbols, symbol.getArity(), (RealSymbol) symbol); | 42 | VersionedMapStoreImpl<?, ?> store = new VersionedMapStoreImpl<>(dataRepresentation.getHashProvider(), |
43 | dataRepresentation.getDefaultValue()); | ||
44 | result.put(dataRepresentation, store); | ||
45 | } else { | ||
46 | throw new UnsupportedOperationException( | ||
47 | "Model store does not have strategy to use " + dataRepresentation.getClass() + "!"); | ||
45 | } | 48 | } |
46 | } | 49 | } |
47 | 50 | for (List<SymbolRepresentation<?>> symbolGroup : symbolRepresentationsPerHashPerArity.values()) { | |
48 | initPredicateGroup(result, predicateSymbols.values(),TruthValue.False); | 51 | initRepresentationGroup(result, symbolGroup); |
49 | initPredicateGroup(result, integerSymbols.values(), null); | 52 | } |
50 | initPredicateGroup(result, realSymbols.values(), null); | 53 | |
51 | |||
52 | return result; | 54 | return result; |
53 | } | 55 | } |
54 | 56 | ||
55 | private <V> void initPredicateGroup(Map<Symbol, VersionedMapStore<Tuple, Object>> result, | 57 | private void initRepresentationGroup(Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> result, |
56 | Collection<? extends List<? extends Symbol>> symbolGroups, V defaultValue) { | 58 | List<SymbolRepresentation<?>> symbolGroup) { |
57 | for (List<? extends Symbol> similarSymbols : symbolGroups) { | 59 | final ContinousHashProvider<Tuple> hashProvider = symbolGroup.get(0).getHashProvider(); |
58 | List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl.createSharedVersionedMapStores( | 60 | final Object defaultValue = symbolGroup.get(0).getDefaultValue(); |
59 | similarSymbols.size(), TupleHashProvider.instance, defaultValue); | 61 | |
60 | for (int i = 0; i < similarSymbols.size(); i++) { | 62 | List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl |
61 | result.put(similarSymbols.get(i), maps.get(i)); | 63 | .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue); |
62 | } | 64 | |
65 | for (int i = 0; i < symbolGroup.size(); i++) { | ||
66 | result.put(symbolGroup.get(i), maps.get(i)); | ||
63 | } | 67 | } |
64 | } | 68 | } |
65 | 69 | ||
@@ -73,30 +77,51 @@ public class ModelStoreImpl implements ModelStore { | |||
73 | } | 77 | } |
74 | list.add(value); | 78 | list.add(value); |
75 | } | 79 | } |
80 | |||
76 | @Override | 81 | @Override |
77 | public Set<Symbol> getSymbols() { | 82 | public Set<DataRepresentation<?, ?>> getDataRepresentations() { |
78 | return this.stores.keySet(); | 83 | return this.stores.keySet(); |
79 | } | 84 | } |
85 | |||
80 | @Override | 86 | @Override |
81 | public Model createModel() { | 87 | public ModelImpl createModel() { |
82 | Map<Symbol, VersionedMap<Tuple,Object>> maps = new TreeMap<>(Symbol.symbolComparator); | 88 | Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps = new HashMap<>(); |
83 | for(Entry<Symbol, VersionedMapStore<Tuple, Object>> entry : this.stores.entrySet()) { | 89 | for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : this.stores.entrySet()) { |
84 | maps.put(entry.getKey(),entry.getValue().createMap()); | 90 | maps.put(entry.getKey(), entry.getValue().createMap()); |
85 | } | 91 | } |
86 | return new Model(this, maps); | 92 | return new ModelImpl(this, maps); |
87 | } | 93 | } |
88 | 94 | ||
89 | @Override | 95 | @Override |
90 | public synchronized Model createModel(long state) { | 96 | public synchronized ModelImpl createModel(long state) { |
91 | Map<Symbol, VersionedMap<Tuple,Object>> maps = new TreeMap<>(Symbol.symbolComparator); | 97 | Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps = new HashMap<>(); |
92 | for(Entry<Symbol, VersionedMapStore<Tuple, Object>> entry : this.stores.entrySet()) { | 98 | for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : this.stores.entrySet()) { |
93 | maps.put(entry.getKey(),entry.getValue().createMap(state)); | 99 | maps.put(entry.getKey(), entry.getValue().createMap(state)); |
100 | } | ||
101 | return new ModelImpl(this, maps); | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | @SuppressWarnings("squid:S1751") | ||
106 | public synchronized Set<Long> getStates() { | ||
107 | // if not empty, return first | ||
108 | for(VersionedMapStore<?, ?> store : stores.values()) { | ||
109 | return store.getStates(); | ||
94 | } | 110 | } |
95 | return new Model(this, maps); | 111 | // if empty |
112 | Set<Long> result = new HashSet<>(); | ||
113 | result.add(0l); | ||
114 | return result; | ||
96 | } | 115 | } |
97 | 116 | ||
98 | @Override | 117 | @Override |
99 | synchronized public Set<Long> getStates() { | 118 | public synchronized ModelDiffCursor getDiffCursor(long from, long to) { |
100 | return this.states; | 119 | Map<DataRepresentation<?, ?>,DiffCursor<?,?>> diffcursors = new HashMap<>(); |
120 | for(Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : stores.entrySet()) { | ||
121 | DataRepresentation<?, ?> representation = entry.getKey(); | ||
122 | DiffCursor<?, ?> diffCursor = entry.getValue().getDiffCursor(from, to); | ||
123 | diffcursors.put(representation, diffCursor); | ||
124 | } | ||
125 | return new ModelDiffCursor(diffcursors); | ||
101 | } | 126 | } |
102 | } | 127 | } |
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java new file mode 100644 index 00000000..49699933 --- /dev/null +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java | |||
@@ -0,0 +1,124 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.internal; | ||
2 | |||
3 | import java.util.HashMap; | ||
4 | import java.util.Map; | ||
5 | import java.util.Set; | ||
6 | |||
7 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
8 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
9 | import org.eclipse.viatra.solver.data.map.DiffCursor; | ||
10 | import org.eclipse.viatra.solver.data.map.VersionedMap; | ||
11 | import org.eclipse.viatra.solver.data.map.internal.MapDiffCursor; | ||
12 | import org.eclipse.viatra.solver.data.model.Model; | ||
13 | import org.eclipse.viatra.solver.data.model.ModelDiffCursor; | ||
14 | import org.eclipse.viatra.solver.data.model.ModelStore; | ||
15 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
16 | |||
17 | public class ModelImpl implements Model { | ||
18 | private final ModelStore store; | ||
19 | private final Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps; | ||
20 | |||
21 | public ModelImpl(ModelStore store, Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps) { | ||
22 | this.store = store; | ||
23 | this.maps = maps; | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public Set<DataRepresentation<?, ?>> getDataRepresentations() { | ||
28 | return maps.keySet(); | ||
29 | } | ||
30 | |||
31 | @SuppressWarnings("unchecked") | ||
32 | private <K, V> VersionedMap<K, V> getMap(DataRepresentation<K, V> representation) { | ||
33 | if (maps.containsKey(representation)) { | ||
34 | return (VersionedMap<K, V>) maps.get(representation); | ||
35 | } else { | ||
36 | throw new IllegalArgumentException("Model does have representation " + representation); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | private <K, V> VersionedMap<K, V> getMapValidateKey(DataRepresentation<K, V> representation, K key) { | ||
41 | if (representation.isValidKey(key)) { | ||
42 | return getMap(representation); | ||
43 | } else { | ||
44 | throw new IllegalArgumentException( | ||
45 | "Key is not valid for representation! (representation=" + representation + ", key=" + key + ");"); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public <K, V> V get(DataRepresentation<K, V> representation, K key) { | ||
51 | return getMapValidateKey(representation, key).get(key); | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | public <K, V> Cursor<K, V> getAll(DataRepresentation<K, V> representation) { | ||
56 | return getMap(representation).getCursor(); | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | public <K, V> void put(DataRepresentation<K, V> representation, K key, V value) { | ||
61 | getMapValidateKey(representation, key).put(key, value); | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public <K, V> void putAll(DataRepresentation<K, V> representation, Cursor<K, V> cursor) { | ||
66 | getMap(representation).putAll(cursor); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public <K, V> long getSize(DataRepresentation<K, V> representation) { | ||
71 | return getMap(representation).getSize(); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public ModelDiffCursor getDiffCursor(long to) { | ||
76 | Model toModel = store.createModel(to); | ||
77 | Map<DataRepresentation<?, ?>, DiffCursor<?, ?>> diffCursors = new HashMap<>(); | ||
78 | for (DataRepresentation<?, ?> representation : this.maps.keySet()) { | ||
79 | MapDiffCursor<?, ?> diffCursor = constructDiffCursor(toModel, representation); | ||
80 | diffCursors.put(representation, diffCursor); | ||
81 | } | ||
82 | return new ModelDiffCursor(diffCursors); | ||
83 | } | ||
84 | |||
85 | private <K, V> MapDiffCursor<K, V> constructDiffCursor(Model toModel, DataRepresentation<K, V> representation) { | ||
86 | @SuppressWarnings("unchecked") | ||
87 | Cursor<K, V> fromCursor = (Cursor<K, V>) this.maps.get(representation).getCursor(); | ||
88 | Cursor<K, V> toCursor = toModel.getAll(representation); | ||
89 | |||
90 | ContinousHashProvider<K> hashProvider = representation.getHashProvider(); | ||
91 | V defaultValue = representation.getDefaultValue(); | ||
92 | return new MapDiffCursor<>(hashProvider, defaultValue, fromCursor, toCursor); | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public long commit() { | ||
97 | long version = 0; | ||
98 | boolean versionSet = false; | ||
99 | for (VersionedMap<?, ?> map : maps.values()) { | ||
100 | long newVersion = map.commit(); | ||
101 | if (versionSet) { | ||
102 | if (version != newVersion) { | ||
103 | throw new IllegalStateException( | ||
104 | "Maps in model have different versions! (" + version + " and" + newVersion + ")"); | ||
105 | } | ||
106 | } else { | ||
107 | version = newVersion; | ||
108 | versionSet = true; | ||
109 | } | ||
110 | } | ||
111 | return version; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public void restore(long state) { | ||
116 | if(store.getStates().contains(state)) { | ||
117 | for (VersionedMap<?, ?> map : maps.values()) { | ||
118 | map.restore(state); | ||
119 | } | ||
120 | } else { | ||
121 | throw new IllegalArgumentException("Map does not contain state "+state+"!"); | ||
122 | } | ||
123 | } | ||
124 | } | ||
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/internal/SymbolRepresentationEquivalenceClass.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/internal/SymbolRepresentationEquivalenceClass.java new file mode 100644 index 00000000..b87b7c13 --- /dev/null +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/internal/SymbolRepresentationEquivalenceClass.java | |||
@@ -0,0 +1,36 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.internal; | ||
2 | |||
3 | import java.util.Objects; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
6 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
7 | import org.eclipse.viatra.solver.data.model.representation.SymbolRepresentation; | ||
8 | |||
9 | public class SymbolRepresentationEquivalenceClass { | ||
10 | final ContinousHashProvider<Tuple> hashProvider; | ||
11 | final Class<?> domainClass; | ||
12 | final Object defaultValue; | ||
13 | final int arity; | ||
14 | public SymbolRepresentationEquivalenceClass(SymbolRepresentation<?> representation) { | ||
15 | this.hashProvider = representation.getHashProvider(); | ||
16 | this.domainClass = representation.getValueClass(); | ||
17 | this.defaultValue = representation.getDefaultValue(); | ||
18 | this.arity = representation.getSymbol().getArity(); | ||
19 | } | ||
20 | @Override | ||
21 | public int hashCode() { | ||
22 | return Objects.hash(arity, defaultValue, domainClass, hashProvider); | ||
23 | } | ||
24 | @Override | ||
25 | public boolean equals(Object obj) { | ||
26 | if (this == obj) | ||
27 | return true; | ||
28 | if (obj == null) | ||
29 | return false; | ||
30 | if (getClass() != obj.getClass()) | ||
31 | return false; | ||
32 | SymbolRepresentationEquivalenceClass other = (SymbolRepresentationEquivalenceClass) obj; | ||
33 | return arity == other.arity && Objects.equals(defaultValue, other.defaultValue) | ||
34 | && Objects.equals(domainClass, other.domainClass) && Objects.equals(hashProvider, other.hashProvider); | ||
35 | } | ||
36 | } | ||