@groovy.transform.CompileStatic @groovy.transform.EqualsAndHashCode class Version
A class for comparing versions. A major parts of the logic in this class is based upon org.gradle.util.GradleVersion.
Modifiers | Name | Description |
---|---|---|
static class |
Version.ParseException |
|
static class |
Version.Parts |
Type | Name and description |
---|---|
static java.util.regex.Pattern |
EXTRAS_PARSER Extract bits out of the extra section. |
static java.util.regex.Pattern |
EXTRAS_WITH_SNAPSHOT_PARSER Patterns for identifying extras which also contains a SNAPSHOT. |
static java.util.regex.Pattern |
INITIAL_PARSER The initial parse is used to extract major, minor, patch and any extras. |
static java.util.regex.Pattern |
SNAPSHOT_PARSER Regex to identify extras as SNAPSHOT. |
boolean |
alpha Whether the version is an alpha. |
Integer |
alphaSequence |
boolean |
beta Whether the version is a beta. |
Integer |
betaSequence |
int |
major The major version of the version. |
boolean |
milestone Whether the version is a milestone. |
Integer |
milestoneSequence |
int |
minor The minor part of the version. |
Integer |
patch The patch part of the version. |
boolean |
rc Whether the version is an RC. |
Integer |
rcSequence |
String |
snapShotSequence |
boolean |
snapshot Whether the version is a snapshot. |
String |
version The version the class was created with |
Constructor and description |
---|
protected Version
(String ver, Version.Parts parts) Creates an instance of a Version object. |
Type Params | Return Type | Name and description |
---|---|---|
|
int |
compareTo(Version rhs) Compares this object with the specified object for order. |
|
static Version.Parts |
defaultParser(String ver) The default parser will look for something that roughly matches the following regex: {@code \d+\. |
|
static Version |
of(String ver) Creates a new version instance from a parse-able string. |
|
static Version |
of(String ver, java.util.function.Function<String, Parts> parser) Creates a new version instance from a parse-able string using a custom parser |
Extract bits out of the extra section.
Patterns for identifying extras which also contains a SNAPSHOT.
The initial parse is used to extract major, minor, patch and any extras.
Regex to identify extras as SNAPSHOT.
Whether the version is an alpha.
Whether the version is a beta.
The major version of the version.
Never null
.
Whether the version is a milestone.
The minor part of the version.
Never null
.
The patch part of the version.
Can be null
.
Whether the version is an RC.
Whether the version is a snapshot.
The version the class was created with
Creates an instance of a Version object.
ver
- Version string that was usedparts
- Decomposed partsCompares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementor must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.
rhs
- the object to be compared. The default parser will look for something that roughly matches the
following regex: \d+\.\d+(\.\d+)?(-(alpha|beta|rc)\.\d+)?(-(SNAPSHOT|\d{14
))?}.
ver
- Version to parseCreates a new version instance from a parse-able string.
ver
- Version string to parse.Creates a new version instance from a parse-able string using a custom parser
ver
- Version string to parse.parser
- Custom parser to useGroovy Documentation