MessageVersion implements Comparable<MessageVersion> { protected Integer[] getVersionParts() { String[] sParts = version.split("\\."); ArrayList<Integer> iParts = new ArrayList<>(); int trailingZeros = 0; for (String sPart : sParts) { Integer iPart = new Integer(sPart); if (iPart == 0) { ++trailingZeros; } else { for (int i = 0; i < trailingZeros; ++i) { iParts.add(0); } trailingZeros = 0; iParts.add(iPart); } } return iParts.toArray(new Integer[iParts.size()]); } MessageVersion(String version); @Override int compareTo(MessageVersion that); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); static final MessageVersion NO_VERSION; }
@Test public void testGetVersionParts() throws Exception { MessageVersion version = new MessageVersion("1.0.0"); assertTrue(Arrays.equals(new Integer[]{1}, version.getVersionParts())); version = new MessageVersion("1.0"); assertTrue(Arrays.equals(new Integer[]{1}, version.getVersionParts())); version = new MessageVersion("1"); assertTrue(Arrays.equals(new Integer[]{1}, version.getVersionParts())); version = new MessageVersion("1.0.2"); assertTrue(Arrays.equals(new Integer[]{1, 0, 2}, version.getVersionParts())); }