2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.common.database.data;
24 import java.text.ParseException;
25 import org.eclipse.jdt.annotation.NonNull;
29 * @author Michael Dürre
32 public class DatabaseVersion {
34 private final String raw;
35 private final int major;
36 private final int minor;
37 private final int revision;
39 public DatabaseVersion(@NonNull String version) throws ParseException {
40 String[] hlp = version.split("\\.");
42 throw new ParseException("unable to parse version string: " + version, 0);
45 this.major = Integer.parseInt(hlp[0]);
46 this.minor = Integer.parseInt(hlp[1]);
47 this.revision = Integer.parseInt(hlp[2]);
51 public String toString() {
52 return String.format("%d.%d.%d", this.major, this.minor, this.revision);
60 public DatabaseVersion(int major, int minor, int revision) {
61 this.raw = String.format("%d.%d.%d", major, minor, revision);
64 this.revision = revision;
68 * @return the revision
70 public int getRevision() {
77 public int getMinor() {
84 public int getMajor() {
89 public boolean equals(Object obj) {
90 if (!(obj instanceof DatabaseVersion)) {
93 DatabaseVersion esobj = (DatabaseVersion) obj;
94 return this.major == esobj.major && this.minor == esobj.minor && this.revision == esobj.revision;
98 public int hashCode() {
99 return this.raw.hashCode();
102 public boolean isNewerOrEqualThan(DatabaseVersion v) {
103 if (this.equals(v)) {
106 return this.isNewerThan(v);
108 public boolean isNewerThan(DatabaseVersion v) {
109 if (this.major > v.major) {
111 } else if (this.major < v.major) {
114 if (this.minor > v.minor) {
116 } else if (this.minor < v.minor) {
119 if (this.revision > v.revision) {
125 public boolean isOlderOrEqualThan(DatabaseVersion v) {
126 if (this.equals(v)) {
129 return this.isOlderThan(v);
132 public boolean isOlderThan(DatabaseVersion v) {
133 if (this.major < v.major) {
135 } else if (this.major > v.major) {
138 if (this.minor < v.minor) {
140 } else if (this.minor > v.minor) {
143 if (this.revision < v.revision) {