JaroWinkler { public final double similarity(@NonNull final String s1, @NonNull final String s2) { if (s1 == null) { throw new NullPointerException("s1 must not be null"); } if (s2 == null) { throw new NullPointerException("s2 must not be null"); } if (s1.equals(s2)) { return 1; } int[] mtp = matches(s1, s2); float m = mtp[0]; if (m == 0) { return 0f; } double j = ((m / s1.length() + m / s2.length() + (m - mtp[1]) / m)) / THREE; double jw = j; if (j > getThreshold()) { jw = j + Math.min(JW_COEF, 1.0 / mtp[THREE]) * mtp[2] * (1 - j); } return jw; } JaroWinkler();  JaroWinkler(final double threshold); final double getThreshold(); final double similarity(@NonNull final String s1, @NonNull final String s2); final double distance(@NonNull final String s1, @NonNull final String s2);  }
@Test public void testCapitalization() { String s = "Sleeping"; String s2 = "sleeping"; assert(jw.similarity(s,s2) > .8); }
@Test public void testShort() { String s = "sl"; String s2 = "s"; assert(jw.similarity(s,s2) > .8); }
@Test public void testDash() { String s = "Sleeping-well"; String s2 = "Sleeping"; assert(jw.similarity(s,s2) > .8); }
@Test public void testNumbers() { String s = "Sleeping1"; String s2 = "Sleeping2"; assert(jw.similarity(s,s2) > .8); }
@Test public void testContained() { String s = "onlaptopwork"; String s2 = "laptop"; assert(jw.similarity(s,s2) < .8); }
@Test public void testIdentical() { String s = "sleeping"; String s2 = "sleeping"; assert(jw.similarity(s,s2) == 1.0); }