@Test public void fromString() { Version version = Version.fromString("1.2.3-SNAPSHOT"); assertEquals(1, version.getMajor()); assertEquals(2, version.getMinor()); assertEquals(3, version.getMaintenance()); version = Version.fromString("2.3.4"); assertEquals(2, version.getMajor()); assertEquals(3, version.getMinor()); assertEquals(4, version.getMaintenance()); }
static Version fromString(String s) { Assert.isTrue(s.matches("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$")); s = s.replaceFirst("-.*$", StringUtils.EMPTY); String[] parts = s.split("\\."); return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); }
Version implements Comparable<Version> { static Version fromString(String s) { Assert.isTrue(s.matches("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$")); s = s.replaceFirst("-.*$", StringUtils.EMPTY); String[] parts = s.split("\\."); return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); } }
Version implements Comparable<Version> { static Version fromString(String s) { Assert.isTrue(s.matches("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$")); s = s.replaceFirst("-.*$", StringUtils.EMPTY); String[] parts = s.split("\\."); return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); } private  Version(int major, int minor, int maintenance); }
Version implements Comparable<Version> { static Version fromString(String s) { Assert.isTrue(s.matches("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$")); s = s.replaceFirst("-.*$", StringUtils.EMPTY); String[] parts = s.split("\\."); return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); } private  Version(int major, int minor, int maintenance); @Override int compareTo(Version v); @Override String toString(); }
Version implements Comparable<Version> { static Version fromString(String s) { Assert.isTrue(s.matches("^[0-9]+\\.[0-9]+\\.[0-9]+(-.+)?$")); s = s.replaceFirst("-.*$", StringUtils.EMPTY); String[] parts = s.split("\\."); return new Version(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); } private  Version(int major, int minor, int maintenance); @Override int compareTo(Version v); @Override String toString();  }