HADOOP-7785. Add equals, hashcode, toString to DataChecksum. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1195832 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c940637b1
commit
a6c110ebd0
@ -531,6 +531,8 @@ Release 0.23.0 - Unreleased
|
||||
|
||||
HADOOP-7763. Add top-level navigation to APT docs. (tomwhite)
|
||||
|
||||
HADOOP-7785. Add equals, hashcode, toString to DataChecksum (todd)
|
||||
|
||||
BUG FIXES
|
||||
|
||||
HADOOP-7740. Fixed security audit logger configuration. (Arpit Gupta via Eric Yang)
|
||||
|
@ -44,6 +44,10 @@ public class DataChecksum implements Checksum {
|
||||
public static final int CHECKSUM_CRC32 = 1;
|
||||
public static final int CHECKSUM_CRC32C = 2;
|
||||
|
||||
private static String[] NAMES = new String[] {
|
||||
"NULL", "CRC32", "CRC32C"
|
||||
};
|
||||
|
||||
private static final int CHECKSUM_NULL_SIZE = 0;
|
||||
private static final int CHECKSUM_CRC32_SIZE = 4;
|
||||
private static final int CHECKSUM_CRC32C_SIZE = 4;
|
||||
@ -395,6 +399,32 @@ private void calculateChunkedSums(
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof DataChecksum)) {
|
||||
return false;
|
||||
}
|
||||
DataChecksum o = (DataChecksum)other;
|
||||
return o.bytesPerChecksum == this.bytesPerChecksum &&
|
||||
o.type == this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (this.type + 31) * this.bytesPerChecksum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String strType;
|
||||
if (type < NAMES.length && type > 0) {
|
||||
strType = NAMES[type];
|
||||
} else {
|
||||
strType = String.valueOf(type);
|
||||
}
|
||||
return "DataChecksum(type=" + strType +
|
||||
", chunkSize=" + bytesPerChecksum + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* This just provides a dummy implimentation for Checksum class
|
||||
|
@ -115,6 +115,26 @@ private void doBulkTest(DataChecksum checksum, int dataLength,
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
assertEquals(
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 512),
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 512));
|
||||
assertFalse(
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 512).equals(
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 1024)));
|
||||
assertFalse(
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 512).equals(
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32C, 512)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("DataChecksum(type=CRC32, chunkSize=512)",
|
||||
DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 512)
|
||||
.toString());
|
||||
}
|
||||
|
||||
private static void corruptBufferOffset(ByteBuffer buf, int offset) {
|
||||
buf.put(offset, (byte)(buf.get(offset) + 1));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user