aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java282
1 files changed, 141 insertions, 141 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java
index 268ee28b96..0b71f03599 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/version/Version.java
@@ -48,145 +48,145 @@ import java.util.regex.Pattern;
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class Version implements Comparable<Version> {
- private Integer majorVersion;
-
- private Integer minorVersion;
-
- private Integer incrementalVersion;
-
- private Integer buildNumber;
-
- private String qualifier;
-
- private ComparableVersion comparable;
-
- public Version(String version) {
- parseVersion(version);
- }
-
- @Override
- public int hashCode() {
- return 11 + comparable.hashCode();
- }
-
- @Override
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
-
- if (!(other instanceof Version)) {
- return false;
- }
-
- return compareTo((Version) other) == 0;
- }
-
- public int compareTo(Version otherVersion) {
- return this.comparable.compareTo(otherVersion.comparable);
- }
-
- public int getMajorVersion() {
- return majorVersion != null ? majorVersion : 0;
- }
-
- public int getMinorVersion() {
- return minorVersion != null ? minorVersion : 0;
- }
-
- public int getIncrementalVersion() {
- return incrementalVersion != null ? incrementalVersion : 0;
- }
-
- public int getBuildNumber() {
- return buildNumber != null ? buildNumber : 0;
- }
-
- public String getQualifier() {
- return qualifier;
- }
-
- public final void parseVersion(String version) {
- comparable = new ComparableVersion(version);
-
- int index = version.indexOf("-");
-
- String part1;
- String part2 = null;
-
- if (index < 0) {
- part1 = version;
- } else {
- part1 = version.substring(0, index);
- part2 = version.substring(index + 1);
- }
-
- if (part2 != null) {
- try {
- if ((part2.length() == 1) || !part2.startsWith("0")) {
- buildNumber = Integer.valueOf(part2);
- } else {
- qualifier = part2;
- }
- } catch (NumberFormatException e) {
- qualifier = part2;
- }
- }
-
- if ((!part1.contains(".")) && !part1.startsWith("0")) {
- try {
- majorVersion = Integer.valueOf(part1);
- } catch (NumberFormatException e) {
- // qualifier is the whole version, including "-"
- qualifier = version;
- buildNumber = null;
- }
- } else {
- boolean fallback = false;
-
- StringTokenizer tok = new StringTokenizer(part1, ".");
- try {
- majorVersion = getNextIntegerToken(tok);
- if (tok.hasMoreTokens()) {
- minorVersion = getNextIntegerToken(tok);
- }
- if (tok.hasMoreTokens()) {
- incrementalVersion = getNextIntegerToken(tok);
- }
- if (tok.hasMoreTokens()) {
- qualifier = tok.nextToken();
- fallback = Pattern.compile("\\d+").matcher(qualifier).matches();
- }
-
- // string tokenzier won't detect these and ignores them
- if (part1.contains("..") || part1.startsWith(".") || part1.endsWith(".")) {
- fallback = true;
- }
- } catch (NumberFormatException e) {
- fallback = true;
- }
-
- if (fallback) {
- // qualifier is the whole version, including "-"
- qualifier = version;
- majorVersion = null;
- minorVersion = null;
- incrementalVersion = null;
- buildNumber = null;
- }
- }
- }
-
- private static Integer getNextIntegerToken(StringTokenizer tok) {
- String s = tok.nextToken();
- if ((s.length() > 1) && s.startsWith("0")) {
- throw new NumberFormatException("Number part has a leading 0: '" + s + "'");
- }
- return Integer.valueOf(s);
- }
-
- @Override
- public String toString() {
- return comparable.toString();
- }
+ private Integer majorVersion;
+
+ private Integer minorVersion;
+
+ private Integer incrementalVersion;
+
+ private Integer buildNumber;
+
+ private String qualifier;
+
+ private ComparableVersion comparable;
+
+ public Version(String version) {
+ parseVersion(version);
+ }
+
+ @Override
+ public int hashCode() {
+ return 11 + comparable.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+
+ if (!(other instanceof Version)) {
+ return false;
+ }
+
+ return compareTo((Version) other) == 0;
+ }
+
+ public int compareTo(Version otherVersion) {
+ return this.comparable.compareTo(otherVersion.comparable);
+ }
+
+ public int getMajorVersion() {
+ return majorVersion != null ? majorVersion : 0;
+ }
+
+ public int getMinorVersion() {
+ return minorVersion != null ? minorVersion : 0;
+ }
+
+ public int getIncrementalVersion() {
+ return incrementalVersion != null ? incrementalVersion : 0;
+ }
+
+ public int getBuildNumber() {
+ return buildNumber != null ? buildNumber : 0;
+ }
+
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ public final void parseVersion(String version) {
+ comparable = new ComparableVersion(version);
+
+ int index = version.indexOf("-");
+
+ String part1;
+ String part2 = null;
+
+ if (index < 0) {
+ part1 = version;
+ } else {
+ part1 = version.substring(0, index);
+ part2 = version.substring(index + 1);
+ }
+
+ if (part2 != null) {
+ try {
+ if ((part2.length() == 1) || !part2.startsWith("0")) {
+ buildNumber = Integer.valueOf(part2);
+ } else {
+ qualifier = part2;
+ }
+ } catch (NumberFormatException e) {
+ qualifier = part2;
+ }
+ }
+
+ if ((!part1.contains(".")) && !part1.startsWith("0")) {
+ try {
+ majorVersion = Integer.valueOf(part1);
+ } catch (NumberFormatException e) {
+ // qualifier is the whole version, including "-"
+ qualifier = version;
+ buildNumber = null;
+ }
+ } else {
+ boolean fallback = false;
+
+ StringTokenizer tok = new StringTokenizer(part1, ".");
+ try {
+ majorVersion = getNextIntegerToken(tok);
+ if (tok.hasMoreTokens()) {
+ minorVersion = getNextIntegerToken(tok);
+ }
+ if (tok.hasMoreTokens()) {
+ incrementalVersion = getNextIntegerToken(tok);
+ }
+ if (tok.hasMoreTokens()) {
+ qualifier = tok.nextToken();
+ fallback = Pattern.compile("\\d+").matcher(qualifier).matches();
+ }
+
+ // string tokenzier won't detect these and ignores them
+ if (part1.contains("..") || part1.startsWith(".") || part1.endsWith(".")) {
+ fallback = true;
+ }
+ } catch (NumberFormatException e) {
+ fallback = true;
+ }
+
+ if (fallback) {
+ // qualifier is the whole version, including "-"
+ qualifier = version;
+ majorVersion = null;
+ minorVersion = null;
+ incrementalVersion = null;
+ buildNumber = null;
+ }
+ }
+ }
+
+ private static Integer getNextIntegerToken(StringTokenizer tok) {
+ String s = tok.nextToken();
+ if ((s.length() > 1) && s.startsWith("0")) {
+ throw new NumberFormatException("Number part has a leading 0: '" + s + "'");
+ }
+ return Integer.valueOf(s);
+ }
+
+ @Override
+ public String toString() {
+ return comparable.toString();
+ }
}