Skip to content

Commit

Permalink
HADOOP-16196. Path Parameterize Comparable.
Browse files Browse the repository at this point in the history
Author:    David Mollitor <david.mollitor@cloudera.com>

(cherry picked from commit 246ab77)
  • Loading branch information
David Mollitor authored and steveloughran committed Mar 22, 2019
1 parent 39f60fa commit 9a449ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
@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.
Expand Down Expand Up @@ -490,11 +491,10 @@ public int hashCode() {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,15 @@ public int hashCode() {
}

@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);
}
Expand Down

0 comments on commit 9a449ac

Please sign in to comment.