Class Version
- All Implemented Interfaces:
Comparable<Version>
Version identifiers have four components.
- Major version. A non-negative integer.
- Minor version. A non-negative integer.
- Micro version. A non-negative integer.
- Qualifier. An ascii text string. See
Version(String)
for the format of the qualifier string.
Unspecified version component is equivalent to 0 (or the empty string for qualifier).
Version
objects are immutable.
- Author:
- bratseth
-
Field Summary
-
Constructor Summary
ConstructorDescriptionVersion()
Creates an empty versionVersion
(int major) Creates a version identifier from the specified numerical components.Version
(int major, int minor) Creates a version identifier from the specified numerical components.Version
(int major, int minor, int micro) Creates a version identifier from the specified numerical components.Creates a version identifier from the specified components.Version
(com.yahoo.text.Utf8Array versionString) Creates a version identifier from the specified string.Creates a version identifier from the specified string. -
Method Summary
Modifier and TypeMethodDescriptionint
Compares thisVersion
object to another version.boolean
Compares thisVersion
to another.static Version
fromString
(String versionString) Returns new Version(versionString), or Version.emptyVersion if the input string is null or ""int
getMajor()
Returns the major component of this version, or 0 if not specifiedint
getMicro()
Returns the micro component of this version, or 0 if not specifiedint
getMinor()
Returns the minor component of this version, or 0 if not specifiedReturns the qualifier component of this version, or "" if not specifiedint
hashCode()
boolean
Returns whether this version number is strictly higher than the given version.boolean
Returns whether this version number is strictly lower than the given version.boolean
isEmpty()
Returns whether this equals the empty versionReturns the string representation of this version identifier as major.minor.micro.qualifier, omitting .qualifier if qualifier empty or unspecifiedCreates a version specification that only matches this versiontoString()
Returns the string representation of this version identifier as major.minor.micro.qualifier, omitting the remaining parts after reaching the first unspecified component.com.yahoo.text.Utf8Array
toUtf8()
withQualifier
(String qualifier)
-
Field Details
-
emptyVersion
The empty version
-
-
Constructor Details
-
Version
public Version()Creates an empty version -
Version
public Version(int major) Creates a version identifier from the specified numerical components.- Parameters:
major
- major component of the version identifier- Throws:
IllegalArgumentException
- If the numerical components are negative.
-
Version
public Version(int major, int minor) Creates a version identifier from the specified numerical components.- Parameters:
major
- major component of the version identifierminor
- minor component of the version identifier- Throws:
IllegalArgumentException
- If the numerical components are negative.
-
Version
public Version(int major, int minor, int micro) Creates a version identifier from the specified numerical components.- Parameters:
major
- major component of the version identifierminor
- minor component of the version identifiermicro
- micro component of the version identifier- Throws:
IllegalArgumentException
- If the numerical components are negative.
-
Version
Creates a version identifier from the specified components.- Parameters:
major
- major component of the version identifierminor
- minor component of the version identifiermicro
- micro component of the version identifierqualifier
- Qualifier component of the version identifier, or null if not specified- Throws:
IllegalArgumentException
- if the numerical components are negative the qualifier string contains non-word/digit-characters, or an earlier component is not specified but a later one is
-
Version
Creates a version identifier from the specified string.Version strings follows this grammar (same as Osgi versions):
version ::= major('.'minor('.'micro('.'qualifier)?)?)? major ::= digit+ minor ::= digit+ micro ::= digit+ qualifier ::= (alpha|digit|'_'|'-')+ digit ::= [0..9] alpha ::= [a..zA..Z]
- Parameters:
versionString
- String representation of the version identifier- Throws:
IllegalArgumentException
- Ifversion
is improperly formatted.
-
Version
public Version(com.yahoo.text.Utf8Array versionString) Creates a version identifier from the specified string.Version strings follows this grammar (same as Osgi versions):
version ::= major('.'minor('.'micro('.'qualifier)?)?)? major ::= digit+ minor ::= digit+ micro ::= digit+ qualifier ::= (alpha|digit|'_'|'-')+ digit ::= [0..9] alpha ::= [a..zA..Z]
- Parameters:
versionString
- String representation of the version identifier- Throws:
IllegalArgumentException
- Ifversion
is improperly formatted.
-
-
Method Details
-
fromString
Returns new Version(versionString), or Version.emptyVersion if the input string is null or "" -
withQualifier
-
toFullString
Returns the string representation of this version identifier as major.minor.micro.qualifier, omitting .qualifier if qualifier empty or unspecifiedThis string form is part of the API of Version and will never change.
-
getMajor
public int getMajor()Returns the major component of this version, or 0 if not specified -
getMinor
public int getMinor()Returns the minor component of this version, or 0 if not specified -
getMicro
public int getMicro()Returns the micro component of this version, or 0 if not specified -
getQualifier
Returns the qualifier component of this version, or "" if not specified -
toString
Returns the string representation of this version identifier as major.minor.micro.qualifier, omitting the remaining parts after reaching the first unspecified component. Unspecified version component is equivalent to 0 (or the empty string for qualifier).The string representation of a Version specified here is a part of the API and will never change.
-
toUtf8
public com.yahoo.text.Utf8Array toUtf8() -
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty()Returns whether this equals the empty version -
equals
Compares thisVersion
to another.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
Compares thisVersion
object to another version.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
).Unspecified numeric components are treated as 0, unspecified qualifier is treated as the empty string.
- Specified by:
compareTo
in interfaceComparable<Version>
- Parameters:
other
- theVersion
object 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
Version
object. - Throws:
ClassCastException
- if the specified object is not aVersion
.
-
isBefore
Returns whether this version number is strictly lower than the given version. This has the same semantics ascompareTo(com.yahoo.component.Version)
. -
isAfter
Returns whether this version number is strictly higher than the given version. This has the same semantics ascompareTo(com.yahoo.component.Version)
. -
toSpecification
Creates a version specification that only matches this version
-