1 package org.openecomp.sdc.tosca.parser.api;
3 public class Version implements Comparable<Version> {
5 private String version;
7 public final String get() {
11 public Version(String version) {
13 throw new IllegalArgumentException("Version can not be null");
14 if(!version.matches("[0-9]+(\\.[0-9]+)*"))
15 throw new IllegalArgumentException("Invalid version format");
16 this.version = version;
19 @Override public int compareTo(Version that) {
22 String[] thisParts = this.get().split("\\.");
23 String[] thatParts = that.get().split("\\.");
24 int length = Math.max(thisParts.length, thatParts.length);
25 for(int i = 0; i < length; i++) {
26 int thisPart = i < thisParts.length ?
27 Integer.parseInt(thisParts[i]) : 0;
28 int thatPart = i < thatParts.length ?
29 Integer.parseInt(thatParts[i]) : 0;
30 if(thisPart < thatPart)
32 if(thisPart > thatPart)
38 @Override public boolean equals(Object that) {
43 if(this.getClass() != that.getClass())
45 return this.compareTo((Version) that) == 0;