1 |
|
package org.europa.together.domain; |
2 |
|
|
3 |
|
import java.util.Objects; |
4 |
|
import org.europa.together.application.LogbackLogger; |
5 |
|
import org.europa.together.business.Logger; |
6 |
|
import org.europa.together.exceptions.MisconfigurationException; |
7 |
|
import org.europa.together.utils.StringUtils; |
8 |
|
import org.europa.together.utils.Validator; |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (103) |
Complexity: 34 |
Complexity Density: 0.58 |
|
36 |
|
public class Version implements Comparable<Version> { |
37 |
|
|
38 |
|
private static final Logger LOGGER = new LogbackLogger(Version.class); |
39 |
|
|
40 |
|
private int major = -1; |
41 |
|
private int minor = -1; |
42 |
|
private int patch = -1; |
43 |
|
private String label = ""; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@param |
49 |
|
@throws |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 6 |
Complexity Density: 0.32 |
|
51 |
58 |
public Version(final String version)... |
52 |
|
throws MisconfigurationException { |
53 |
57 |
if (!Validator.validate(version, Validator.SEMANTIC_VERSION_NUMBER)) { |
54 |
5 |
String msg = "The version number " + version |
55 |
|
+ " do not match the Pattern: [1].[2].[3]-[LABEL]."; |
56 |
5 |
throw new MisconfigurationException(msg); |
57 |
|
} |
58 |
52 |
String[] fragments = version.split("\\."); |
59 |
52 |
LOGGER.log("Fragments: " + fragments.length, LogLevel.DEBUG); |
60 |
|
|
61 |
52 |
major = Integer.parseInt(fragments[0]); |
62 |
51 |
if (fragments.length > 1) { |
63 |
50 |
if (!fragments[1].contains("-")) { |
64 |
49 |
minor = Integer.parseInt(fragments[1]); |
65 |
|
} else { |
66 |
1 |
LOGGER.log("Lable after minor.", LogLevel.DEBUG); |
67 |
1 |
String[] optional = fragments[1].split("-"); |
68 |
1 |
minor = Integer.parseInt(optional[0]); |
69 |
1 |
label = optional[1]; |
70 |
|
} |
71 |
|
} |
72 |
51 |
if (fragments.length > 2) { |
73 |
30 |
String[] optional = fragments[2].split("-"); |
74 |
|
|
75 |
30 |
patch = Integer.parseInt(optional[0]); |
76 |
30 |
if (optional.length == 2) { |
77 |
5 |
label = optional[1]; |
78 |
|
} |
79 |
|
} |
80 |
51 |
LOGGER.log("Version: " + toString(), LogLevel.DEBUG); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@return |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
5 |
public int getMajor() {... |
90 |
5 |
return major; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@return |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
5 |
public int getMinor() {... |
99 |
5 |
return minor; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@return |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
5 |
public int getPatch() {... |
109 |
5 |
return patch; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
@return |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
4 |
public String getLabel() {... |
119 |
4 |
return label; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@return |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
127 |
68 |
public String getVersion() {... |
128 |
68 |
String version = Integer.toString(major); |
129 |
68 |
if (minor != -1) { |
130 |
66 |
version = version + "." + minor; |
131 |
|
} |
132 |
68 |
if (patch != -1) { |
133 |
42 |
version = version + "." + patch; |
134 |
|
} |
135 |
68 |
if (!StringUtils.isEmpty(label)) { |
136 |
8 |
version = version + "-" + label; |
137 |
|
} |
138 |
68 |
return version; |
139 |
|
} |
140 |
|
|
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 7 |
Complexity Density: 0.47 |
|
142 |
20 |
@Override... |
143 |
|
public int compareTo(final Version o) { |
144 |
|
|
145 |
20 |
int compare; |
146 |
20 |
if (this.major > o.major) { |
147 |
2 |
compare = 1; |
148 |
18 |
} else if (this.major < o.major) { |
149 |
6 |
compare = -1; |
150 |
|
} else { |
151 |
12 |
if (this.minor > o.minor) { |
152 |
2 |
compare = 1; |
153 |
10 |
} else if (this.minor < o.minor) { |
154 |
2 |
compare = -1; |
155 |
|
} else { |
156 |
|
|
157 |
8 |
if (this.patch > o.patch) { |
158 |
3 |
compare = 1; |
159 |
5 |
} else if (this.patch < o.patch) { |
160 |
1 |
compare = -1; |
161 |
|
} else { |
162 |
4 |
compare = 0; |
163 |
|
} |
164 |
|
} |
165 |
|
} |
166 |
20 |
return compare; |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 11 |
Complexity Density: 1.38 |
|
169 |
15 |
@Override... |
170 |
|
public boolean equals(final Object object) { |
171 |
15 |
boolean success = false; |
172 |
15 |
if (object != null && object instanceof Version) { |
173 |
13 |
if (this == object) { |
174 |
1 |
success = true; |
175 |
|
} else { |
176 |
12 |
final Version other = (Version) object; |
177 |
12 |
if (Objects.equals(this.major, other.major) |
178 |
|
&& Objects.equals(this.minor, other.minor) |
179 |
|
&& ((this.patch == -1 || this.patch == 0) |
180 |
|
&& (other.patch == -1 || other.patch == 0) |
181 |
|
|| Objects.equals(this.patch, other.patch))) { |
182 |
5 |
success = true; |
183 |
|
} |
184 |
|
} |
185 |
|
} |
186 |
15 |
return success; |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
189 |
2 |
@Override... |
190 |
|
public int hashCode() { |
191 |
2 |
int hash = Objects.hashCode(this.major); |
192 |
2 |
hash += Objects.hashCode(this.minor); |
193 |
2 |
hash += Objects.hashCode(this.patch); |
194 |
2 |
return hash; |
195 |
|
} |
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
197 |
63 |
@Override... |
198 |
|
public String toString() { |
199 |
63 |
return "Version{" + getVersion() + "}"; |
200 |
|
} |
201 |
|
} |