class Hamming {
    private final int hammingDistance;

    Hamming(String leftStrand, String rightStrand) {
        hammingDistance = computeHammingDistance(leftStrand, rightStrand);
    }

    int getHammingDistance() {
        return hammingDistance;
    }

    private int computeHammingDistance(String leftStrand, String rightStrand) {
        if (leftStrand.length() == 0 && rightStrand.length() == 0) {
            return 0;
        } else if (leftStrand.length() == 0) {
            throw new IllegalArgumentException("left strand must not be empty.");
        } else if (rightStrand.length() == 0) {
            throw new IllegalArgumentException("right strand must not be empty.");
        } else if (leftStrand.length() != rightStrand.length()) {
            throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length.");
        }

        int length = leftStrand.length();
        int distance = 0;
        for (int i = 0; i < length; i++) {
            distance += hammingContributionAt(i, leftStrand, rightStrand);
        }

        return distance;
    }

    private int hammingContributionAt(int index, String leftStrand, String rightStrand) {
        return leftStrand.charAt(index) != rightStrand.charAt(index) ? 1 : 0;
    }

}

@@ -1,8 +1,84 @@
+import java.util.function.IntPredicate;%0Aimport java.util.stream.IntStream;%0A%0A
 class Ha
@@ -190,49 +190,35 @@
     
-hammingDistance = computeHammingDistance(
+String exceptionMessage = %22
 left
@@ -215,33 +215,36 @@
 ge = %22leftStrand
-,
+ and
  rightStrand);%0A 
@@ -243,167 +243,35 @@
 rand
-);%0A    %7D%0A%0A    int getHammingDistance() %7B%0A        return hammingDistance;%0A    %7D%0A%0A    private int computeHammingDistance(String leftStrand, String rightStrand) %7B
+ must be of equal length.%22;
 %0A   
@@ -303,15 +303,10 @@
 h() 
+!
 =
-= 0 &&
  rig
@@ -314,37 +314,32 @@
 tStrand.length()
- == 0
 ) %7B%0A            
@@ -342,33 +342,8 @@
     
-return 0;%0A        %7D else 
 if (
@@ -349,37 +349,33 @@
 (leftStrand.
-length() == 0
+isEmpty()
 ) %7B%0A        
@@ -382,43 +382,31 @@
     
-throw new IllegalArgumentException(
+    exceptionMessage = 
 %22lef
@@ -425,33 +425,32 @@
 t not be empty.%22
-)
 ;%0A        %7D else
@@ -439,30 +439,41 @@
 .%22;%0A        
-%7D else
+    %7D%0A           
  if (rightSt
@@ -481,21 +481,17 @@
 and.
-length() == 0
+isEmpty()
 ) %7B%0A
@@ -506,43 +506,31 @@
     
-throw new IllegalArgumentException(
+    exceptionMessage = 
 %22rig
@@ -558,17 +558,16 @@
  empty.%22
-)
 ;%0A      
@@ -572,166 +572,77 @@
     
-%7D else if (leftStrand.length() != rightStrand.length()) %7B%0A            throw new IllegalArgumentException(%22leftStrand and rightStrand must be of equal length.%22
+    %7D%0A            throw new IllegalArgumentException(exceptionMessage
 );%0A 
@@ -663,110 +663,98 @@
     
-int length = leftStrand.length();%0A        int distance = 0;%0A        for (int i = 0; i %3C length; i++) %7B
+IntPredicate areNotEqual = index -%3E leftStrand.charAt(index) != rightStrand.charAt(index);
 %0A   
@@ -762,21 +762,24 @@
     
-    d
+hammingD
 istance 
 += h
@@ -778,278 +778,160 @@
 nce 
-+
 = 
-hammingContributionAt(i, leftStrand, rightStrand);%0A        %7D%0A%0A        return distance;%0A    %7D%0A%0A    private int hammingContributionAt(int index, String leftStrand, String rightStrand) %7B%0A        return leftStrand.charAt(index) != rightStrand.charAt(index) ? 1 : 0
+(int) IntStream.range(0, leftStrand.length()).filter(areNotEqual).count();%0A    %7D%0A%0A    int getHammingDistance() %7B%0A        return hammingDistance
 ;%0A    %7D%0A
 %0A%7D%0A
@@ -927,11 +927,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Update hamming reference (#1660)