Esempio n. 1
0
  @Override
  public Object clone() throws CloneNotSupportedException {
    Version v = new Version();

    v.rawVersion = this.rawVersion;
    v.prefix = this.prefix;
    v.suffix = this.suffix;

    v.numberOfComponents = this.numberOfComponents;

    v.major = this.major;
    v.minor = this.minor;
    v.build = this.build;
    v.revision = this.revision;

    return v;
  }
Esempio n. 2
0
  /**
   * 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;
  }