Fixes - Using Java 8 Comparator for TableRange compareTo
@@ -17,6 +17,7 @@ package org.apache.fluo.core.worker.finder.hash;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -104,21 +105,11 @@ public class TableRange implements Comparable<TableRange> {
return new Range(tper, false, ter, true);
}
- @Override
- public int compareTo(TableRange o) {
- if (Objects.equals(getEndRow(), o.getEndRow())) {
- // this will catch case of both null
- return 0;
- }
-
- if (getEndRow() == null) {
- return 1;
- }
+ private static final Comparator<TableRange> TABLE_RANGE_COMPARATOR =
+ Comparator.comparing(TableRange::getEndRow, Comparator.nullsLast(Bytes::compareTo));
- if (o.getEndRow() == null) {
- return -1;
- }
-
- return getEndRow().compareTo(o.getEndRow());
+ @Override
+ public int compareTo(TableRange other) {
+ return TABLE_RANGE_COMPARATOR.compare(this, other);
}
}
