JavaVersion implements Comparable<JavaVersion> { @Override public int compareTo(JavaVersion o) { if (this.version - o.version == 0) { if (this.major - o.major == 0) { return this.minor - o.minor; } else { return this.major - o.major; } } return this.version - o.version; } JavaVersion(int version, int major, int minor); static void main(String[] args); static JavaVersion fromString(String s); @Override int compareTo(JavaVersion o); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testCompareTo() throws Exception { assertEquals(new JavaVersion(1,9,2).compareTo(new JavaVersion(1,9,2)),0); assertTrue(new JavaVersion(1,9,2).compareTo(new JavaVersion(1,7,2))>0); assertTrue(new JavaVersion(1,5,2).compareTo(new JavaVersion(1,7,2))<0); }