Class Version
- All Implemented Interfaces:
Comparable<Version>
Versions
parsed by this class are always 0
-padded to at least three places. For
example, an input of "2"
will result in [2, 0, 0]
. More specific input, such as "1.7.9.5"
will result in longer lists; 3 places is a minimum, not a maximum.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
APattern
that can validate a potential version String to ensure it contains a valid set of numbers and '.''sVersion
does not use this pattern, but it's handy for code that wants to ensure a version string is valid before turning it into aVersion
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Compare two versions to determine their ordering.boolean
int
getMajor()
int
getMinor()
int
getPatch()
Retrieves an immutable copy of the ordered list of version components.int
hashCode()
toString()
Returns aString
representation of thisversion
, with the components separated by dots.
-
Field Details
-
STRICT_NUMERIC_VALIDATOR
APattern
that can validate a potential version String to ensure it contains a valid set of numbers and '.''sVersion
does not use this pattern, but it's handy for code that wants to ensure a version string is valid before turning it into aVersion
.
-
-
Constructor Details
-
Version
Constructor for accepting a pre-parsed version.- Parameters:
elements
- the version elements, starting with the most significant
-
Version
Constructor that parses a version string. Version parts are determined by splitting on [.-] characters. If a non- numerical value is found (e.g. 'RC4'), the rest of the version String is ignored. In other words '1.0.1-RC.2' is considered equal to '1.0.1'- Parameters:
version
- the version string
-
-
Method Details
-
compareTo
Compare two versions to determine their ordering. This class has a natural ordering that is consistent withequals
.Note: Returns from this method should not be assumed to be
-1
,0
or1
. As per the contract ofComparable
, they should be evaluated as negative,0
or positive. Implementations are free to use any positive or negative number they wish to indicate greater than and less than ordering.- Specified by:
compareTo
in interfaceComparable<Version>
-
equals
-
getMajor
public int getMajor()- Returns:
- the major version, e.g.
getVersion().get(0)
- Since:
- 5.14
-
getMinor
public int getMinor()- Returns:
- the minor version, e.g.
getVersion().get(1)
- Since:
- 5.14
-
getPatch
public int getPatch()- Returns:
- the patch version, e.g.
getVersion().get(2)
- Since:
- 5.14
-
getVersion
Retrieves an immutable copy of the ordered list of version components. The returned list is guaranteed to include at least 3 elements, formajor
,minor
andpatch
versions.- Returns:
- the version
-
hashCode
public int hashCode() -
toString
Returns aString
representation of thisversion
, with the components separated by dots.Note: For version strings which contain non-numerical, non-separator elements, the resulting representation will not match the input. For example, an initial version like
"1.7.9-RC1"
will result in"1.7.9"
for the return value here. Padding may also be applied, so an initial version of"2"
would be represented as"2.0.0"
.
-