hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1195831 - in /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/util/DataChecksum.java src/test/java/org/apache/hadoop/util/TestDataChecksum.java
Date Tue, 01 Nov 2011 05:25:07 GMT
Author: todd
Date: Tue Nov  1 05:25:06 2011
New Revision: 1195831

URL: http://svn.apache.org/viewvc?rev=1195831&view=rev
Log:
HADOOP-7785. Add equals, hashcode, toString to DataChecksum. Contributed by Todd Lipcon.

Modified:
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDataChecksum.java

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1195831&r1=1195830&r2=1195831&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt Tue
Nov  1 05:25:06 2011
@@ -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)

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java?rev=1195831&r1=1195830&r2=1195831&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java
Tue Nov  1 05:25:06 2011
@@ -44,6 +44,10 @@ public class DataChecksum implements Che
   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 Che
     }
   }
 
-
+  @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 

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDataChecksum.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDataChecksum.java?rev=1195831&r1=1195830&r2=1195831&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDataChecksum.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDataChecksum.java
Tue Nov  1 05:25:06 2011
@@ -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));    



Mime
View raw message