-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hamming.java
28 lines (22 loc) · 872 Bytes
/
Hamming.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.stream.IntStream;
public class Hamming {
private int hammingDistance;
public Hamming(String leftStrand, String rightStrand) {
if (leftStrand.isEmpty() && rightStrand.isEmpty()) {
return;
} else if (leftStrand.trim().equals("")) {
throw new IllegalArgumentException("left strand must not be empty.");
} else if (rightStrand.trim().equals("")) {
throw new IllegalArgumentException("right strand must not be empty.");
}
if (leftStrand.length() == rightStrand.length()) {
hammingDistance = (int) IntStream.range(0, leftStrand.length())
.filter(x -> leftStrand.charAt(x) != rightStrand.charAt(x)).count();
} else {
throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length.");
}
}
public int getHammingDistance() {
return hammingDistance;
}
}