You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by st...@apache.org on 2019/03/22 10:27:39 UTC

[hadoop] branch trunk updated: HADOOP-16196. Path Parameterize Comparable.

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

stevel pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 246ab77  HADOOP-16196. Path Parameterize Comparable.
246ab77 is described below

commit 246ab77f281614b2206bfb1dae70a8dec62147a7
Author: David Mollitor <da...@cloudera.com>
AuthorDate: Fri Mar 22 10:26:24 2019 +0000

    HADOOP-16196. Path Parameterize Comparable.
    
    Author:    David Mollitor <da...@cloudera.com>
---
 .../src/main/java/org/apache/hadoop/fs/Path.java            | 10 +++++-----
 .../hadoop/mapreduce/task/reduce/MergeManagerImpl.java      | 13 ++++++-------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java
index 7672c99..c5d7bfc 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java
@@ -40,7 +40,8 @@ import org.apache.hadoop.conf.Configuration;
 @Stringable
 @InterfaceAudience.Public
 @InterfaceStability.Stable
-public class Path implements Comparable, Serializable, ObjectInputValidation {
+public class Path
+    implements Comparable<Path>, Serializable, ObjectInputValidation {
 
   /**
    * The directory separator, a slash.
@@ -490,11 +491,10 @@ public class Path implements Comparable, Serializable, ObjectInputValidation {
   }
 
   @Override
-  public int compareTo(Object o) {
-    Path that = (Path)o;
-    return this.uri.compareTo(that.uri);
+  public int compareTo(Path o) {
+    return this.uri.compareTo(o.uri);
   }
-  
+
   /**
    * Returns the number of elements in this path.
    * @return the number of elements in this path
diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java
index f01b24c..58c2686 100644
--- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java
+++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java
@@ -860,16 +860,15 @@ public class MergeManagerImpl<K, V> implements MergeManager<K, V> {
     }
 
     @Override
-    public int compareTo(Object obj) {
-      if(obj instanceof CompressAwarePath) {
+    public int compareTo(Path obj) {
+      if (obj instanceof CompressAwarePath) {
         CompressAwarePath compPath = (CompressAwarePath) obj;
-        if(this.compressedSize < compPath.getCompressedSize()) {
-          return -1;
-        } else if (this.getCompressedSize() > compPath.getCompressedSize()) {
-          return 1;
-        }
+        int c = Long.compare(this.compressedSize, compPath.compressedSize);
         // Not returning 0 here so that objects with the same size (but
         // different paths) are still added to the TreeSet.
+        if (c != 0) {
+          return c;
+        }
       }
       return super.compareTo(obj);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org