@Test public void testParseString() { version = Version.parseString("0.0.0"); assertEquals("0.0.0", version.toString()); version = Version.parseString("2"); assertEquals("2.0.0", version.toString()); version = Version.parseString("3.1"); assertEquals("3.1.0", version.toString()); }
public static Version parseString(String version) { int p = version.indexOf('.', 0); if (p > -1) { int major = Integer.parseInt(version.substring(0, p)); int q = version.indexOf('.', p + 1); if (q > -1) { int minor = Integer.parseInt(version.substring(p + 1, q)); int update = Integer.parseInt(version.substring(q + 1)); return new Version(major, minor, update); } else { return new Version(major, Integer.parseInt(version.substring(p + 1)), 0); } } else { return new Version(Integer.parseInt(version), 0, 0); } }
Version implements Serializable, Comparable<Version> { public static Version parseString(String version) { int p = version.indexOf('.', 0); if (p > -1) { int major = Integer.parseInt(version.substring(0, p)); int q = version.indexOf('.', p + 1); if (q > -1) { int minor = Integer.parseInt(version.substring(p + 1, q)); int update = Integer.parseInt(version.substring(q + 1)); return new Version(major, minor, update); } else { return new Version(major, Integer.parseInt(version.substring(p + 1)), 0); } } else { return new Version(Integer.parseInt(version), 0, 0); } } }
Version implements Serializable, Comparable<Version> { public static Version parseString(String version) { int p = version.indexOf('.', 0); if (p > -1) { int major = Integer.parseInt(version.substring(0, p)); int q = version.indexOf('.', p + 1); if (q > -1) { int minor = Integer.parseInt(version.substring(p + 1, q)); int update = Integer.parseInt(version.substring(q + 1)); return new Version(major, minor, update); } else { return new Version(major, Integer.parseInt(version.substring(p + 1)), 0); } } else { return new Version(Integer.parseInt(version), 0, 0); } } Version(int major, int minor, int update); }
Version implements Serializable, Comparable<Version> { public static Version parseString(String version) { int p = version.indexOf('.', 0); if (p > -1) { int major = Integer.parseInt(version.substring(0, p)); int q = version.indexOf('.', p + 1); if (q > -1) { int minor = Integer.parseInt(version.substring(p + 1, q)); int update = Integer.parseInt(version.substring(q + 1)); return new Version(major, minor, update); } else { return new Version(major, Integer.parseInt(version.substring(p + 1)), 0); } } else { return new Version(Integer.parseInt(version), 0, 0); } } Version(int major, int minor, int update); static Version parseString(String version); boolean isGreaterThan(Version version); boolean isGreaterOrEqualThan(Version version); boolean isEqualTo(Version version); int getMinorVersion(); int getMajorVersion(); int getUpdateVersion(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object object); @Override int compareTo(Version v); }
Version implements Serializable, Comparable<Version> { public static Version parseString(String version) { int p = version.indexOf('.', 0); if (p > -1) { int major = Integer.parseInt(version.substring(0, p)); int q = version.indexOf('.', p + 1); if (q > -1) { int minor = Integer.parseInt(version.substring(p + 1, q)); int update = Integer.parseInt(version.substring(q + 1)); return new Version(major, minor, update); } else { return new Version(major, Integer.parseInt(version.substring(p + 1)), 0); } } else { return new Version(Integer.parseInt(version), 0, 0); } } Version(int major, int minor, int update); static Version parseString(String version); boolean isGreaterThan(Version version); boolean isGreaterOrEqualThan(Version version); boolean isEqualTo(Version version); int getMinorVersion(); int getMajorVersion(); int getUpdateVersion(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object object); @Override int compareTo(Version v); static final Version ZERO; static final Version MIN; static final Version MAX; }