@Test public void testCompare() { assertEquals(0, new Version("4").compareTo(new Version("4"))); assertEquals(0, new Version("4.1").compareTo(new Version("4.1"))); assertEquals(0, new Version("4.12").compareTo(new Version("4.12"))); assertEquals(-1, new Version("4.12").compareTo(new Version("4.22"))); assertEquals(-1, new Version("4.12.9").compareTo(new Version("4.22"))); assertEquals(-1, new Version("4.12.9-LTS").compareTo(new Version("4.22"))); assertEquals(1, new Version("4.22").compareTo(new Version("4.12"))); assertEquals(1, new Version("4.22").compareTo(new Version("4.12.9"))); assertEquals(1, new Version("4.22").compareTo(new Version("4.12.9-LTS"))); }
@Override public int compareTo(final Version that) { String[] thisParts = version.split("\\."); String[] thatParts = that.version.split("\\."); int length = Math.max(thisParts.length, thatParts.length); for(int i = 0; i < length; i++) { int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; if(thisPart < thatPart) { return -1; } if(thisPart > thatPart) { return 1; } } return 0; }
Version implements Comparable<Version> { @Override public int compareTo(final Version that) { String[] thisParts = version.split("\\."); String[] thatParts = that.version.split("\\."); int length = Math.max(thisParts.length, thatParts.length); for(int i = 0; i < length; i++) { int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; if(thisPart < thatPart) { return -1; } if(thisPart > thatPart) { return 1; } } return 0; } }
Version implements Comparable<Version> { @Override public int compareTo(final Version that) { String[] thisParts = version.split("\\."); String[] thatParts = that.version.split("\\."); int length = Math.max(thisParts.length, thatParts.length); for(int i = 0; i < length; i++) { int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; if(thisPart < thatPart) { return -1; } if(thisPart > thatPart) { return 1; } } return 0; } Version(String version); }
Version implements Comparable<Version> { @Override public int compareTo(final Version that) { String[] thisParts = version.split("\\."); String[] thatParts = that.version.split("\\."); int length = Math.max(thisParts.length, thatParts.length); for(int i = 0; i < length; i++) { int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; if(thisPart < thatPart) { return -1; } if(thisPart > thatPart) { return 1; } } return 0; } Version(String version); @Override int compareTo(final Version that); @Override int hashCode(); @Override boolean equals(Object that); }
Version implements Comparable<Version> { @Override public int compareTo(final Version that) { String[] thisParts = version.split("\\."); String[] thatParts = that.version.split("\\."); int length = Math.max(thisParts.length, thatParts.length); for(int i = 0; i < length; i++) { int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; if(thisPart < thatPart) { return -1; } if(thisPart > thatPart) { return 1; } } return 0; } Version(String version); @Override int compareTo(final Version that); @Override int hashCode(); @Override boolean equals(Object that);  }