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