This is an automated email from the ASF dual-hosted git repository.

cjmctague pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/fluo.git


The following commit(s) were added to refs/heads/master by this push:
     new fc909ab  Fixes #1044 - Using Java 8 Comparator for TableRange 
compareTo (#1045)
fc909ab is described below

commit fc909abe4cb55414c992bdcfce07c96fc63413b5
Author: Christopher McTague <[email protected]>
AuthorDate: Fri Jul 27 10:51:45 2018 -0400

    Fixes #1044 - Using Java 8 Comparator for TableRange compareTo (#1045)
---
 .../fluo/core/worker/finder/hash/TableRange.java    | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/TableRange.java
 
b/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/TableRange.java
index a3c70bb..ef4d530 100644
--- 
a/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/TableRange.java
+++ 
b/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/TableRange.java
@@ -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);
   }
 }

Reply via email to