Class Version
- java.lang.Object
-
- org.jboss.hal.config.Version
-
- All Implemented Interfaces:
Comparable<Version>
public class Version extends Object implements Comparable<Version>
Version identifier for bundles and packages.Version identifiers have four components.
- Major version. A non-negative integer.
- Minor version. A non-negative integer.
- Micro version. A non-negative integer.
- Qualifier. A text string. See
Version(String)for the format of the qualifier string.
Versionobjects are immutable.
-
-
Field Summary
Fields Modifier and Type Field Description static VersionEMPTY_VERSIONThe empty version "0.0.0".
-
Constructor Summary
Constructors Constructor Description Version(int major, int minor, int micro)Creates a version identifier from the specified numerical components.Version(int major, int minor, int micro, String qualifier)Creates a version identifier from the specifed components.Version(String version)Created a version identifier from the specified string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Version other)Compares thisVersionobject to another object.booleanequals(Object object)Compares thisVersionobject to another object.intgetMajor()Returns the major component of this version identifier.intgetMicro()Returns the micro component of this version identifier.intgetMinor()Returns the minor component of this version identifier.StringgetQualifier()Returns the qualifier component of this version identifier.booleangreaterThan(Version other)Checks if this version is greater than the other version.booleangreaterThanOrEqualTo(Version other)Checks if this version is greater than or equal to the other version.inthashCode()Returns a hash code value for the object.booleanlessThan(Version other)Checks if this version is less than the other version.booleanlessThanOrEqualTo(Version other)Checks if this version is less than or equal to the other version.static VersionparseVersion(String version)Parses a version identifier from the specified string.StringtoString()Returns the string representation of this version identifier.
-
-
-
Field Detail
-
EMPTY_VERSION
public static final Version EMPTY_VERSION
The empty version "0.0.0". Equivalent to callingnew Version(0,0,0).
-
-
Constructor Detail
-
Version
public Version(int major, int minor, int micro)Creates a version identifier from the specified numerical components.The qualifier is set to the empty string.
- Parameters:
major- Major component of the version identifier.minor- Minor component of the version identifier.micro- Micro component of the version identifier.- Throws:
IllegalArgumentException- If the numerical components are negative.
-
Version
public Version(int major, int minor, int micro, String qualifier)Creates a version identifier from the specifed components.- Parameters:
major- Major component of the version identifier.minor- Minor component of the version identifier.micro- Micro component of the version identifier.qualifier- Qualifier component of the version identifier. Ifnullis specified, then the qualifier will be set to the empty string.- Throws:
IllegalArgumentException- If the numerical components are negative or the qualifier string is invalid.
-
Version
public Version(String version)
Created a version identifier from the specified string.Here is the grammar for version strings.
version ::= major('.'minor('.'micro('.'qualifier)?)?)? major ::= digit+ minor ::= digit+ micro ::= digit+ qualifier ::= (alpha|digit|'_'|'-')+ digit ::= [0..9] alpha ::= [a..zA..Z]There must be no whitespace in version.- Parameters:
version- String representation of the version identifier.- Throws:
IllegalArgumentException- Ifversionis improperly formatted.
-
-
Method Detail
-
parseVersion
public static Version parseVersion(String version)
Parses a version identifier from the specified string.See
Version(String)for the format of the version string.- Parameters:
version- String representation of the version identifier. Leading and trailing whitespace will be ignored.- Returns:
- A
Versionobject representing the version identifier. Ifversionisnullor the empty string thenEMPTY_VERSIONwill be returned. - Throws:
IllegalArgumentException- Ifversionis improperly formatted.
-
getMajor
public int getMajor()
Returns the major component of this version identifier.- Returns:
- The major component.
-
getMinor
public int getMinor()
Returns the minor component of this version identifier.- Returns:
- The minor component.
-
getMicro
public int getMicro()
Returns the micro component of this version identifier.- Returns:
- The micro component.
-
getQualifier
public String getQualifier()
Returns the qualifier component of this version identifier.- Returns:
- The qualifier component.
-
toString
public String toString()
Returns the string representation of this version identifier.The format of the version string will be
major.minor.microif qualifier is the empty string ormajor.minor.micro.qualifierotherwise.
-
hashCode
public int hashCode()
Returns a hash code value for the object.
-
equals
public boolean equals(Object object)
Compares thisVersionobject to another object.A version is considered to be equal to another version if the major, minor and micro components are equal and the qualifier component is equal (using
String.equals).
-
compareTo
public int compareTo(Version other)
Compares thisVersionobject to another object.A version is considered to be less than another version if its major component is less than the other version's major component, or the major components are equal and its minor component is less than the other version's minor component, or the major and minor components are equal and its micro component is less than the other version's micro component, or the major, minor and micro components are equal and it's qualifier component is less than the other version's qualifier component (using
String.compareTo).A version is considered to be equal to another version if the major, minor and micro components are equal and the qualifier component is equal (using
String.compareTo).- Specified by:
compareToin interfaceComparable<Version>- Parameters:
other- TheVersionobject to be compared.- Returns:
- A negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the
specified
Versionobject. - Throws:
ClassCastException- If the specified object is not aVersion.
-
greaterThan
public boolean greaterThan(Version other)
Checks if this version is greater than the other version.- Parameters:
other- the other version to compare to- Returns:
trueif this version is greater than the other version orfalseotherwise- See Also:
compareTo(Version other)
-
greaterThanOrEqualTo
public boolean greaterThanOrEqualTo(Version other)
Checks if this version is greater than or equal to the other version.- Parameters:
other- the other version to compare to- Returns:
trueif this version is greater than or equal to the other version orfalseotherwise- See Also:
compareTo(Version other)
-
lessThan
public boolean lessThan(Version other)
Checks if this version is less than the other version.- Parameters:
other- the other version to compare to- Returns:
trueif this version is less than the other version orfalseotherwise- See Also:
compareTo(Version other)
-
lessThanOrEqualTo
public boolean lessThanOrEqualTo(Version other)
Checks if this version is less than or equal to the other version.- Parameters:
other- the other version to compare to- Returns:
trueif this version is less than or equal to the other version orfalseotherwise- See Also:
compareTo(Version other)
-
-