StringUtils { public static int getLevenshteinDistance(final String s, final String t) { checkNotNull(s); checkNotNull(t); if (s.equals(t)) { return 0; } if (s.length() == 0) { return t.length(); } if (t.length() == 0) { return s.length(); } final int[] v0 = new int[t.length() + 1]; final int[] v1 = new int[t.length() + 1]; for (int i = 0; i < v0.length; i++) { v0[i] = i; } for (int i = 0; i < s.length(); i++) { v1[0] = i + 1; for (int j = 0; j < t.length(); j++) { int cost = (s.charAt(i) == t.charAt(j)) ? 0 : 1; v1[j + 1] = Math.min(Math.min(v1[j] + 1, v0[j + 1] + 1), v0[j] + cost); } System.arraycopy(v1, 0, v0, 0, v0.length); } return v1[t.length()]; }  static String byteArrayToJsonString(byte[] bytes); static byte[] jsonStringToByteArray(String string); static int getLevenshteinDistance(final String s, final String t);  }
@Test public void testLevenshteinDistance() { assertEquals(0, StringUtils.getLevenshteinDistance("", "")); assertEquals(3, StringUtils.getLevenshteinDistance("", "abc")); assertEquals(3, StringUtils.getLevenshteinDistance("abc", "")); assertEquals(5, StringUtils.getLevenshteinDistance("abc", "12345")); assertEquals(1, StringUtils.getLevenshteinDistance("abc", "ac")); assertEquals(1, StringUtils.getLevenshteinDistance("abc", "ab1c")); assertEquals(1, StringUtils.getLevenshteinDistance("abc", "a1c")); }