public final class Version extends java.lang.Object implements java.lang.Comparable<Version>, java.io.Serializable
Constructor and Description |
---|
Version(int major,
int minor)
Create a new version.
|
Version(int major,
int minor,
int patch)
Create a new version.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Version other)
Compares to version numbers by their major and minor numbers.
|
boolean |
equals(java.lang.Object other)
Two version are equal if their major and minor version numbers are equal.
|
int |
getMajor()
Get major version number.
|
int |
getMinor()
Get minor version number.
|
int |
getPatch()
Get patch version number.
|
int |
hashCode() |
boolean |
isSatisfied(Version currentVersion,
Version compatibleVersion)
This method is used to check version compatibility in dependency management.
|
static Version |
parseVersion(java.lang.String s)
Parses a version from a string.
|
java.lang.String |
toString()
String representation: major.minor
|
public Version(int major, int minor)
major
- major version number.minor
- minor version number.java.lang.IllegalArgumentException
- if one of the version numbers is less than 0.public Version(int major, int minor, int patch)
major
- major version number.minor
- minor version number.patch
- patch version number.java.lang.IllegalArgumentException
- if one of the version numbers is less than 0.public static Version parseVersion(java.lang.String s) throws FormatException
FormatException
- if the string does not follow the expected pattern.public int compareTo(Version other)
compareTo
in interface java.lang.Comparable<Version>
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int getMajor()
public int getMinor()
public int getPatch()
public int hashCode()
hashCode
in class java.lang.Object
public boolean isSatisfied(Version currentVersion, Version compatibleVersion)
Consider the following situation and artefact A (the depender) depends on another artefact B (the dependee). A claims that it requires B in version 1.3. B states that it has version 1.5 but is downward compatible to version 1.1.
Using this method one can find out if the version provided by B satisfies A's requirement. It is satisfied iff
requiredVersion <= currentVersion && requiredVersion >= compatibleVersionwhere
requiredVersion
is this instance and the other two are
provided as method parameters.java.lang.IllegalArgumentException
- if compatibleVersion
is greater than
currentVersion
.public java.lang.String toString()
toString
in class java.lang.Object