int (@NotNull FilePath filePath1, @NotNull FilePath filePath2) { String path1 = filePath1.getPath(); String path2 = filePath2.getPath(); int commonPrefix = StringUtil.commonPrefixLength(path1, path2, myIgnoreCase); if (commonPrefix == path1.length() && commonPrefix == path2.length()) { if (filePath1.isDirectory() != filePath2.isDirectory()) { return filePath1.isDirectory() ? -1 : 1; } return 0; } else if (commonPrefix == path1.length() && path2.charAt(commonPrefix) == '/') { return filePath1.isDirectory() ? -1 : 1; // name1 == "", isDirectory2 == true } else if (commonPrefix == path2.length() && path1.charAt(commonPrefix) == '/') { return filePath2.isDirectory() ? 1 : -1; // name2 == "", isDirectory1 == true } else { int start = StringUtil.lastIndexOf(path1, '/', 0, commonPrefix) + 1; int end1 = path1.indexOf('/', start); int end2 = path2.indexOf('/', start); boolean isDirectory1 = end1 != -1 || filePath1.isDirectory(); boolean isDirectory2 = end2 != -1 || filePath2.isDirectory(); if (isDirectory1 != isDirectory2) { return isDirectory1 ? -1 : 1; } if (end1 == -1) end1 = path1.length(); if (end2 == -1) end2 = path2.length(); CharSequence name1 = new CharSequenceSubSequence(path1, start, end1); CharSequence name2 = new CharSequenceSubSequence(path2, start, end2); return compareFileNames(name1, name2); } }