HDFS-5266. Addendum for addressing Findbugs warnings for lack of hashCode method and lack of null check in equals. Contributed by Chris Nauroth.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-4949@1527023 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f17d64527
commit
89c147d46f
|
@ -18,6 +18,7 @@
|
|||
package org.apache.hadoop.io;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
|
@ -55,6 +56,9 @@ public final class ElasticByteBufferPool implements ByteBufferPool {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object rhs) {
|
||||
if (rhs == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Key o = (Key)rhs;
|
||||
return (compareTo(o) == 0);
|
||||
|
@ -62,6 +66,14 @@ public final class ElasticByteBufferPool implements ByteBufferPool {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().
|
||||
append(capacity).
|
||||
append(insertionTime).
|
||||
toHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
private final TreeMap<Key, ByteBuffer> buffers =
|
||||
|
|
Loading…
Reference in New Issue