Class Version
- java.lang.Object
-
- com.yahoo.component.Version
-
- All Implemented Interfaces:
java.lang.Comparable<Version>
public final class Version extends java.lang.Object implements java.lang.Comparable<Version>
A component versionVersion 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
Fields Modifier and Type Field Description static Version
emptyVersion
The empty version
-
Constructor Summary
Constructors Constructor Description Version()
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.Version(int major, int minor, int micro, java.lang.String qualifier)
Creates a version identifier from the specified components.Version(com.yahoo.text.Utf8Array versionString)
Creates a version identifier from the specified string.Version(java.lang.String versionString)
Creates a version identifier from the specified string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Version other)
Compares thisVersion
object to another version.boolean
equals(java.lang.Object object)
Compares thisVersion
to another.static Version
fromString(java.lang.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 specifiedjava.lang.String
getQualifier()
Returns the qualifier component of this version, or "" if not specifiedint
hashCode()
boolean
isAfter(Version other)
Returns whether this version number is strictly higher than the given version.boolean
isBefore(Version other)
Returns whether this version number is strictly lower than the given version.boolean
isEmpty()
Returns whether this equals the empty versionjava.lang.String
toFullString()
Returns the string representation of this version identifier as major.minor.micro.qualifier, omitting .qualifier if qualifier empty or unspecifiedVersionSpecification
toSpecification()
Creates a version specification that only matches this versionjava.lang.String
toString()
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()
-
-
-
Field Detail
-
emptyVersion
public static final Version emptyVersion
The empty version
-
-
Constructor Detail
-
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:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException
- If the numerical components are negative.
-
Version
public Version(int major, int minor, int micro, java.lang.String qualifier)
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:
java.lang.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
public Version(java.lang.String 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:
java.lang.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:
java.lang.IllegalArgumentException
- Ifversion
is improperly formatted.
-
-
Method Detail
-
fromString
public static Version fromString(java.lang.String versionString)
Returns new Version(versionString), or Version.emptyVersion if the input string is null or ""
-
toFullString
public java.lang.String 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
public java.lang.String getQualifier()
Returns the qualifier component of this version, or "" if not specified
-
toString
public java.lang.String 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.
- Overrides:
toString
in classjava.lang.Object
-
toUtf8
public com.yahoo.text.Utf8Array toUtf8()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isEmpty
public boolean isEmpty()
Returns whether this equals the empty version
-
equals
public boolean equals(java.lang.Object object)
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
).- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- TheVersion
object to be compared.- Returns:
true
ifobject
is aVersion
and is equal to this object;false
otherwise.
-
compareTo
public int compareTo(Version other)
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 interfacejava.lang.Comparable<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:
java.lang.ClassCastException
- if the specified object is not aVersion
.
-
isBefore
public boolean isBefore(Version other)
Returns whether this version number is strictly lower than the given version. This has the same semantics ascompareTo(com.yahoo.component.Version)
.
-
isAfter
public boolean isAfter(Version other)
Returns whether this version number is strictly higher than the given version. This has the same semantics ascompareTo(com.yahoo.component.Version)
.
-
toSpecification
public VersionSpecification toSpecification()
Creates a version specification that only matches this version
-
-