Version implements Comparable<Version> { @Override public int compareTo(Version v) { return new CompareToBuilder() .append(major, v.major) .append(minor, v.minor) .append(maintenance, v.maintenance) .toComparison(); } private  Version(int major, int minor, int maintenance); @Override int compareTo(Version v); @Override String toString();  }
@Test public void compareTo() { Version version = Version.fromString("1.2.3-SNAPSHOT"); Version version2 = Version.fromString("2.3.4"); assertTrue(version.compareTo(version2) < 0); assertTrue(version2.compareTo(version) > 0); assertEquals(0, version.compareTo(version)); }