-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExasolVersionNumber.java
91 lines (81 loc) · 2.92 KB
/
ExasolVersionNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.exasol.versionnumberprovider;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.exasol.errorreporting.ExaError;
/**
* This class represents Exasol docker-db version numbers.
*/
class ExasolVersionNumber implements Comparable<ExasolVersionNumber> {
private static final Pattern DOCKER_IMAGE_VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(?:-d(.+))?");
private final int major;
private final int minor;
private final int fix;
private final String imageRevision;
private final String versionNumberString;
/**
* Create a new instance of {@link ExasolVersionNumber}.
*
* @param versionNumberString version number to wrap
*/
ExasolVersionNumber(final String versionNumberString) {
this.versionNumberString = versionNumberString;
final Matcher matcher = DOCKER_IMAGE_VERSION_PATTERN.matcher(versionNumberString);
if (!matcher.matches()) {
throw new IllegalStateException(ExaError.messageBuilder("E-EVNP-1")
.message("Unsupported release tag: {{tag}}.", versionNumberString).toString());
}
this.major = Integer.parseInt(matcher.group(1));
this.minor = Integer.parseInt(matcher.group(2));
this.fix = Integer.parseInt(matcher.group(3));
this.imageRevision = matcher.group(4) == null ? "" : matcher.group(4);
}
@Override
public int compareTo(final ExasolVersionNumber other) {
if (this.major != other.major) {
return Integer.compare(this.major, other.major);
} else if (this.minor != other.minor) {
return Integer.compare(this.minor, other.minor);
} else if (this.fix != other.fix) {
return Integer.compare(this.fix, other.fix);
} else {
return this.imageRevision.compareTo(other.imageRevision);
}
}
@Override
public boolean equals(final Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ExasolVersionNumber)) {
return false;
}
final ExasolVersionNumber that = (ExasolVersionNumber) other;
return this.major == that.major && this.minor == that.minor && this.fix == that.fix
&& this.imageRevision.equals(that.imageRevision);
}
@Override
public int hashCode() {
return Objects.hash(this.major, this.minor, this.fix, this.imageRevision);
}
@Override
public String toString() {
return this.versionNumberString;
}
/**
* Get the MAJOR version.
*
* @return integer MAJOR of version string "MAJOR.MINOR.FIX(suffix)"
*/
public int getMajorVersion() {
return this.major;
}
/**
* Get the MINOR version.
*
* @return integer MINOR of version string "MAJOR.MINOR.FIX(suffix)"
*/
public int getMinorVersion() {
return this.minor;
}
}