@Test public void of() { Version actual = Version.of("1.2.3"); Assert.assertEquals(new Version((byte) 1, (byte) 2, (byte) 3, null), actual); Assert.assertEquals(1, actual.getMajor()); Assert.assertEquals(2, actual.getMinor()); Assert.assertEquals(3, actual.getMicro()); Assert.assertNull(actual.getQualifier()); }
public static Version of(String version) { int start = 0; int end = version.indexOf(PERIOD, start); if (end >= 1) { final byte major = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(PERIOD, start); if (end >= 0 && end - start >= 1) { final byte minor = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(DASH, start); if (end >= 0) { if (end - start >= 1) { final byte micro = Byte.valueOf(version.substring(start, end)); final String qualifier = version.substring(end + 1); return new Version(major, minor, micro, qualifier); } } else { final byte micro = Byte.valueOf(version.substring(start)); return new Version(major, minor, micro, null); } } } throw new IllegalArgumentException("Cannot parse \"" + version + "\" into a version. A string matching major.minor.micro[-qualifier] expected."); }
Version implements Comparable<Version> { public static Version of(String version) { int start = 0; int end = version.indexOf(PERIOD, start); if (end >= 1) { final byte major = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(PERIOD, start); if (end >= 0 && end - start >= 1) { final byte minor = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(DASH, start); if (end >= 0) { if (end - start >= 1) { final byte micro = Byte.valueOf(version.substring(start, end)); final String qualifier = version.substring(end + 1); return new Version(major, minor, micro, qualifier); } } else { final byte micro = Byte.valueOf(version.substring(start)); return new Version(major, minor, micro, null); } } } throw new IllegalArgumentException("Cannot parse \"" + version + "\" into a version. A string matching major.minor.micro[-qualifier] expected."); } }
Version implements Comparable<Version> { public static Version of(String version) { int start = 0; int end = version.indexOf(PERIOD, start); if (end >= 1) { final byte major = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(PERIOD, start); if (end >= 0 && end - start >= 1) { final byte minor = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(DASH, start); if (end >= 0) { if (end - start >= 1) { final byte micro = Byte.valueOf(version.substring(start, end)); final String qualifier = version.substring(end + 1); return new Version(major, minor, micro, qualifier); } } else { final byte micro = Byte.valueOf(version.substring(start)); return new Version(major, minor, micro, null); } } } throw new IllegalArgumentException("Cannot parse \"" + version + "\" into a version. A string matching major.minor.micro[-qualifier] expected."); } Version(byte major, byte minor, byte micro, String qualifier);   Version(int majorMinorMicro, String qualifier); }
Version implements Comparable<Version> { public static Version of(String version) { int start = 0; int end = version.indexOf(PERIOD, start); if (end >= 1) { final byte major = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(PERIOD, start); if (end >= 0 && end - start >= 1) { final byte minor = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(DASH, start); if (end >= 0) { if (end - start >= 1) { final byte micro = Byte.valueOf(version.substring(start, end)); final String qualifier = version.substring(end + 1); return new Version(major, minor, micro, qualifier); } } else { final byte micro = Byte.valueOf(version.substring(start)); return new Version(major, minor, micro, null); } } } throw new IllegalArgumentException("Cannot parse \"" + version + "\" into a version. A string matching major.minor.micro[-qualifier] expected."); } Version(byte major, byte minor, byte micro, String qualifier);   Version(int majorMinorMicro, String qualifier); static Version of(String version); @Override int compareTo(Version other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
Version implements Comparable<Version> { public static Version of(String version) { int start = 0; int end = version.indexOf(PERIOD, start); if (end >= 1) { final byte major = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(PERIOD, start); if (end >= 0 && end - start >= 1) { final byte minor = Byte.valueOf(version.substring(start, end)); start = end + 1; end = version.indexOf(DASH, start); if (end >= 0) { if (end - start >= 1) { final byte micro = Byte.valueOf(version.substring(start, end)); final String qualifier = version.substring(end + 1); return new Version(major, minor, micro, qualifier); } } else { final byte micro = Byte.valueOf(version.substring(start)); return new Version(major, minor, micro, null); } } } throw new IllegalArgumentException("Cannot parse \"" + version + "\" into a version. A string matching major.minor.micro[-qualifier] expected."); } Version(byte major, byte minor, byte micro, String qualifier);   Version(int majorMinorMicro, String qualifier); static Version of(String version); @Override int compareTo(Version other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static final Version _0_10_0; static final Version CURRENT; }