/** * Parses a new Version object from a String. * * @param toParse The String object to parse. * @return a new Version object. * @throws IllegalArgumentException When there is an error parsing the String. */ public static Version parse(final String toParse) throws IllegalArgumentException { if (toParse == null) { throw new IllegalArgumentException("Error parsing version from null String"); } final Matcher m = STD_VERSION_PATT.matcher(toParse); if (!m.find()) { throw new IllegalArgumentException(String.format("Error parsing version from '%s'", toParse)); } Version v = new Version(); v.rawVersion = toParse; v.prefix = m.group(1); final String major = m.group(2); if (major != null && !major.equals("")) { v.setMajor(major); } final String minor = m.group(3); if (minor != null && !minor.equals("")) { v.setMinor(minor); } final String build = m.group(4); if (build != null && !build.equals("")) { v.setBuild(build); } final String revision = m.group(5); if (revision != null && !revision.equals("")) { v.setRevision(m.group(5)); } v.suffix = m.group(6); return v; }
/** * Sets the version's REVISION component. * * @param toSet The version's REVISION component. */ public void setRevision(int toSet) { setRevision(String.valueOf(toSet)); }