sanpwc commented on a change in pull request #121:
URL: https://github.com/apache/ignite-3/pull/121#discussion_r634128758
##########
File path:
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/watch/KeyCriterion.java
##########
@@ -118,45 +222,113 @@ public CollectionCriterion(Collection<Key> keys) {
}
/** {@inheritDoc} */
- @Override public IgniteBiTuple<Key, Key> toRange() {
- return new IgniteBiTuple<>(Collections.min(keys),
Collections.max(keys));
+ @Override public boolean contains(Key key) {
+ return keys.contains(key);
}
/** {@inheritDoc} */
- @Override public boolean contains(Key key) {
- return keys.contains(key);
+ @Override protected Optional<KeyCriterion> doUnion(KeyCriterion
keyCriterion) {
+ var newKeys = new ArrayList<>(keys);
+
+ if (keyCriterion instanceof ExactCriterion) {
+ newKeys.add(((ExactCriterion)keyCriterion).key);
+
+ return Optional.of(new CollectionCriterion(newKeys));
+ }
+ else if (keyCriterion instanceof CollectionCriterion) {
+ newKeys.addAll(((CollectionCriterion)keyCriterion).keys);
+
+ return Optional.of(new CollectionCriterion(newKeys));
+ } else
+ return Optional.empty();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ CollectionCriterion criterion = (CollectionCriterion)o;
+ return Objects.equals(keys, criterion.keys);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return Objects.hash(keys);
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte getHierarchyOrder() {
+ return 1;
+ }
+
+ /**
+ * @return Collection of keys.
+ */
+ public Collection<Key> keys() {
+ return keys;
}
}
/**
- * Criterion which consists of all keys with defined prefix.
+ * Simple criterion which contains exactly one key.
*/
- static class PrefixCriterion implements KeyCriterion {
- /** Prefix of the key. */
- private final Key prefixKey;
+ public static class ExactCriterion extends KeyCriterion {
+ /** The key of criterion. */
+ private final Key key;
/**
- * Creates the instance of prefix key criterion.
+ * Creates the instance of exact criterion.
*
- * @param prefixKey Prefix of the key.
+ * @param key Instance of the reference key.
*/
- public PrefixCriterion(Key prefixKey) {
- this.prefixKey = prefixKey;
+ public ExactCriterion(Key key) {
+ this.key = key;
}
/** {@inheritDoc} */
- @Override public IgniteBiTuple<Key, Key> toRange() {
- var bytes = Arrays.copyOf(prefixKey.bytes(),
prefixKey.bytes().length);
- if (bytes[bytes.length - 1] != Byte.MAX_VALUE)
- bytes[bytes.length - 1]++;
+ @Override public boolean contains(Key key) {
+ return this.key.equals(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected Optional<KeyCriterion> doUnion(KeyCriterion
keyCriterion) {
+ if (keyCriterion instanceof ExactCriterion)
+ return Optional.of(new CollectionCriterion(Arrays.asList(key,
((ExactCriterion)keyCriterion).key)));
Review comment:
Same, as above, are we going to create Collection Criterion for two
exact criterions that equals one another?
--
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]