CharSequences { @SuppressFBWarnings("CLI_CONSTANT_LIST_INDEX") public static int distance(final CharSequence s1, final CharSequence s2) { int l1 = s1.length(); int l2 = s2.length(); if (l1 == 0) { return l2; } if (l2 == 0) { return l1; } int[] prev = new int[l2]; char c1 = s1.charAt(0); char cs20 = s2.charAt(0); prev[0] = distance(c1, cs20); for (int j = 1; j < l2; j++) { int pd = prev[j - 1]; prev[j] = pd == j ? pd + distance(c1, s2.charAt(j)) : pd + 1; } int[] dist = new int[l2]; for (int i = 1; i < l1; i++) { c1 = s1.charAt(i); int pd = prev[0]; dist[0] = pd == i ? pd + distance(c1, cs20) : pd + 1; for (int j = 1; j < l2; j++) { dist[j] = min(prev[j - 1] + distance(c1, s2.charAt(j)), min(prev[j] + 1, dist[j - 1] + 1)); } int[] tmp = prev; prev = dist; dist = tmp; } return prev[l2 - 1]; } private  CharSequences(); @SuppressFBWarnings("CLI_CONSTANT_LIST_INDEX") static int distance(final CharSequence s1, final CharSequence s2); static int distance(final char c1, final char c2); @Deprecated static int compareTo(final CharSequence s, final CharSequence t); static int compare(final CharSequence s, final CharSequence t); static int compare(final CharSequence s, final int sLength,
          final CharSequence t, final int tLength); static int compare(final CharSequence s, final int sFrom, final int sLength,
          final CharSequence t, final int tFrom, final int tLength); static boolean equalsNullables(final CharSequence s, final CharSequence t); static boolean equals(final CharSequence s, final CharSequence t); static int hashcode(final CharSequence cs); static CharSequence subSequence(final CharSequence seq, final int startIdx, final int endIdx); static boolean startsWith(final CharSequence sequence, final CharSequence prefix, final int toffset); static boolean endsWith(final CharSequence qc, final CharSequence with); static Appendable lineNumbered(final int startLineNr, final Appendable appendable); static Appendable lineNumbered(final int startLineNr, final Appendable appendable, final IntAppender ia); static CharSequence toLineNumbered(final int startLineNr, final CharSequence source); static CharSequence toLineNumbered(final int startLineNr, final CharSequence source, final IntAppender ia); static int parseInt(@Nonnull final CharSequence s); static int parseInt(@Nonnull final CharSequence cs, final int radix); @SuppressWarnings("checkstyle:InnerAssignment") static int parseUnsignedInt(@Nonnull final CharSequence cs, final int radix, final int idxFrom); @SuppressWarnings("checkstyle:InnerAssignment") static int parseUnsignedInt(@Nonnull final CharSequence cs, final int radix,
          final int idxFrom, final int idxTo); @SuppressWarnings("checkstyle:InnerAssignment") static long parseUnsignedLong(@Nonnull final CharSequence cs, final int radix, final int idxFrom); @SuppressWarnings("checkstyle:InnerAssignment") static long parseUnsignedLong(@Nonnull final CharSequence cs, final int radix,
          final int idxFrom, final int idxTo, final boolean strict); static long parseLong(@Nonnull final CharSequence cs); static long parseLong(@Nonnull final CharSequence cs, final int radix); static boolean containsAnyChar(final CharSequence string, final char... chars); static boolean containsAnyChar(final CharSequence string,
          final int start, final int end,
          final char... chars); static boolean isValidJavaId(final CharSequence name); static boolean isValidFileName(@Nonnull final CharSequence fileName); static T validatedFileName(@Nonnull final T fileName); static boolean regionMatches(final CharSequence t, final int toffset,
          final CharSequence other, final int ooffset, final int plen); static boolean regionMatchesIgnoreCase(final CharSequence ta, final int toffset,
          final CharSequence pa, final int ooffset, final int plen); static boolean match(final CharSequence wildcard, final CharSequence cs2Match); CharSequence getJavaRegexpStr(final CharSequence wildcard); static int indexOf(final CharSequence cs, final int from, final int to, final char c); static int indexOf(final CharSequence cs, final int from, final int to, final IntPredicate cp); static int indexOf(final CharSequence cs, final int from, final int to, final char... chars); static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr); static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr); static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr, final int idxStart); static int countIgnoreCase(final CharSequence str, final CharSequence searchStr); @GwtIncompatible static Reader reader(final CharSequence cs);  }
@Test public void testDistance() { Assert.assertEquals(3, CharSequences.distance("abc", "abcdef")); Assert.assertEquals(3, CharSequences.distance("def", "abcdef")); Assert.assertEquals(1, CharSequences.distance("abc", "bc")); Assert.assertEquals(3, CharSequences.distance("abc", "def")); Assert.assertEquals(1, CharSequences.distance("zoltran", "zoltan")); }
@Test public void testDistance2() { Assert.assertEquals(3, CharSequences.distance("horse", "ros")); }
@Test public void testDistance3() { Assert.assertEquals(27, CharSequences.distance("pneumonoultramicroscopicsilicovolcanoconiosis", "ultramicroscopically")); }