@Test public void testVersionParses() { Assert.assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3")); Assert.assertEquals(new Version(1, 2, 3, "foo"), Version.parseVersion("1.2.3.foo")); Assert.assertEquals(new Version(1, 2, 0), Version.parseVersion("1.2")); Assert.assertEquals(new Version(1, 2, 0, "foo"), Version.parseVersion("1.2.foo")); Assert.assertEquals(new Version(1, 0, 0), Version.parseVersion("1")); Assert.assertEquals(new Version(1, 0, 0, "foo"), Version.parseVersion("1.foo")); tryBadVersionParse("qwerty"); tryBadVersionParse("qwerty.foo"); tryBadVersionParse("1.qwerty.foo"); tryBadVersionParse("1.2.qwerty.foo"); }
public static Version parseVersion(String version) throws SimpleInteractiveSpacesException { if (version != null) { version = version.trim(); Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) { String major = matcher.group(REGEX_GROUP_NUMBER_MAJOR); String minor = matcher.group(REGEX_GROUP_NUMBER_MINOR); String micro = matcher.group(REGEX_GROUP_NUMBER_MICRO); String qualifier = matcher.group(REGEX_GROUP_NUMBER_QUALIFIER); if (qualifier != null) { qualifier = qualifier.substring(1); } return new Version(Integer.parseInt(major), (minor != null ? Integer.parseInt(minor.substring(1)) : 0), (micro != null ? Integer.parseInt(micro.substring(1)) : 0), qualifier); } else { throw new SimpleInteractiveSpacesException(String.format("Illegal version %s", version)); } } else { throw new SimpleInteractiveSpacesException("Illegal version null"); } }
Version implements Comparable<Version> { public static Version parseVersion(String version) throws SimpleInteractiveSpacesException { if (version != null) { version = version.trim(); Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) { String major = matcher.group(REGEX_GROUP_NUMBER_MAJOR); String minor = matcher.group(REGEX_GROUP_NUMBER_MINOR); String micro = matcher.group(REGEX_GROUP_NUMBER_MICRO); String qualifier = matcher.group(REGEX_GROUP_NUMBER_QUALIFIER); if (qualifier != null) { qualifier = qualifier.substring(1); } return new Version(Integer.parseInt(major), (minor != null ? Integer.parseInt(minor.substring(1)) : 0), (micro != null ? Integer.parseInt(micro.substring(1)) : 0), qualifier); } else { throw new SimpleInteractiveSpacesException(String.format("Illegal version %s", version)); } } else { throw new SimpleInteractiveSpacesException("Illegal version null"); } } }
Version implements Comparable<Version> { public static Version parseVersion(String version) throws SimpleInteractiveSpacesException { if (version != null) { version = version.trim(); Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) { String major = matcher.group(REGEX_GROUP_NUMBER_MAJOR); String minor = matcher.group(REGEX_GROUP_NUMBER_MINOR); String micro = matcher.group(REGEX_GROUP_NUMBER_MICRO); String qualifier = matcher.group(REGEX_GROUP_NUMBER_QUALIFIER); if (qualifier != null) { qualifier = qualifier.substring(1); } return new Version(Integer.parseInt(major), (minor != null ? Integer.parseInt(minor.substring(1)) : 0), (micro != null ? Integer.parseInt(micro.substring(1)) : 0), qualifier); } else { throw new SimpleInteractiveSpacesException(String.format("Illegal version %s", version)); } } else { throw new SimpleInteractiveSpacesException("Illegal version null"); } } Version(int major, int minor, int micro, String qualifier);  Version(int major, int minor, int micro); }
Version implements Comparable<Version> { public static Version parseVersion(String version) throws SimpleInteractiveSpacesException { if (version != null) { version = version.trim(); Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) { String major = matcher.group(REGEX_GROUP_NUMBER_MAJOR); String minor = matcher.group(REGEX_GROUP_NUMBER_MINOR); String micro = matcher.group(REGEX_GROUP_NUMBER_MICRO); String qualifier = matcher.group(REGEX_GROUP_NUMBER_QUALIFIER); if (qualifier != null) { qualifier = qualifier.substring(1); } return new Version(Integer.parseInt(major), (minor != null ? Integer.parseInt(minor.substring(1)) : 0), (micro != null ? Integer.parseInt(micro.substring(1)) : 0), qualifier); } else { throw new SimpleInteractiveSpacesException(String.format("Illegal version %s", version)); } } else { throw new SimpleInteractiveSpacesException("Illegal version null"); } } Version(int major, int minor, int micro, String qualifier);  Version(int major, int minor, int micro); static boolean isLegalSyntax(String candidate); static Version parseVersionIncludeNull(String version); static Version parseVersion(String version); int getMajor(); int getMinor(); int getMicro(); String getQualifier(); boolean lessThan(Version other); boolean lessThanOrEqual(Version other); boolean greaterThan(Version other); boolean greaterThanOrEqual(Version other); Version incrementMajor(); Version incrementMinor(); Version incrementMicro(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(Version o); @Override String toString(); }
Version implements Comparable<Version> { public static Version parseVersion(String version) throws SimpleInteractiveSpacesException { if (version != null) { version = version.trim(); Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) { String major = matcher.group(REGEX_GROUP_NUMBER_MAJOR); String minor = matcher.group(REGEX_GROUP_NUMBER_MINOR); String micro = matcher.group(REGEX_GROUP_NUMBER_MICRO); String qualifier = matcher.group(REGEX_GROUP_NUMBER_QUALIFIER); if (qualifier != null) { qualifier = qualifier.substring(1); } return new Version(Integer.parseInt(major), (minor != null ? Integer.parseInt(minor.substring(1)) : 0), (micro != null ? Integer.parseInt(micro.substring(1)) : 0), qualifier); } else { throw new SimpleInteractiveSpacesException(String.format("Illegal version %s", version)); } } else { throw new SimpleInteractiveSpacesException("Illegal version null"); } } Version(int major, int minor, int micro, String qualifier);  Version(int major, int minor, int micro); static boolean isLegalSyntax(String candidate); static Version parseVersionIncludeNull(String version); static Version parseVersion(String version); int getMajor(); int getMinor(); int getMicro(); String getQualifier(); boolean lessThan(Version other); boolean lessThanOrEqual(Version other); boolean greaterThan(Version other); boolean greaterThanOrEqual(Version other); Version incrementMajor(); Version incrementMinor(); Version incrementMicro(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(Version o); @Override String toString(); static final char VERSION_SECTION_SEPARATOR; static final String QUALIFIER_REGEX; static final Pattern VERSION_PATTERN; static final int REGEX_GROUP_NUMBER_MAJOR; static final int REGEX_GROUP_NUMBER_MINOR; static final int REGEX_GROUP_NUMBER_MICRO; static final int REGEX_GROUP_NUMBER_QUALIFIER; static final Pattern QUALIFIER_PATTERN; static final String VERSION_FORMAT_DESCRIPTION; }