@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); }
@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 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 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); }
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(); }
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();  }