public class Version extends Object implements 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.
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
STRICT_NUMERIC_VALIDATOR
A
Pattern that can validate a potential version String to ensure it contains a
valid set of numbers and '.''s
Version does not use this pattern, but it's handy for code that wants to ensure a
version string is valid before turning it into a Version. |
| Constructor and Description |
|---|
Version(Integer... elements)
Constructor for accepting a pre-parsed version.
|
Version(String version)
Constructor that parses a version string.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Version o)
Compare two versions to determine their ordering.
|
boolean |
equals(Object obj) |
int |
getMajor() |
int |
getMinor() |
int |
getPatch() |
List<Integer> |
getVersion()
Retrieves an immutable copy of the ordered list of version components.
|
int |
hashCode() |
String |
toString()
Returns a
String representation of this version, with the components separated by
dots. |
public static final Pattern STRICT_NUMERIC_VALIDATOR
Pattern that can validate a potential version String to ensure it contains a
valid set of numbers and '.''s
Version does not use this pattern, but it's handy for code that wants to ensure a
version string is valid before turning it into a Version.public Version(Integer... elements)
elements - the version elements, starting with the most significantpublic Version(String version)
version - the version stringpublic int compareTo(@Nonnull Version o)
equals.
Note: Returns from this method should not be assumed to be -1, 0 or 1. As per the
contract of Comparable, 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.
compareTo in interface Comparable<Version>public int getMajor()
getVersion().get(0)public int getMinor()
getVersion().get(1)public int getPatch()
getVersion().get(2)@Nonnull public List<Integer> getVersion()
major, minor and patch
versions.public String toString()
String representation of this version, 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".
Copyright © 2019 Atlassian. All rights reserved.