Class Version
- All Implemented Interfaces:
Comparable<Version>
NodeJSVersion identifiers have tree components.
- Major version. A non-negative integer.
- Minor version. A non-negative integer.
- Micro version. A non-negative integer.
NodeJSVersion objects are immutable.
- Author:
- Nikolas Falco
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares thisNodeJSVersionobject to anotherNodeJSVersion.booleanCompares thisNodeJSVersionobject 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.inthashCode()Returns a hash code value for the object.static VersionparseVersion(String version) Parses a version identifier from the specified string.toString()Returns the string representation of this version identifier.
-
Field Details
-
emptyVersion
The empty version "0.0.0".
-
-
Constructor Details
-
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 identifier.minor- Minor component of the version identifier.micro- Micro component of the version identifier.- Throws:
IllegalArgumentException- If the numerical components are negative.
-
Version
Creates a version identifier from the specified string.NodeJSVersion string grammar:
version ::= major('.'minor('.'micro)?)? major ::= digit+ minor ::= digit+ micro ::= digit+ digit ::= [0..9]- Parameters:
version- String representation of the version identifier. There must be no whitespace in the argument.- Throws:
IllegalArgumentException- Ifversionis improperly formatted.
-
-
Method Details
-
parseVersion
Parses a version identifier from the specified string.See
NodeJSVersion(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
NodeJSVersionobject representing the version identifier. Ifversionisnullor the empty string thenemptyVersionwill 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.
-
toString
Returns the string representation of this version identifier.The format of the version string will be
major.minor.micro. -
hashCode
public int hashCode()Returns a hash code value for the object. -
equals
Compares thisNodeJSVersionobject to another object.A version is considered to be equal to another version if the major, minor and micro components are equal.
-
compareTo
Compares thisNodeJSVersionobject to anotherNodeJSVersion.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.
A version is considered to be equal to another version if the major, minor and micro components are equal.
- Specified by:
compareToin interfaceComparable<Version>- Parameters:
other- TheNodeJSVersionobject to be compared.- Returns:
- A negative integer, zero, or a positive integer if this version
is less than, equal to, or greater than the specified
NodeJSVersionobject. - Throws:
ClassCastException- If the specified object is not aNodeJSVersionobject.
-