int (@Nullable CharSequence s1, @Nullable CharSequence s2, boolean ignoreCase) { if (s1 == s2) return 0; if (s1 == null) return -1; if (s2 == null) return 1; int length1 = s1.length(); int length2 = s2.length(); int i = 0; for (; i < length1 && i < length2; i++) { int diff = compare(s1.charAt(i), s2.charAt(i), ignoreCase); if (diff != 0) { return diff; } } return length1 - length2; }