public static Version fromString(String version){
  if (!Strings.hasLength(version)) {
    return Version.CURRENT;
  }
  final boolean snapshot;
  if (snapshot=version.endsWith("-SNAPSHOT")) {
    version=version.substring(0,version.length() - 9);
  }
  String[] parts=version.split("\\.|\\-");
  if (parts.length < 3 || parts.length > 4) {
    throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build: " + version);
  }
  try {
    final int major=Integer.parseInt(parts[0]) * 1000000;
    final int minor=Integer.parseInt(parts[1]) * 10000;
    final int revision=Integer.parseInt(parts[2]) * 100;
    int build=99;
    if (parts.length == 4) {
      String buildStr=parts[3];
      if (buildStr.startsWith("Beta") || buildStr.startsWith("beta")) {
        build=Integer.parseInt(buildStr.substring(4));
      }
      if (buildStr.startsWith("RC") || buildStr.startsWith("rc")) {
        build=Integer.parseInt(buildStr.substring(2)) + 50;
      }
    }
    final Version versionFromId=fromId(major + minor + revision+ build);
    if (snapshot != versionFromId.snapshot()) {
      return new Version(versionFromId.id,snapshot,versionFromId.luceneVersion);
    }
    return versionFromId;
  }
 catch (  NumberFormatException e) {
    throw new IllegalArgumentException("unable to parse version " + version,e);
  }
}

public static Version fromString ( String version ) { if ( ! Strings . hasLength ( version ) ) { return Version . CURRENT ; } final boolean snapshot ; if ( snapshot = version . endsWith ( "-SNAPSHOT" ) ) { version = version . substring ( 0 , version . length ( ) - 9 ) ; } String [ ] parts = version . split ( "\\.|\\-" ) ; if ( parts . length < 3 || parts . length > 4 ) { throw new IllegalArgumentException ( "the version needs to contain major, minor and revision, and optionally the build: " + version ) ; } try { final int major = Integer . parseInt ( parts [ 0 ] ) * 1000000 ; final int minor = Integer . parseInt ( parts [ 1 ] ) * 10000 ; final int revision = Integer . parseInt ( parts [ 2 ] ) * 100 ; int build = 99 ; if ( parts . length == 4 ) { String buildStr = parts [ 3 ] ; if ( buildStr . startsWith ( "Beta" ) || buildStr . startsWith ( "beta" ) ) { build = Integer . parseInt ( buildStr . substring ( 4 ) ) ; } if ( buildStr . startsWith ( "RC" ) || buildStr . startsWith ( "rc" ) ) { build = Integer . parseInt ( buildStr . substring ( 2 ) ) + 50 ; } } final Version versionFromId = fromId ( major + minor + revision + build ) ; if ( snapshot != versionFromId . snapshot ( ) ) { return new Version ( versionFromId . id , snapshot , versionFromId . luceneVersion ) ; } return versionFromId ; } catch ( NumberFormatException e ) { throw new IllegalArgumentException ( "unable to parse version " + version , e ) ; } }
returns the version given its string representation , current version if the argument is null or empty
