Class VersionRangeParser


  • public class VersionRangeParser
    extends java.lang.Object
    A parser for strings representing a valid version range. Constructed with the string to parse, parse() must be invoked to parse the version range. This method returns the parsed version range.



    Version ranges must match the following specification:

    Version Ranges

    Ranges must fit into one of the two categories
    • Glob ranges
    • Version ranges

    Glob Ranges

    Glob ranges are represented as follows:
    1. +:
      This will match any version.
    2. major.+
      This matches any version which begins with major., meaning: any version between major.0.0 inclusively and {major+1}.0.0 exclusively.
      Example: The glob range 1.+ will match 1.0.0, 1.2.3, and 1.99.99 but not 2.0.0
    3. major.minor.+
      This matches any version which begins with major.minor, meaning: any version between major.minor.0 inclusively and major.{minor+1}.0 exclusively.
      Example: The glob range 1.2.+ will match 1.2.0, 1.2.3, and 1.2.99 but not 1.3.0
    4. major.minor.patch
      This matches only version major.minor.patch,
      Example: The glob range 1.2.+ will match 1.2.0, 1.2.3, and 1.2.99 but not 1.3.0

    Version Ranges

    Version ranges are represented by 2 versions surrounded by either brackets ("[]") or braces ("()").

    They must fit the following format:

    
          ("[" or "(")VersionOne,VersionTwo("]" or ")")
     
    Where VersionOne and VersionTwo are valid Versions.

    Note: Both VersionOne and VersionTwo are optional.

    Here is a list of example versions and what they match

    Table of version examples
    Version Description
    [1.0.0,2.0.0] all versions greater or equal to 1.0.0 and lower or equal to 2.0.0
    (1.0.0,2.0.0) all versions greater or equal to 1.0.0 and lower than 2.0.0
    (1.0.0,2.0.0] all versions greater than 1.0.0 and lower or equal to 2.0.0
    (1.0,2.0) all versions greater than 1.0.0 and lower than 2.0.0
    [1.0.0,) all versions greater or equal to 1.0.0
    (1.0.0,) all versions greater than 1.0.0
    (,2.0.0] all versions lower or equal to 2.0.0
    (,2.0) all versions lower than 2.0.0
    See Also:
    VersionParser
    • Constructor Summary

      Constructors 
      Constructor Description
      VersionRangeParser​(java.lang.String versionRangeString)
      Constructs a new version range parser with the provided string to parse.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @NotNull VersionRange parse()
      Parses the provided version range string to a VersionRange.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VersionRangeParser

        public VersionRangeParser​(java.lang.String versionRangeString)
        Constructs a new version range parser with the provided string to parse.
        Parameters:
        versionRangeString - The version range string to parse
    • Method Detail

      • parse

        @NotNull
        @Contract(value="-> new",
                  pure=true)
        public @NotNull VersionRange parse()
                                    throws ParseException
        Parses the provided version range string to a VersionRange.
        Returns:
        The Version parsed from the string this object was instantated with.
        Throws:
        ParseException - If an exception occurred during the parsing of the version. If taking user input, the message from this exception is highly useful and should be returned to the user.