Last active
July 24, 2020 16:53
-
-
Save dmlloyd/dd35d41dccaf8e9d1fb22a99e25c15bb to your computer and use it in GitHub Desktop.
Sort maven versions neatly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //usr/bin/env jbang "$0" "$@" ; exit $? | |
| //DEPS org.apache.maven:maven-artifact:3.6.3 | |
| import org.apache.maven.artifact.versioning.ComparableVersion; | |
| import java.util.*; | |
| public class ComprehensiveSort { | |
| static final Comparator<String> c = (a, b) -> Integer.signum(new ComparableVersion(a).compareTo(new ComparableVersion(b))); | |
| public static void main(String[] args) { | |
| List<String> list = new ArrayList<String>(); | |
| for (char c : new char[] { '0', '1', 'x' }) { | |
| for (char d : new char[] { '0', '1', 'x' }) { | |
| for (char e : new char[] { '0', '1', 'x' }) { | |
| list.add("" + c + "." + d + "." + e); | |
| //list.add("" + c + "." + d + "." + e + "-1"); | |
| list.add("" + c + "." + d + "." + e + "-x"); | |
| } | |
| } | |
| } | |
| Collections.sort(list, c); | |
| for (String s : list) { | |
| System.out.println(s); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //usr/bin/env jbang "$0" "$@" ; exit $? | |
| //DEPS org.apache.maven:maven-artifact:3.6.3 | |
| import org.apache.maven.artifact.versioning.ComparableVersion; | |
| import java.util.*; | |
| public class VersionSort { | |
| static final Comparator<String> c = (a, b) -> Integer.signum(new ComparableVersion(a).compareTo(new ComparableVersion(b))); | |
| public static void main(String[] args) { | |
| Collections.sort(Arrays.asList(args), c); | |
| for (String s : args) { | |
| System.out.println(s); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment