public class HammingDistance extends Object implements EditDistance<Integer>
For further explanation about the Hamming Distance, take a look at its Wikipedia page at http://en.wikipedia.org/wiki/Hamming_distance.
Constructor and Description |
---|
HammingDistance() |
Modifier and Type | Method and Description |
---|---|
Integer |
apply(CharSequence left,
CharSequence right)
Find the Hamming Distance between two strings with the same
length.
|
public HammingDistance()
public Integer apply(CharSequence left, CharSequence right)
The distance starts with zero, and for each occurrence of a different character in either String, it increments the distance by 1, and finally return its value.
Since the Hamming Distance can only be calculated between strings of equal length, input of different lengths will throw IllegalArgumentException
distance.apply("", "") = 0 distance.apply("pappa", "pappa") = 0 distance.apply("1011101", "1011111") = 1 distance.apply("ATCG", "ACCC") = 2 distance.apply("karolin", "kerstin" = 3
apply
in interface EditDistance<Integer>
apply
in interface SimilarityScore<Integer>
left
- the first CharSequence, must not be nullright
- the second CharSequence, must not be nullIllegalArgumentException
- if either input is null
or
if they do not have the same lengthCopyright © 2014–2017 The Apache Software Foundation. All rights reserved.