sanpwc commented on a change in pull request #121:
URL: https://github.com/apache/ignite-3/pull/121#discussion_r634121283
##########
File path:
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/watch/KeyCriterion.java
##########
@@ -17,62 +17,80 @@
package org.apache.ignite.internal.metastorage.watch;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import org.apache.ignite.lang.IgniteBiTuple;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.ignite.metastorage.common.Key;
/**
* Filter for listen key's changes on metastore.
*/
-public interface KeyCriterion {
- /**
- * Translates any type of key criterion to range of keys.
- *
- * @return Ignite tuple with first key as start of range and second as the
end.
- */
- public IgniteBiTuple<Key, Key> toRange();
-
+public abstract class KeyCriterion {
/**
* Check if this key criterion contains the key.
*
* @return true if criterion contains the key, false otherwise.
*/
- public boolean contains(Key key);
+ public abstract boolean contains(Key key);
/**
- * Simple criterion which contains exactly one key.
+ * Union two key criteria and produce the new one.
+ *
+ * Rules for the union of different types of criteria:
+ * <pre>
+ * exact + exact = collection
+ * collection + exact = collection
+ * collection + collection = collection
+ * range + exact = range
+ * range + collection = range
+ * range + range = range
+ * </pre>
+ *
+ * @param keyCriterion1 first criterion to calculate the union with.
+ * @param keyCriterion2 second criterion to calculate the union with.
+ * @throws UnsupportedOperationException if can't union two criteria.
+ * @return result of criteria union.
*/
- static class ExactCriterion implements KeyCriterion {
- /** The key of criterion. */
- private final Key key;
-
- /**
- * Creates the instance of exact criterion.
- *
- * @param key Instance of the reference key.
- */
- public ExactCriterion(Key key) {
- this.key = key;
- }
+ public static KeyCriterion union(KeyCriterion keyCriterion1, KeyCriterion
keyCriterion2) {
+ Optional<KeyCriterion> res;
- /** {@inheritDoc} */
- @Override public IgniteBiTuple<Key, Key> toRange() {
- return new IgniteBiTuple<>(key, key);
- }
+ if (keyCriterion1.getHierarchyOrder() <
keyCriterion2.getHierarchyOrder())
+ res = keyCriterion2.doUnion(keyCriterion1);
+ else
+ res = keyCriterion1.doUnion(keyCriterion2);
- /** {@inheritDoc} */
- @Override public boolean contains(Key key) {
- return this.key.equals(key);
- }
+ if (res.isPresent())
+ return res.get();
+ else
+ throw new UnsupportedOperationException("Can't calculate the union
of " + keyCriterion1.getClass() + " and " +
Review comment:
Why it's possible?
--
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]