sk0x50 commented on a change in pull request #121:
URL: https://github.com/apache/ignite-3/pull/121#discussion_r638655651



##########
File path: 
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/watch/KeyCriterion.java
##########
@@ -91,74 +93,250 @@ public RangeCriterion(ByteArray from, ByteArray to) {
         }
 
         /** {@inheritDoc} */
-        @Override public IgniteBiTuple<ByteArray, ByteArray> toRange() {
-            return new IgniteBiTuple<>(from, to);
+        @Override public boolean contains(ByteArray key) {
+            return key.compareTo(from) >= 0 && key.compareTo(to) < 0;
+        }
+
+        /**
+         * Calculate range representation for prefix criterion
+         * as {@code (prefixKey, nextKey(prefixKey)) }.
+         *
+         * @param prefixKey prefix.
+         * @return calculated range
+         */
+        public static RangeCriterion fromPrefixKey(ByteArray prefixKey) {
+            return new RangeCriterion(prefixKey, nextKey(prefixKey));
         }
 
         /** {@inheritDoc} */
-        @Override public boolean contains(ByteArray key) {
-            return key.compareTo(from) >= 0 && key.compareTo(to) < 0;
+        @Override protected KeyCriterion union(KeyCriterion keyCriterion, 
boolean swapTry) {
+            ByteArray from;
+            ByteArray to;
+
+            if (keyCriterion instanceof ExactCriterion) {
+                from = ((ExactCriterion)keyCriterion).key;
+                to = nextKey(from);
+            }
+            else if (keyCriterion instanceof CollectionCriterion) {
+                from = 
Collections.min(((CollectionCriterion)keyCriterion).keys);
+                to = 
nextKey(Collections.max(((CollectionCriterion)keyCriterion).keys));
+            }
+            else if (keyCriterion instanceof RangeCriterion) {
+                from = ((RangeCriterion)keyCriterion).from;
+                to = ((RangeCriterion)keyCriterion).to;
+            }
+            else if (!swapTry)
+                return keyCriterion.union(this, true);
+            else throw KeyCriterion.unsupportedUnionException(this, 
keyCriterion);
+
+            return new RangeCriterion(

Review comment:
       My fault. This line is obviously reachable :)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to