Class VersionNumber

  • All Implemented Interfaces:
    Comparable<VersionNumber>

    public class VersionNumber
    extends Object
    implements Comparable<VersionNumber>
    A version number in the form X.Y.Z with optional pre-release labels and build metadata.

    Version numbers compare the usual way, the major number (X) is compared first, then the minor one (Y) and then the patch level one (Z). Lastly, versions with pre-release sorts before the versions that don't have one, and labels are sorted alphabetically if necessary. Build metadata are ignored for sorting versions. The versions supported loosely correspond to what http://semver.org/ defines though it does not adhere to it strictly.

    • Method Detail

      • parse

        public static VersionNumber parse​(String version)
        Parse a version from a string.

        The version string should have primarily the form X.Y.Z to which can be appended one or more pre-release label after dashes (2.0.1-beta1, 2.1.4-rc1-SNAPSHOT) and an optional build label (2.1.0-beta1+a20ba.sha). Out of convenience, the "patch" version number, Z, can be omitted, in which case it is assumed to be 0.

        Parameters:
        version - the string to parse
        Returns:
        the parsed version number.
        Throws:
        IllegalArgumentException - if the provided string does not represent a valid version.
      • getMajor

        public int getMajor()
        The major version number.
        Returns:
        the major version number, i.e. X in X.Y.Z.
      • getMinor

        public int getMinor()
        The minor version number.
        Returns:
        the minor version number, i.e. Y in X.Y.Z.
      • getPatch

        public int getPatch()
        The patch version number.
        Returns:
        the patch version number, i.e. Z in X.Y.Z.
      • getDSEPatch

        public int getDSEPatch()
        The DSE patch version number (will only be present for version of Cassandra in DSE).

        DataStax Entreprise (DSE) adds a fourth number to the version number to track potential hot fixes and/or DSE specific patches that may have been applied to the Cassandra version. In that case, this method return that fourth number.

        Returns:
        the DSE patch version number, i.e. D in X.Y.Z.D, or -1 if the version number is not from DSE.
      • getPreReleaseLabels

        public List<String> getPreReleaseLabels()
        The pre-release labels if relevant, i.e. label1 and label2 in X.Y.Z-label1-lable2.
        Returns:
        the pre-releases labels. The return list will be null if the version number doesn't have one.
      • getBuildLabel

        public String getBuildLabel()
        The build label if there is one.
        Returns:
        the build label or null if the version number doesn't have one.
      • nextStable

        public VersionNumber nextStable()
        The next stable version, i.e. the version stripped of its pre-release labels and build metadata.

        This is mostly used during our development stage, where we test the driver against pre-release versions of Cassandra like 2.1.0-rc7-SNAPSHOT, but need to compare to the stable version 2.1.0 when testing for native protocol compatibility, etc.

        Returns:
        the next stable version.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object