//Set up an initial (null) abstract version
Version version = null;
//Check to see if the string is empty
if (versionAsString.isEmpty()) {
throw new InvalidVersionException("Can't create a blank version!");
}
//Set up a split
String[] versionParts = versionAsString.split("\\.");
//Switch by the number of version parts
switch (versionParts.length) {
case 4: {
int major = Integer.valueOf(versionParts[0]);
int minor = Integer.valueOf(versionParts[1]);
int build = Integer.valueOf(versionParts[2]);
int revision;
if (versionParts[3].contains("-") || versionParts[3].contains(" ")) {
revision = Integer.valueOf(versionParts[3].split("[ -]")[0]);
} else {
revision = Integer.valueOf(versionParts[3]);
}
version = new FourPartVersion(major, minor, build, revision);
}
break;
case 3: {
int major = Integer.valueOf(versionParts[0]);
int minor = Integer.valueOf(versionParts[1]);
int build;
if (versionParts[2].contains("-") || versionParts[2].contains(" ")) {
build = Integer.valueOf(versionParts[2].split("[ -]")[0]);
} else {
build = Integer.valueOf(versionParts[2]);
}
version = new ThreePartVersion(major, minor, build);
}
break;
case 2: {
int major = Integer.valueOf(versionParts[0]);
int minor;
if (versionParts[1].contains("-") || versionParts[1].contains(" ")) {
minor = Integer.valueOf(versionParts[1].split("[ -]")[0]);
} else {
minor = Integer.valueOf(versionParts[1]);
}
version = new TwoPartVersion(major, minor);
}
break;
case 1: {
int _version;
if (versionParts[0].contains("-") || versionParts[0].contains(" ")) {
_version = Integer.valueOf(versionParts[0].split("[ -]")[0]);
} else {
_version = Integer.valueOf(versionParts[0]);
}
version = new NumericVersion(_version);
}
break;
}
//Check the version before we start on the rest
if (version == null) {
throw new InvalidVersionException("Version \"" + versionAsString + "\" could not be decoded");
}
//Get the last part
String lastPart = versionParts[versionParts.length - 1];