All Implemented Interfaces:

public class ComparableVersion extends Object implements Comparable<ComparableVersion>
Generic implementation of version comparison.


  • mixing of '-' (hyphen) and '.' (dot) separators,
  • transition between characters and digits also constitutes a separator: 1.0alpha1 => [1, 0, alpha, 1]
  • unlimited number of version components,
  • version components in the text can be digits or strings,
  • strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. Well-known qualifiers (case insensitive) are:
    • alpha or a
    • beta or b
    • milestone or m
    • rc or cr
    • snapshot
    • (the empty string) or ga or final
    • sp
    Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive),
  • a hyphen usually precedes a qualifier, and is always less important than something preceded with a dot.
See Also:
  • Constructor Details

    • ComparableVersion

      public ComparableVersion(String version)
  • Method Details

    • parseVersion

      public final void parseVersion(String version)
    • compareTo

      public int compareTo(ComparableVersion o)
      Specified by:
      compareTo in interface Comparable<ComparableVersion>
    • toString

      public String toString()
      toString in class Object
    • getCanonical

      public String getCanonical()
    • equals

      public boolean equals(Object o)
      equals in class Object
    • hashCode

      public int hashCode()
      hashCode in class Object
    • main

      public static void main(String... args)
      Main to test version parsing and comparison.
      args - the version strings to parse and compare
    • getFirstString

      public String getFirstString()
      Returns the first string in this ComparableVersion. Usually this refers to the qualifier of the version.
      The first string, or null if not found
    • getFirstInteger

      public BigInteger getFirstInteger()
      Returns the first integer in this ComparableVersion. Usually this refers to the major version.
      The first integer, or null if not found