Class VersibleParser

java.lang.Object
dev.gigaherz.versible.VersibleParser

public class VersibleParser extends Object
Utilities for parsing versions and ranges. This class cannot be instantiated.
  • Method Details

    • parseRange

      public static VersibleRange parseRange(String range)
      Parses a version range into an object that can test versions.

      Grammar

      
           <range> ::= <version>
                    |  <version> '.' '*'
                    |  <comparison-operator> <version>
                    |  <interval>
      
           <comparison-operator> ::= '>=' | '>' | '<=' | '<' | '='
      
           <interval>       ::= <left-interval> (<version> ',' <version>? | ',' <version>) <right-interval>
           <left-interval>  ::= '[' | '('
           <right-interval> ::= ']' | ')'
       

      Examples

           String      -> Parses into
          ------------------------------------
           1.*         -> [1.0,2.0)
           >1.0        -> (1.0,)
           1.0         -> [1.0,1.0]
           =1.0.1      -> [1.0.1,1.0.1]
           [1,2]       -> [1,2]
           (1.23,1.37) -> (1.23,1.37)
       
      Parameters:
      range - The string containing the range to be parsed.
      Returns:
      The range representing the given string.
      Throws:
      IllegalArgumentException - If the string cannot be converted into a valid range.
    • parseVersion

      @NotNull public static @NotNull VersibleVersion parseVersion(String version)
      Parses a version string into a comparable version object.

      Grammar

      
           <version> ::= <component-list> ( [+-] <component-list> )*
           <component-list> ::= <component> ('.'? <component>)*
           <component> ::= <number> | <word>
           <number> ::= {Digit}+
           <word> ::= {Letter}+
       

      Examples

           String      -> Parses into
          ------------------------------------
           1           -> [ 1 ]
           1.0         -> [ 1, 0 ]
           1.0-1       -> [ 1, 0, -, 1 ]
           1.0+2       -> [ 1, 0, +, 1 ]
           1.0.2a3     -> [ 1, 0, 2, a, 3 ]
           23w32a      -> [ 23, w, 32, a ]
       
      Parameters:
      version - The string containing the version to be parsed.
      Returns:
      The version representing the given string.
      Throws:
      IllegalArgumentException - If the string cannot be converted into a valid version.