Version implements Comparable<Version> { @Override public int compareTo(Version other) { final int mmmCompared = Integer.compare(this.majorMinorMicro, other.majorMinorMicro); switch (mmmCompared) { case 0: return this.qualifier == other.qualifier ? 0 : (this.qualifier == null ? -1 : (other.qualifier == null ? 1 : this.qualifier.compareTo(other.qualifier))); default: return mmmCompared; } } Version(byte major, byte minor, byte micro, String qualifier);   Version(int majorMinorMicro, String qualifier); static Version of(String version); @Override int compareTo(Version other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static final Version _0_10_0; static final Version CURRENT; }
@Test public void compareTo() { Version[] versions = new Version[] { Version.of("4.2.3-q"), Version.of("2.2.3-q"), Version.of("2.2.2-q"), Version.of("2.2.2-q"), Version.of("2.1.2-q"), Version.of("2.1.1-q"), Version.of("0.0.0-b"), Version.of("0.0.0-a"), Version.of("0.0.0") }; Arrays.sort(versions); Assert.assertArrayEquals(new Version[] { Version.of("0.0.0"), Version.of("0.0.0-a"), Version.of("0.0.0-b"), Version.of("2.1.1-q"), Version.of("2.1.2-q"), Version.of("2.2.2-q"), Version.of("2.2.2-q"), Version.of("2.2.3-q"), Version.of("4.2.3-q") }, versions); }