StringComparisonUtil implements Serializable { public static int getPrefixLength(final String string1, final String string2) { if (string1 == null || string2 == null) { return 0; } int[] cpArray1 = stringToCodePointArray(string1); int[] cpArray2 = stringToCodePointArray(string2); int lengthToMatch = Math.min(cpArray1.length, cpArray2.length); final int min = Math.min(MINPREFIXTESTLENGTH, lengthToMatch); for (int i = 0; i < min; i++) { if (cpArray1[i] != cpArray2[i]) { return i; } } return min; } private  StringComparisonUtil(); static int difference(String str1, String str2); static StringBuilder getCommonCharacters(final String string1, final String string2, final int distanceSep); static int getPrefixLength(final String string1, final String string2);  }
@Test public void testGetPrefixLength() { assertEquals(0, StringComparisonUtil.getPrefixLength(null, str2)); assertEquals(0, StringComparisonUtil.getPrefixLength(str1, null)); assertEquals(3, StringComparisonUtil.getPrefixLength(str1, str2)); assertEquals(3, StringComparisonUtil.getPrefixLength(str1, str3)); assertEquals(2, StringComparisonUtil.getPrefixLength(str1, str4)); assertEquals(0, StringComparisonUtil.getPrefixLength(str1, str5)); assertEquals(0, StringComparisonUtil.getPrefixLength(" ", "")); assertEquals(1, StringComparisonUtil.getPrefixLength(" ", " ")); assertEquals(2, StringComparisonUtil.getPrefixLength(str6, str7)); assertEquals(1, StringComparisonUtil.getPrefixLength(str8, str9)); assertEquals(2, StringComparisonUtil.getPrefixLength("𠀐𠀑𠀒𠀓𠀔", "𠀐𠀑𠀠𠀡𠀢𠀣")); assertEquals(1, StringComparisonUtil.getPrefixLength("𠀐𠀑𠀒𠀓𠀔", "𠀐a")); assertEquals(0, StringComparisonUtil.getPrefixLength("我𠀑𠀒𠀓𠀔", "𠀐𠀑𠀒ab")); }