Make minor improvements
This commit is contained in:
parent
5d0aa683cb
commit
838d40e90e
2
pom.xml
2
pom.xml
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<groupId>com.github.zafarkhaja</groupId>
|
<groupId>com.github.zafarkhaja</groupId>
|
||||||
<artifactId>semver</artifactId>
|
<artifactId>semver</artifactId>
|
||||||
<version>0.2.0-SNAPSHOT</version>
|
<version>0.2.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>semver</name>
|
<name>semver</name>
|
||||||
|
|
|
@ -32,16 +32,14 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
|
class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
static final String FORMAT = "([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)";
|
static final String FORMAT = "([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)";
|
||||||
private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$");
|
private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$");
|
||||||
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
AlphaNumericVersion(String value) {
|
AlphaNumericVersion(String value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new NullPointerException(
|
throw new NullPointerException("Alpha-numeric version MUST NOT be NULL");
|
||||||
"Alpha-numeric version MUST NOT be NULL"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Matcher matcher = PATTERN.matcher(value);
|
Matcher matcher = PATTERN.matcher(value);
|
||||||
if (!matcher.matches()) {
|
if (!matcher.matches()) {
|
||||||
|
|
|
@ -73,9 +73,7 @@ public class Version implements Comparable<Version> {
|
||||||
public static Version valueOf(String value) {
|
public static Version valueOf(String value) {
|
||||||
Matcher matcher = SEMVER_PATTERN.matcher(value);
|
Matcher matcher = SEMVER_PATTERN.matcher(value);
|
||||||
if (!matcher.matches()) {
|
if (!matcher.matches()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Illegal version format");
|
||||||
"Illegal version format"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NormalVersion normal = new NormalVersion(
|
NormalVersion normal = new NormalVersion(
|
||||||
|
@ -188,7 +186,11 @@ public class Version implements Comparable<Version> {
|
||||||
if (preRelease != null && other.preRelease != null) {
|
if (preRelease != null && other.preRelease != null) {
|
||||||
result = preRelease.compareTo(other.preRelease);
|
result = preRelease.compareTo(other.preRelease);
|
||||||
} else if (preRelease == null ^ other.preRelease == null) {
|
} else if (preRelease == null ^ other.preRelease == null) {
|
||||||
result = preRelease == null ? 1 : -1;
|
/**
|
||||||
|
* Pre-release versions satisfy but have a lower precedence
|
||||||
|
* than the associated normal version. (SemVer p.9)
|
||||||
|
*/
|
||||||
|
result = (preRelease == null) ? 1 : -1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +200,11 @@ public class Version implements Comparable<Version> {
|
||||||
if (build != null && other.build != null) {
|
if (build != null && other.build != null) {
|
||||||
result = build.compareTo(other.build);
|
result = build.compareTo(other.build);
|
||||||
} else if (build == null ^ other.build == null) {
|
} else if (build == null ^ other.build == null) {
|
||||||
result = build == null ? -1 : 1;
|
/**
|
||||||
|
* Build versions satisfy and have a higher precedence
|
||||||
|
* than the associated normal version. (SemVer p.10)
|
||||||
|
*/
|
||||||
|
result = (build == null) ? -1 : 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user