int (File f1, File f2) { String name1 = StringUtil.toLowerCase(f1.getName()); String name2 = StringUtil.toLowerCase(f2.getName()); // C:\Program Files\Git is better candidate for _default_ than C:\Program Files\Git_1.8.0 if (name1.equals("git")) { return name2.equals("git") ? fallback(f1, f2) : 1; } else if (name2.equals("git")) { return -1; } final Pattern GIT_WITH_VERSION = Pattern.compile("^git[ _]*([\\d\\.]*).*$"); Matcher m1 = GIT_WITH_VERSION.matcher(name1); Matcher m2 = GIT_WITH_VERSION.matcher(name2); if (m1.matches() && m2.matches()) { GitVersion v1 = parseGitVersion(m1.group(1)); GitVersion v2 = parseGitVersion(m2.group(1)); if (v1 == null || v2 == null) { return fallback(f1, f2); } int compareVersions = v1.compareTo(v2); return compareVersions == 0 ? fallback(f1, f2) : compareVersions; } return fallback(f1, f2); }