int (@Nullable String v1, @Nullable String v2) { // todo duplicates com.intellij.util.text.VersionComparatorUtil.compare // todo please refactor next time you make changes here if (v1 == null && v2 == null) { return 0; } if (v1 == null) { return -1; } if (v2 == null) { return 1; } String[] part1 = v1.split("[._\\-]"); String[] part2 = v2.split("[._\\-]"); int idx = 0; for (; idx < part1.length && idx < part2.length; idx++) { String p1 = part1[idx]; String p2 = part2[idx]; int cmp; if (p1.matches("\\d+") && p2.matches("\\d+")) { cmp = Integer.valueOf(p1).compareTo(Integer.valueOf(p2)); } else { cmp = part1[idx].compareTo(part2[idx]); } if (cmp != 0) return cmp; } if (part1.length != part2.length) { boolean left = part1.length > idx; String[] parts = left ? part1 : part2; for (; idx < parts.length; idx++) { String p = parts[idx]; int cmp; if (p.matches("\\d+")) { cmp = Integer.valueOf(p).compareTo(0); } else { cmp = 1; } if (cmp != 0) return left ? cmp : -cmp; } } return 0; }