Version implements Comparable<Version>, Serializable { @Override public int compareTo(Version o) { for (int i = 0; i < Math.max(parts.length, o.parts.length); i++) { if (i < parts.length) { if (i < o.parts.length) { if (parts[i] < o.parts[i]) { return -1; } else if (parts[i] > o.parts[i]) { return 1; } } else { if (parts[i] > 0) { return 1; } } } else { if (o.parts[i] > 0) { return -1; } } } if (this.extension != null) { if (o.extension != null) { return this.extension.compareTo(o.extension); } else { return -1; } } else if (o.extension != null) { return 1; } else { return 0; } } Version(int... parts);  Version(int part0, String extension);  Version(int part0, int part1, String extension);  Version(int part0, int part1, int part2,  String extension);  Version(int[] parts, String extension); int[] getParts(); String getExtension(); boolean isAtLeast(Version version); @Override int compareTo(Version o); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static Version parse(String str);  }
@Test public void testCompareTo() { assertEquals(0, new Version(1).compareTo(new Version(1))); assertEquals(0, new Version(1, 0, 0).compareTo(new Version(1, 0, 0))); assertEquals(0, new Version(1).compareTo(new Version(1, 0, 0))); assertEquals(0, new Version(1, 0, 0).compareTo(new Version(1))); assertEquals(1, new Version(1, 0, 0).compareTo(new Version(1, 0, 0, "SNAPSHOT"))); assertEquals(-1, new Version(1, 0, 0, "SNAPSHOT").compareTo(new Version(1, 0, 0))); assertEquals(0, new Version(1, 0, 0, "SNAPSHOT").compareTo(new Version(1, 0, 0, "SNAPSHOT"))); assertEquals(1, new Version(1).compareTo(new Version(1, 0, 0, "SNAPSHOT"))); assertEquals(-1, new Version(1, 0, 0, "SNAPSHOT").compareTo(new Version(1))); assertEquals(0, new Version(1, 0, 0, "SNAPSHOT").compareTo(new Version(1, "SNAPSHOT"))); assertEquals(-1, new Version(0, 9, 9).compareTo(new Version(1))); assertEquals(-1, new Version(0, 9, 9).compareTo(new Version(1, 0, 0))); assertEquals(1, new Version(1, 0, 1).compareTo(new Version(1))); assertEquals(1, new Version(1, 0, 1).compareTo(new Version(1, 0, 0))); assertEquals(1, new Version(2).compareTo(new Version(1))); assertEquals(1, new Version(2).compareTo(new Version(1, 0, 0))); assertEquals(1, new Version(2, 0, 0).compareTo(new Version(1, 0, 0))); assertEquals(-1, new Version(1).compareTo(new Version(2))); assertEquals(-1, new Version(1, 0, 0).compareTo(new Version(2))); assertEquals(-1, new Version(1, 0, 0).compareTo(new Version(2, 0, 0))); }