コード例 #1
0
ファイル: Version.java プロジェクト: pmeisen/gen-misc
  @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;
  }
コード例 #2
0
ファイル: Version.java プロジェクト: pmeisen/gen-misc
  @Override
  public int compareTo(final Version toCompare) {
    int result = toString().compareTo(toCompare.toString());
    int snapshot = new Boolean(toCompare.isSnapshot()).compareTo(isSnapshot());
    if (result == 0) {
      return snapshot;
    }

    result = compareInts(getMajorAsInt(), toCompare.getMajorAsInt());
    if (result != 0) {
      return result;
    }

    result = compareInts(getMinorAsInt(), toCompare.getMinorAsInt());
    if (result != 0) {
      return result;
    }

    result = compareInts(getBuildAsInt(), toCompare.getBuildAsInt());
    if (result != 0) {
      return result;
    }

    result = compareInts(getRevisionAsInt(), toCompare.getRevisionAsInt());
    if (result != 0) {
      return result;
    }

    return snapshot;
  }
コード例 #3
0
ファイル: Version.java プロジェクト: pmeisen/gen-misc
  /**
   * 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;
  }