Class Version

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Version>

    public final class Version
    extends java.lang.Object
    implements java.lang.Comparable<Version>, java.io.Serializable
    A version for a module. Versions are series of letters and digits, optionally divided by separator characters, which include ., -, +, and _. The transition between letter and digit (or vice-versa) is also considered to be an invisible separator.

    Versions may be compared, sorted, used as hash keys, and iterated.

    Author:
    David M. Lloyd
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Version.Iterator
      An iterator over the parts of a version.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Version that)
      Compares this module version to another module version.
      boolean equals​(java.lang.Object ob)
      Tests this module version for equality with the given object.
      int hashCode()
      Computes a hash code for this module version.
      Version.Iterator iterator()
      Construct a new iterator over the parts of this version string.
      static Version parse​(java.lang.String v)
      Parses the given string as a version string.
      java.lang.String toString()
      Returns the normalized string representation of this version.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • parse

        public static Version parse​(java.lang.String v)
        Parses the given string as a version string.
        Parameters:
        v - The string to parse
        Returns:
        The resulting Version
        Throws:
        java.lang.IllegalArgumentException - If v is null, an empty string, or cannot be parsed as a version string
      • iterator

        public Version.Iterator iterator()
        Construct a new iterator over the parts of this version string.
        Returns:
        the iterator
      • compareTo

        public int compareTo​(Version that)
        Compares this module version to another module version. Module versions are compared as described in the class description.
        Specified by:
        compareTo in interface java.lang.Comparable<Version>
        Parameters:
        that - The module version to compare
        Returns:
        A negative integer, zero, or a positive integer as this module version is less than, equal to, or greater than the given module version
      • equals

        public boolean equals​(java.lang.Object ob)
        Tests this module version for equality with the given object.

        If the given object is not a Version then this method returns false. Two module version are equal if their corresponding components are equal.

        This method satisfies the general contract of the Object.equals method.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        ob - the object to which this object is to be compared
        Returns:
        true if, and only if, the given object is a module reference that is equal to this module reference
      • hashCode

        public int hashCode()
        Computes a hash code for this module version.

        The hash code is based upon the components of the version and satisfies the general contract of the Object.hashCode method.

        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash-code value for this module version
      • toString

        public java.lang.String toString()
        Returns the normalized string representation of this version.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The normalized string.