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



##########
File path: 
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/watch/KeyCriterion.java
##########
@@ -91,72 +93,216 @@ public RangeCriterion(Key from, Key to) {
         }
 
         /** {@inheritDoc} */
-        @Override public IgniteBiTuple<Key, Key> toRange() {
-            return new IgniteBiTuple<>(from, to);
+        @Override public boolean contains(Key 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(Key prefixKey) {
+            return new RangeCriterion(prefixKey, nextKey(prefixKey));
+        }
+
+        /** {@inheritDoc} */
+        @Override protected KeyCriterion union(KeyCriterion keyCriterion, 
boolean swapTry) {
+            Key from;
+            Key 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(
+                Collections.min(Arrays.asList(this.from, from)),
+                Collections.max(Arrays.asList(this.to, to))

Review comment:
       Seems that we'll get NPE if  to is null
   ```
        * @param keyTo End key of range (exclusive). Could be {@code null}.
        * @return Cursor built upon entries corresponding to the given range 
and revision.
        * @throws OperationTimeoutException If the operation is timed out.
        * @throws CompactedException If the desired revisions are removed from 
the storage due to a compaction.
        * @see ByteArray
        * @see Entry
        */
       @NotNull
       Cursor<Entry> range(@NotNull ByteArray keyFrom, @Nullable ByteArray 
keyTo);
   ```




-- 
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