@Test public void testCompareTo() { SchemaVersion schemaVersion1 = new SchemaVersion(); SchemaVersion schemaVersion2 = new SchemaVersion(); schemaVersion1.version = "1.0"; schemaVersion2.version = "1.0"; assertEquals(0, schemaVersion1.compareTo(schemaVersion2)); schemaVersion1.version = "1.0"; schemaVersion2.version = "1.0.0"; assertEquals(0, schemaVersion1.compareTo(schemaVersion2)); schemaVersion1.version = "1.0"; schemaVersion2.version = "2.0"; assertTrue(schemaVersion1.compareTo(schemaVersion2) < 0); assertTrue(schemaVersion2.compareTo(schemaVersion1) > 0); schemaVersion1.version = "0.1"; schemaVersion2.version = "0.2"; assertTrue(schemaVersion1.compareTo(schemaVersion2) < 0); assertTrue(schemaVersion2.compareTo(schemaVersion1) > 0); schemaVersion1.version = "0.2"; schemaVersion2.version = "0.2.5"; assertTrue(schemaVersion1.compareTo(schemaVersion2) < 0); assertTrue(schemaVersion2.compareTo(schemaVersion1) > 0); }
public int compareTo(SchemaVersion other) { if(this.version.equalsIgnoreCase(other.version) || this.version == V_ANY.version || other.version == V_ANY.version) { return 0; } String[] v1Splits = this.version.split("\\."); String[] v2Splits = other.version.split("\\."); int v1 = 0; for(String v1Split: v1Splits) { v1 = 10 * v1 + Integer.parseInt(v1Split); } int v2 = 0; for(String v2Split: v2Splits) { v2 = 10 * v2 + Integer.parseInt(v2Split); } if(v1Splits.length < v2Splits.length) { v1 *= 10 * (v2Splits.length - v1Splits.length); } else if(v2Splits.length < v1Splits.length) { v2 *= 10 * (v1Splits.length - v2Splits.length); } return Integer.compare(v1, v2); }
SchemaVersion implements Comparable<SchemaVersion> { public int compareTo(SchemaVersion other) { if(this.version.equalsIgnoreCase(other.version) || this.version == V_ANY.version || other.version == V_ANY.version) { return 0; } String[] v1Splits = this.version.split("\\."); String[] v2Splits = other.version.split("\\."); int v1 = 0; for(String v1Split: v1Splits) { v1 = 10 * v1 + Integer.parseInt(v1Split); } int v2 = 0; for(String v2Split: v2Splits) { v2 = 10 * v2 + Integer.parseInt(v2Split); } if(v1Splits.length < v2Splits.length) { v1 *= 10 * (v2Splits.length - v1Splits.length); } else if(v2Splits.length < v1Splits.length) { v2 *= 10 * (v1Splits.length - v2Splits.length); } return Integer.compare(v1, v2); } }
SchemaVersion implements Comparable<SchemaVersion> { public int compareTo(SchemaVersion other) { if(this.version.equalsIgnoreCase(other.version) || this.version == V_ANY.version || other.version == V_ANY.version) { return 0; } String[] v1Splits = this.version.split("\\."); String[] v2Splits = other.version.split("\\."); int v1 = 0; for(String v1Split: v1Splits) { v1 = 10 * v1 + Integer.parseInt(v1Split); } int v2 = 0; for(String v2Split: v2Splits) { v2 = 10 * v2 + Integer.parseInt(v2Split); } if(v1Splits.length < v2Splits.length) { v1 *= 10 * (v2Splits.length - v1Splits.length); } else if(v2Splits.length < v1Splits.length) { v2 *= 10 * (v1Splits.length - v2Splits.length); } return Integer.compare(v1, v2); } SchemaVersion();  SchemaVersion(String version); }
SchemaVersion implements Comparable<SchemaVersion> { public int compareTo(SchemaVersion other) { if(this.version.equalsIgnoreCase(other.version) || this.version == V_ANY.version || other.version == V_ANY.version) { return 0; } String[] v1Splits = this.version.split("\\."); String[] v2Splits = other.version.split("\\."); int v1 = 0; for(String v1Split: v1Splits) { v1 = 10 * v1 + Integer.parseInt(v1Split); } int v2 = 0; for(String v2Split: v2Splits) { v2 = 10 * v2 + Integer.parseInt(v2Split); } if(v1Splits.length < v2Splits.length) { v1 *= 10 * (v2Splits.length - v1Splits.length); } else if(v2Splits.length < v1Splits.length) { v2 *= 10 * (v1Splits.length - v2Splits.length); } return Integer.compare(v1, v2); } SchemaVersion();  SchemaVersion(String version); void setVersion(String version); String getVersion(); int compareTo(SchemaVersion other); @Override boolean equals(Object obj); boolean isLessThanOrEqual(SchemaVersion other); boolean isLessThan(SchemaVersion other); boolean isGreaterThanOrEqual(SchemaVersion other); boolean isGreaterThan(SchemaVersion other); @Override String toString(); }
SchemaVersion implements Comparable<SchemaVersion> { public int compareTo(SchemaVersion other) { if(this.version.equalsIgnoreCase(other.version) || this.version == V_ANY.version || other.version == V_ANY.version) { return 0; } String[] v1Splits = this.version.split("\\."); String[] v2Splits = other.version.split("\\."); int v1 = 0; for(String v1Split: v1Splits) { v1 = 10 * v1 + Integer.parseInt(v1Split); } int v2 = 0; for(String v2Split: v2Splits) { v2 = 10 * v2 + Integer.parseInt(v2Split); } if(v1Splits.length < v2Splits.length) { v1 *= 10 * (v2Splits.length - v1Splits.length); } else if(v2Splits.length < v1Splits.length) { v2 *= 10 * (v1Splits.length - v2Splits.length); } return Integer.compare(v1, v2); } SchemaVersion();  SchemaVersion(String version); void setVersion(String version); String getVersion(); int compareTo(SchemaVersion other); @Override boolean equals(Object obj); boolean isLessThanOrEqual(SchemaVersion other); boolean isLessThan(SchemaVersion other); boolean isGreaterThanOrEqual(SchemaVersion other); boolean isGreaterThan(SchemaVersion other); @Override String toString(); static final SchemaVersion V_ANY; static final SchemaVersion V_0_1; static final SchemaVersion V_0_2; static final SchemaVersion V_0_2_5; static final SchemaVersion V_0_3; static final SchemaVersion V_0_4; static final SchemaVersion V_0_4_5; static final SchemaVersion V_0_5; }