@Test public void testLowerComparsion() { Assert.assertTrue(new Version(1).compareTo(new Version(2)) < 0); Assert.assertTrue(new Version(1).compareTo(new Version(20)) < 0); Assert.assertTrue(new Version(1, 2).compareTo(new Version(1, 3)) < 0); Assert.assertTrue(new Version(1, 2).compareTo(new Version(2)) < 0); Assert.assertTrue(new Version(1, 2).compareTo(new Version(1, 100)) < 0); Assert.assertTrue(new Version(1, 2, 3).compareTo(new Version(1, 3)) < 0); Assert.assertTrue(new Version(1, 2, 3).compareTo(new Version(1, 2, 4)) < 0); Assert.assertTrue(new Version(2, 1, 2).compareTo(new Version(2, 11, 0)) < 0); Assert.assertTrue(new Version(2, 1, 2).compareTo(new Version(2, 20, 1)) < 0); Assert.assertTrue(new Version(1, 0, 0).compareTo(new Version(1, 0, 0, 0, 0, 1)) < 0); }
@Override public int compareTo(Version o) { if (o == null) { return 1; } for (int i = 0; i < Math.min(versions.length, o.versions.length); i++) { if (!versions[i].equals(o.versions[i])) { return Integer.compare(versions[i], o.versions[i]); } } return Integer.compare(versions.length, o.versions.length); }
Version implements Comparable<Version> { @Override public int compareTo(Version o) { if (o == null) { return 1; } for (int i = 0; i < Math.min(versions.length, o.versions.length); i++) { if (!versions[i].equals(o.versions[i])) { return Integer.compare(versions[i], o.versions[i]); } } return Integer.compare(versions.length, o.versions.length); } }
Version implements Comparable<Version> { @Override public int compareTo(Version o) { if (o == null) { return 1; } for (int i = 0; i < Math.min(versions.length, o.versions.length); i++) { if (!versions[i].equals(o.versions[i])) { return Integer.compare(versions[i], o.versions[i]); } } return Integer.compare(versions.length, o.versions.length); } Version(Integer... parts); }
Version implements Comparable<Version> { @Override public int compareTo(Version o) { if (o == null) { return 1; } for (int i = 0; i < Math.min(versions.length, o.versions.length); i++) { if (!versions[i].equals(o.versions[i])) { return Integer.compare(versions[i], o.versions[i]); } } return Integer.compare(versions.length, o.versions.length); } Version(Integer... parts); static Version from(String string); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(Version o); }
Version implements Comparable<Version> { @Override public int compareTo(Version o) { if (o == null) { return 1; } for (int i = 0; i < Math.min(versions.length, o.versions.length); i++) { if (!versions[i].equals(o.versions[i])) { return Integer.compare(versions[i], o.versions[i]); } } return Integer.compare(versions.length, o.versions.length); } Version(Integer... parts); static Version from(String string); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(Version o);  }