UpgradeTaskId implements Comparable<UpgradeTaskId> { @Override public int compareTo(UpgradeTaskId other) { if (other == null) { return 1; } if (!StringUtils.equals(version, other.getVersion())) { final String[] versionParts = version.split("\\."); final String[] otherVersionParts = other.getVersion().split("\\."); for (int i = 0; i < versionParts.length; i++) { String currentPart = leftPad(versionParts[i], 6, '0'); String otherPart = "000000"; if (i < otherVersionParts.length) { otherPart = leftPad(otherVersionParts[i], 6, '0'); } final int result = currentPart.compareTo(otherPart); if (result != 0) { return result; } } } return Integer.compare(order, other.getOrder()); } UpgradeTaskId();  UpgradeTaskId(String version, String name, int order); String getVersion(); void setVersion(String version); String getName(); void setName(String name); int getOrder(); void setOrder(int order); @Override String toString(); String getUniqueKey(); @Override int compareTo(UpgradeTaskId other); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void shouldEquals() throws Exception { UpgradeTaskId id1 = new UpgradeTaskId("1.2.0", "name", 1); UpgradeTaskId id2 = new UpgradeTaskId("1.2.0", "name", 1); assertEquals(0, id1.compareTo(id2)); }
@Test public void shouldCompareOrder() throws Exception { UpgradeTaskId id1 = new UpgradeTaskId("1.2.0", "name", 1); UpgradeTaskId id2 = new UpgradeTaskId("1.2.0", "name", 2); assertTrue(id1.compareTo(id2) < 0); }
@Test public void shouldCompareVersion() throws Exception { UpgradeTaskId id1 = new UpgradeTaskId("10.5.0", "name", 1); UpgradeTaskId id2 = new UpgradeTaskId("1.3.0", "name", 1); assertTrue(id1.compareTo(id2) > 0); }
@Test public void shouldDealWithEdition() throws Exception { UpgradeTaskId id1 = new UpgradeTaskId("5.3.0-PE", "name", 1); UpgradeTaskId id2 = new UpgradeTaskId("5.3.1-EE", "name", 1); assertTrue(id1.compareTo(id2) < 0); }
@Test public void shouldDealWithShorterVersion() throws Exception { UpgradeTaskId id1 = new UpgradeTaskId("1.6.3", "name", 1); UpgradeTaskId id2 = new UpgradeTaskId("1.6", "name", 1); assertTrue(id1.compareTo(id2) > 0); }