chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1594553 - in /chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src: main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ test/java/org/apache/chemistry/opencmis/commons/impl/misc/
Date Wed, 14 May 2014 12:13:52 GMT
Author: fmui
Date: Wed May 14 12:13:52 2014
New Revision: 1594553

URL: http://svn.apache.org/r1594553
Log:
ContentStreamHashImpl improvements

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java?rev=1594553&r1=1594552&r2=1594553&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ContentStreamHashImpl.java
Wed May 14 12:13:52 2014
@@ -76,18 +76,18 @@ public class ContentStreamHashImpl imple
      * @param hash
      *            the hash value
      */
-    public ContentStreamHashImpl(String algorithm, String hash) {
+    public ContentStreamHashImpl(String algorithm, String hashStr) {
         if (algorithm == null || algorithm.trim().length() == 0) {
             throw new IllegalArgumentException("Algorithm must be set!");
         }
 
-        if (hash == null || hash.trim().length() == 0) {
+        if (hashStr == null || hashStr.trim().length() == 0) {
             throw new IllegalArgumentException("Hash must be set!");
         }
 
         this.algorithm = algorithm.toLowerCase(Locale.ENGLISH);
-        this.hash = hash.replaceAll("\\s", "").toLowerCase(Locale.ENGLISH);
-        this.propertyValue = "{" + algorithm + "}" + hash;
+        this.hash = hashStr.replaceAll("\\s", "").toLowerCase(Locale.ENGLISH);
+        this.propertyValue = "{" + this.algorithm + "}" + this.hash;
     }
 
     /**
@@ -109,7 +109,7 @@ public class ContentStreamHashImpl imple
 
         this.algorithm = algorithm.toLowerCase(Locale.ENGLISH);
         this.hash = byteArrayToHexString(hashBytes);
-        this.propertyValue = "{" + algorithm + "}" + hash;
+        this.propertyValue = "{" + this.algorithm + "}" + this.hash;
     }
 
     public String getPropertyValue() {
@@ -124,6 +124,40 @@ public class ContentStreamHashImpl imple
         return hash;
     }
 
+    @Override
+    public int hashCode() {
+        return propertyValue.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+
+        ContentStreamHashImpl other = (ContentStreamHashImpl) obj;
+        if (propertyValue == null) {
+            if (other.propertyValue != null) {
+                return false;
+            }
+        } else if (!propertyValue.equals(other.propertyValue)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return propertyValue;
+    }
+
     /**
      * Creates a list of content hashes from a stream
      * <p>

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java?rev=1594553&r1=1594552&r2=1594553&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/misc/ContentStreamHashTest.java
Wed May 14 12:13:52 2014
@@ -19,7 +19,9 @@
 package org.apache.chemistry.opencmis.commons.impl.misc;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.util.List;
@@ -56,9 +58,13 @@ public class ContentStreamHashTest {
 
         assertEquals(hash1.getAlgorithm(), hash2.getAlgorithm());
         assertEquals(hash1.getHash(), hash2.getHash());
-        
+
         assertEquals(hash1.getAlgorithm(), hash3.getAlgorithm());
         assertEquals(hash1.getHash(), hash3.getHash());
+
+        assertFalse(hash1.equals(hash2));
+        assertFalse(hash1.equals(hash2));
+        assertTrue(hash2.equals(hash3));
     }
 
     @Test



Mime
View raw message