java.lang.Object
org.jenkinsci.plugins.DependencyCheck.tools.Version
All Implemented Interfaces:
Comparable<Version>

public class Version extends Object implements Comparable<Version>
NodeJSVersion identifier.

NodeJSVersion identifiers have tree components.

  1. Major version. A non-negative integer.
  2. Minor version. A non-negative integer.
  3. Micro version. A non-negative integer.

NodeJSVersion objects are immutable.

Author:
Nikolas Falco
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Version
    The 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(String version)
    Creates a version identifier from the specified string.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares this NodeJSVersion object to another NodeJSVersion.
    boolean
    equals(Object object)
    Compares this NodeJSVersion object to another object.
    int
    Returns the major component of this version identifier.
    int
    Returns the micro component of this version identifier.
    int
    Returns the minor component of this version identifier.
    int
    Returns a hash code value for the object.
    static Version
    Parses a version identifier from the specified string.
    Returns the string representation of this version identifier.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • emptyVersion

      public static final Version 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

      public Version(String 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 - If version is improperly formatted.
  • Method Details

    • parseVersion

      public static Version parseVersion(String version)
      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 NodeJSVersion object representing the version identifier. If version is null or the empty string then emptyVersion will be returned.
      Throws:
      IllegalArgumentException - If version is 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

      public String toString()
      Returns the string representation of this version identifier.

      The format of the version string will be major.minor.micro.

      Overrides:
      toString in class Object
      Returns:
      The string representation of this version identifier.
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class Object
      Returns:
      An integer which is a hash code value for this object.
    • equals

      public boolean equals(Object object)
      Compares this NodeJSVersion object to another object.

      A version is considered to be equal to another version if the major, minor and micro components are equal.

      Overrides:
      equals in class Object
      Parameters:
      object - The NodeJSVersion object to be compared.
      Returns:
      true if object is a NodeJSVersion and is equal to this object; false otherwise.
    • compareTo

      public int compareTo(Version other)
      Compares this NodeJSVersion object to another NodeJSVersion.

      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:
      compareTo in interface Comparable<Version>
      Parameters:
      other - The NodeJSVersion object 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 NodeJSVersion object.
      Throws:
      ClassCastException - If the specified object is not a NodeJSVersion object.