Package jetbrains.buildServer.util
Class Version
- java.lang.Object
-
- jetbrains.buildServer.util.Version
-
- All Implemented Interfaces:
Comparable<Version>
public final class Version extends Object implements Comparable<Version>
Version of a product. Holds one or more numbers of the version. Value object (immutable). Comparable. Useful. Quadratisch. Praktisch. Gut.How to use:
Version v = Version.of(System.getProperty("java.runtime.version")); if (v.compareTo(Version.of(1,7)) < 0) { ... }Note: the tailing zeros are not meaningful, in other words, versions 1.2.3 and 1.2.3.0.0 are equal.
- Since:
- 8.1.3.
- Author:
- Leonid Bushuev from JetBrains
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(int... that)Compares to the specified version.intcompareTo(Version that)Compares to the specified version.booleanequals(Object o)intget(int index)The i-th element, if specified, or 0 if not.inthashCode()booleanisNotZero()The version is not zero.booleanisOrGreater(int... than)Checks whether the version is equal to or gerater than the specified version.static Versionof(Integer... elements)Trivial constructor - makes the version by it elements.static Versionof(String string)Parse the version string.intsize()StringtoString()Comma delimited version string.StringtoString(int minimumElements, int maximumElements)Comma delimited version string.
-
-
-
Field Detail
-
ZERO
public static final Version ZERO
-
-
Method Detail
-
of
public static Version of(@NotNull String string)
Parse the version string.- Parameters:
string-- Returns:
-
of
public static Version of(@NotNull Integer... elements)
Trivial constructor - makes the version by it elements.- Parameters:
elements- elements, must contain at least one element.- Returns:
- the version.
-
get
public int get(int index)
The i-th element, if specified, or 0 if not.So, for version 1.2.3 first three elements will be 1,2,3, and the rest elements will be 0.
In other words, versions 1.2.3.0.0 and 1.2.3 are equal.
- Parameters:
index- element index (started with zero).- Returns:
- the i-th element.
-
size
public int size()
-
isNotZero
public boolean isNotZero()
The version is not zero. Zero in most cases version is unknown.- Returns:
- true if not zero, false if zero.
- Since:
- 9.0.1
-
compareTo
public int compareTo(@NotNull Version that)Compares to the specified version.- Specified by:
compareToin interfaceComparable<Version>- Parameters:
that- version to compare with.- Returns:
- +1 when this version is greater than the specified, -1 when this version is less than the specified, 0 when they equal.
-
compareTo
public int compareTo(int... that)
Compares to the specified version.- Parameters:
that- version to compare with.- Returns:
- +1 when this version is greater than the specified, -1 when this version is less than the specified, 0 when they equal.
-
isOrGreater
public boolean isOrGreater(int... than)
Checks whether the version is equal to or gerater than the specified version.- Parameters:
than- v ersion to compare.- Returns:
- true if equals to or is greater than.
-
toString
@NotNull public String toString()
Comma delimited version string.- Overrides:
toStringin classObject- Returns:
- dot delimited version string.
- See Also:
toString(int, int)
-
toString
@NotNull public String toString(int minimumElements, int maximumElements)
Comma delimited version string.- Parameters:
minimumElements- minimum elements to use.maximumElements- maximum elements to use.- Returns:
- dot delimited version string.
-
-