Class VersionSpecification
- All Implemented Interfaces:
Comparable<VersionSpecification>
Version specifications 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.
A null version component means "unspecified", i.e any value of that component matches the specification
VersionSpecification
objects are immutable.
- Author:
- arnej27959, bratseth
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates an empty versionVersionSpecification
(Integer major) Creates a version specification from the specified numerical components.VersionSpecification
(Integer major, Integer minor) Creates a version specification from the specified numerical components.VersionSpecification
(Integer major, Integer minor, Integer micro) Creates a version specification from the specified numerical components.VersionSpecification
(Integer major, Integer minor, Integer micro, String qualifier) Creates a version specification from the specifed components.VersionSpecification
(String versionString) Creates a version specification from the specified string. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(VersionSpecification other) Compares thisVersionSpecification
object to another.boolean
Compares thisVersionSpecification
to another.static VersionSpecification
fromString
(String versionString) 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 specifiedReturns the specified major component, which may be nullReturns the specified micro component, which may be nullReturns the specified minor component, which may be nullReturns the specified qualifier component, which may be nullint
hashCode()
intersect
(VersionSpecification other) boolean
isEmpty()
check if the Version specification is equal to the empty spec ("match anything")Returns the lowest possible Version object that matches this specboolean
Returns true if the given version matches this specification.toString()
Returns the string representation of this version specification as major.minor.micro.qualifier, where trailing unspecified components are omitted
-
Field Details
-
emptyVersionSpecification
The empty version
-
-
Constructor Details
-
VersionSpecification
public VersionSpecification()Creates an empty version -
VersionSpecification
Creates a version specification from the specified numerical components.- Parameters:
major
- major component of the version specification, or null if not specified- Throws:
IllegalArgumentException
- If the numerical components are negative.
-
VersionSpecification
Creates a version specification from the specified numerical components.- Parameters:
major
- major component of the version specification, or null if not specifiedminor
- minor component of the version specification, or null if not specified- Throws:
IllegalArgumentException
- If the numerical components are negative.
-
VersionSpecification
Creates a version specification from the specified numerical components.- Parameters:
major
- major component of the version specification, or null if not specifiedminor
- minor component of the version specification, or null if not specifiedmicro
- micro component of the version specification, or null if not specified- Throws:
IllegalArgumentException
- If the numerical components are negative.
-
VersionSpecification
Creates a version specification from the specifed components.- Parameters:
major
- major component of the version specification, or null if not specifiedminor
- minor component of the version specification, or null if not specifiedmicro
- micro component of the version specification, or null if not specifiedqualifier
- Qualifier component of the version specification, 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
-
VersionSpecification
Creates a version specification from the specified string.VersionSpecification 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 specification- Throws:
IllegalArgumentException
- Ifversion
is improperly formatted.
-
-
Method Details
-
fromString
-
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 -
getSpecifiedMajor
Returns the specified major component, which may be null -
getSpecifiedMinor
Returns the specified minor component, which may be null -
getSpecifiedMicro
Returns the specified micro component, which may be null -
getSpecifiedQualifier
Returns the specified qualifier component, which may be null -
toString
Returns the string representation of this version specification as major.minor.micro.qualifier, where trailing unspecified components are omitted -
hashCode
public int hashCode() -
equals
Compares thisVersionSpecification
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
).Note that two versions are only equal if they are equally specified, use
matches(com.yahoo.component.Version)
to match a more specified version to a less specified. -
isEmpty
public boolean isEmpty()check if the Version specification is equal to the empty spec ("match anything") -
lowestMatchingVersion
Returns the lowest possible Version object that matches this spec -
matches
Returns true if the given version matches this specification. It matches if all the numeric components specified are the same as in the version, and both qualifiers are either null or set to the same value. I.e, a version which includes a qualifier will only match exactly and will never return true from a request for an unspecified qualifier. -
compareTo
Compares thisVersionSpecification
object to another.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<VersionSpecification>
- Parameters:
other
- theVersionSpecification
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
VersionSpecification
object. - Throws:
ClassCastException
- if the specified object is not aVersionSpecification
.
-
intersect
-