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>
|
||||
<artifactId>semver</artifactId>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
<version>0.2.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>semver</name>
|
||||
|
|
|
@ -32,16 +32,14 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
|
||||
|
||||
private String value;
|
||||
|
||||
static final String FORMAT = "([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)";
|
||||
private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$");
|
||||
|
||||
private String value;
|
||||
|
||||
AlphaNumericVersion(String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException(
|
||||
"Alpha-numeric version MUST NOT be NULL"
|
||||
);
|
||||
throw new NullPointerException("Alpha-numeric version MUST NOT be NULL");
|
||||
}
|
||||
Matcher matcher = PATTERN.matcher(value);
|
||||
if (!matcher.matches()) {
|
||||
|
|
|
@ -73,9 +73,7 @@ public class Version implements Comparable<Version> {
|
|||
public static Version valueOf(String value) {
|
||||
Matcher matcher = SEMVER_PATTERN.matcher(value);
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal version format"
|
||||
);
|
||||
throw new IllegalArgumentException("Illegal version format");
|
||||
}
|
||||
|
||||
NormalVersion normal = new NormalVersion(
|
||||
|
@ -188,7 +186,11 @@ public class Version implements Comparable<Version> {
|
|||
if (preRelease != null && other.preRelease != null) {
|
||||
result = preRelease.compareTo(other.preRelease);
|
||||
} 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;
|
||||
}
|
||||
|
@ -198,7 +200,11 @@ public class Version implements Comparable<Version> {
|
|||
if (build != null && other.build != null) {
|
||||
result = build.compareTo(other.build);
|
||||
} 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user