2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.versioning.dao.types;
23 import com.datastax.driver.mapping.annotations.Transient;
24 import com.datastax.driver.mapping.annotations.UDT;
26 import lombok.NoArgsConstructor;
29 import java.util.Date;
32 @UDT(name = "version", keyspace = "dox")
36 public class Version {
37 public static final String VERSION_STRING_VIOLATION_MSG =
38 "Version string must be in the format of: {integer}.{integer}";
42 private int major; // TODO: 6/7/2017 remove!
43 private int minor; // TODO: 6/7/2017 remove!
47 private String description;
49 private String baseId;
51 private Date creationTime;
53 private Date modificationTime;
55 private VersionStatus status = VersionStatus.Draft;
57 private VersionState state;
59 private Map<String, Object> additionalInfo;
61 public Version(String id) {
66 public Version(int major, int minor) {
74 * @param versionString the version string
77 public static Version valueOf(String versionString) {
78 if (versionString == null) {
81 String[] versionLevels = versionString.split("\\.");
83 if (versionLevels.length != 2) {
84 throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
87 version = new Version(Integer.parseInt(versionLevels[0]), Integer.parseInt(versionLevels[1]));
88 } catch (Exception ex) {
89 throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
94 public Version calculateNextCandidate() {
95 return new Version(major, minor + 1);
98 public Version calculateNextFinal() {
99 return new Version(major + 1, 0);
103 public boolean isFinal() {
104 return major != 0 && minor == 0;
108 public int hashCode() {
110 result = 31 * result + minor;
115 public boolean equals(Object obj) {
119 if (obj == null || getClass() != obj.getClass()) {
123 Version version = (Version) obj;
124 return major == version.major && minor == version.minor;
127 public int compareTo(Version other){
128 if (this.major>other.major) {
130 } else if(this.major<other.major){
132 } else if(this.major == other.major){
133 return Integer.compare(this.minor,other.minor);
139 public String toString() {
140 return name != null ? name : major + "." + minor;
144 public Version clone() {
145 Version version = new Version();
146 version.setStatus(this.getStatus());
147 version.setCreationTime(this.getCreationTime());
148 version.setName(this.getName());
149 version.setBaseId(this.getBaseId());
150 version.setMajor(this.major);
151 version.setMinor(this.minor);
152 version.setModificationTime(this.getModificationTime());
153 version.setDescription(this.description);
154 version.setId(this.getId());