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/map/internal/MutableNode.java | |
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/map/internal/MutableNode.java')
-rw-r--r-- | store/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java b/store/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java index 9e63b941..b5fee673 100644 --- a/store/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java +++ b/store/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java | |||
@@ -52,19 +52,22 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
52 | this.cachedHash = node.hashCode(); | 52 | this.cachedHash = node.hashCode(); |
53 | } | 53 | } |
54 | 54 | ||
55 | @SuppressWarnings("unchecked") | ||
56 | @Override | 55 | @Override |
57 | public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { | 56 | public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { |
58 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); | 57 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); |
58 | @SuppressWarnings("unchecked") | ||
59 | K keyCandidate = (K) this.content[2 * selectedHashFragment]; | 59 | K keyCandidate = (K) this.content[2 * selectedHashFragment]; |
60 | if (keyCandidate != null) { | 60 | if (keyCandidate != null) { |
61 | if (keyCandidate.equals(key)) { | 61 | if (keyCandidate.equals(key)) { |
62 | return (V) this.content[2 * selectedHashFragment + 1]; | 62 | @SuppressWarnings("unchecked") |
63 | V value = (V) this.content[2 * selectedHashFragment + 1]; | ||
64 | return value; | ||
63 | } else { | 65 | } else { |
64 | return defaultValue; | 66 | return defaultValue; |
65 | } | 67 | } |
66 | } else { | 68 | } else { |
67 | Node<K, V> nodeCandidate = (Node<K, V>) content[2 * selectedHashFragment + 1]; | 69 | @SuppressWarnings("unchecked") |
70 | var nodeCandidate = (Node<K, V>) content[2 * selectedHashFragment + 1]; | ||
68 | if (nodeCandidate != null) { | 71 | if (nodeCandidate != null) { |
69 | int newDepth = depth + 1; | 72 | int newDepth = depth + 1; |
70 | int newHash = newHash(hashProvider, key, hash, newDepth); | 73 | int newHash = newHash(hashProvider, key, hash, newDepth); |
@@ -75,11 +78,11 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
75 | } | 78 | } |
76 | } | 79 | } |
77 | 80 | ||
78 | @SuppressWarnings("unchecked") | ||
79 | @Override | 81 | @Override |
80 | public Node<K, V> putValue(K key, V value, OldValueBox<V> oldValue, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, | 82 | public Node<K, V> putValue(K key, V value, OldValueBox<V> oldValue, ContinousHashProvider<? super K> hashProvider, |
81 | int depth) { | 83 | V defaultValue, int hash, int depth) { |
82 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); | 84 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); |
85 | @SuppressWarnings("unchecked") | ||
83 | K keyCandidate = (K) content[2 * selectedHashFragment]; | 86 | K keyCandidate = (K) content[2 * selectedHashFragment]; |
84 | if (keyCandidate != null) { | 87 | if (keyCandidate != null) { |
85 | // If has key | 88 | // If has key |
@@ -105,10 +108,11 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
105 | } | 108 | } |
106 | } else { | 109 | } else { |
107 | // If it does not have key, check for value | 110 | // If it does not have key, check for value |
108 | Node<K, V> nodeCandidate = (Node<K, V>) content[2 * selectedHashFragment + 1]; | 111 | @SuppressWarnings("unchecked") |
112 | var nodeCandidate = (Node<K, V>) content[2 * selectedHashFragment + 1]; | ||
109 | if (nodeCandidate != null) { | 113 | if (nodeCandidate != null) { |
110 | // If it has value, it is a subnode -> upate that | 114 | // If it has value, it is a subnode -> upate that |
111 | Node<K, V> newNode = nodeCandidate.putValue(key, value, oldValue, hashProvider, defaultValue, | 115 | var newNode = nodeCandidate.putValue(key, value, oldValue, hashProvider, defaultValue, |
112 | newHash(hashProvider, key, hash, depth + 1), depth + 1); | 116 | newHash(hashProvider, key, hash, depth + 1), depth + 1); |
113 | return updateWithSubNode(selectedHashFragment, newNode, value.equals(defaultValue)); | 117 | return updateWithSubNode(selectedHashFragment, newNode, value.equals(defaultValue)); |
114 | } else { | 118 | } else { |
@@ -125,10 +129,11 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
125 | } | 129 | } |
126 | } | 130 | } |
127 | 131 | ||
128 | @SuppressWarnings("unchecked") | 132 | private Node<K, V> addEntry(K key, V value, OldValueBox<V> oldValueBox, int selectedHashFragment) { |
129 | private Node<K, V> addEntry(K key, V value, OldValueBox<V> oldValue, int selectedHashFragment) { | ||
130 | content[2 * selectedHashFragment] = key; | 133 | content[2 * selectedHashFragment] = key; |
131 | oldValue.setOldValue((V) content[2 * selectedHashFragment + 1]); | 134 | @SuppressWarnings("unchecked") |
135 | V oldValue = (V) content[2 * selectedHashFragment + 1]; | ||
136 | oldValueBox.setOldValue(oldValue); | ||
132 | content[2 * selectedHashFragment + 1] = value; | 137 | content[2 * selectedHashFragment + 1] = value; |
133 | updateHash(); | 138 | updateHash(); |
134 | return this; | 139 | return this; |
@@ -231,6 +236,8 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
231 | return this; | 236 | return this; |
232 | } | 237 | } |
233 | 238 | ||
239 | // Pass everything as parameters for performance. | ||
240 | @SuppressWarnings("squid:S107") | ||
234 | private MutableNode<K, V> newNodeWithTwoEntries(ContinousHashProvider<? super K> hashProvider, K key1, V value1, | 241 | private MutableNode<K, V> newNodeWithTwoEntries(ContinousHashProvider<? super K> hashProvider, K key1, V value1, |
235 | int oldHash1, K key2, V value2, int oldHash2, int newdepth) { | 242 | int oldHash1, K key2, V value2, int oldHash2, int newdepth) { |
236 | int newHash1 = newHash(hashProvider, key1, oldHash1, newdepth); | 243 | int newHash1 = newHash(hashProvider, key1, oldHash1, newdepth); |
@@ -377,7 +384,6 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
377 | } | 384 | } |
378 | } | 385 | } |
379 | 386 | ||
380 | @SuppressWarnings({ "unchecked" }) | ||
381 | @Override | 387 | @Override |
382 | public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) { | 388 | public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) { |
383 | // check for orphan nodes | 389 | // check for orphan nodes |
@@ -390,7 +396,9 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
390 | // check the place of data | 396 | // check the place of data |
391 | for (int i = 0; i < FACTOR; i++) { | 397 | for (int i = 0; i < FACTOR; i++) { |
392 | if (this.content[2 * i] != null) { | 398 | if (this.content[2 * i] != null) { |
399 | @SuppressWarnings("unchecked") | ||
393 | K key = (K) this.content[2 * i]; | 400 | K key = (K) this.content[2 * i]; |
401 | @SuppressWarnings("unchecked") | ||
394 | V value = (V) this.content[2 * i + 1]; | 402 | V value = (V) this.content[2 * i + 1]; |
395 | 403 | ||
396 | if (value == defaultValue) { | 404 | if (value == defaultValue) { |
@@ -408,7 +416,8 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
408 | // check subnodes | 416 | // check subnodes |
409 | for (int i = 0; i < FACTOR; i++) { | 417 | for (int i = 0; i < FACTOR; i++) { |
410 | if (this.content[2 * i + 1] != null && this.content[2 * i] == null) { | 418 | if (this.content[2 * i + 1] != null && this.content[2 * i] == null) { |
411 | Node<K, V> subNode = (Node<K, V>) this.content[2 * i + 1]; | 419 | @SuppressWarnings("unchecked") |
420 | var subNode = (Node<K, V>) this.content[2 * i + 1]; | ||
412 | subNode.checkIntegrity(hashProvider, defaultValue, depth + 1); | 421 | subNode.checkIntegrity(hashProvider, defaultValue, depth + 1); |
413 | } | 422 | } |
414 | } | 423 | } |
@@ -436,12 +445,10 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
436 | return true; | 445 | return true; |
437 | if (obj == null) | 446 | if (obj == null) |
438 | return false; | 447 | return false; |
439 | if (obj instanceof MutableNode<?, ?>) { | 448 | if (obj instanceof MutableNode<?, ?> mutableObj) { |
440 | MutableNode<?, ?> other = (MutableNode<?, ?>) obj; | 449 | return Arrays.deepEquals(this.content, mutableObj.content); |
441 | return Arrays.deepEquals(this.content, other.content); | 450 | } else if (obj instanceof ImmutableNode<?, ?> immutableObj) { |
442 | } else if (obj instanceof ImmutableNode<?, ?>) { | 451 | return ImmutableNode.compareImmutableMutable(immutableObj, this); |
443 | ImmutableNode<?, ?> other = (ImmutableNode<?, ?>) obj; | ||
444 | return ImmutableNode.compareImmutableMutable(other, this); | ||
445 | } else { | 452 | } else { |
446 | return false; | 453 | return false; |
447 | } | 454 | } |