HADOOP-7785. Add equals, hashcode, toString to DataChecksum. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1195831 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f6a4c651a0
commit
19f40f8604
|
@ -455,6 +455,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,7 +399,33 @@ public class DataChecksum implements Checksum {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
* This is used when there is no checksum available or required for
|
||||
|
|
|
@ -114,6 +114,26 @@ public class TestDataChecksum {
|
|||
assertTrue(ce.getMessage().contains("fake file"));
|
||||
}
|
||||
}
|
||||
|
||||
@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