Class Version

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

    public class Version
    extends AbstractVersion
    implements java.lang.Comparable<Version>, java.io.Serializable
    The version
    See Also:
    Serialized Form
    • Constructor Detail

      • Version

        public Version​(int majorNumber,
                       int minorNumber,
                       int patchNumber)
        Constructor
        Parameters:
        majorNumber - the major number
        minorNumber - the minor number
        patchNumber - the patch number
      • Version

        public Version​(java.lang.String version)
        Constructor
        Parameters:
        version - the version
      • Version

        public Version​(java.lang.String version,
                       java.lang.String sep)
        Constructor
        Parameters:
        version - the version
        sep - the separator
      • Version

        public Version​(java.lang.String version,
                       VersionType versionType,
                       java.lang.String sep)
        Constructor
        Parameters:
        version - the version
        versionType - the version type
        sep - the separator
    • Method Detail

      • getMajor

        public Version.VersionNumberElement getMajor()
        Get the major part of the version. Example: for "1.2.3" = 1
        Returns:
        the major part of the version
      • getMajorNumber

        public int getMajorNumber()
        Get the major part of the version. Example: for "1.2.3" = 1
        Returns:
        the major part of the version
      • getMajorSuffix

        public java.lang.String getMajorSuffix()
        Gets the additional minor suffix
        Returns:
        the additional minor suffix
      • setMajorNumber

        public Version setMajorNumber​(java.lang.String majorNumber)
        Sets the major number
        Parameters:
        majorNumber - the major number to set
        Returns:
        the new version
      • getMinor

        public Version.VersionNumberElement getMinor()
        Get the minor part of the version. Example: for "1.2.3" = 2
        Returns:
        the minor part of the version
      • getMinorNumber

        public int getMinorNumber()
        Get the minor part of the version. Example: for "1.2.3" = 2
        Returns:
        the minor part of the version
      • getMinorSuffix

        public java.lang.String getMinorSuffix()
        Gets the additional minor suffix
        Returns:
        the additional minor suffix
      • setMinorNumber

        public Version setMinorNumber​(java.lang.String minorNumber)
        Sets the minor number
        Parameters:
        minorNumber - the minor number to set
        Returns:
        the new version
      • getPatch

        public Version.VersionNumberElement getPatch()
        Get the patch part of the version. Example: for "1.2.3" = 3
        Returns:
        the patch part of the version
      • getPatchNumber

        public int getPatchNumber()
        Get the patch part of the version. Example: for "1.2.3" = 3
        Returns:
        the patch part of the version
      • getPatchSuffix

        public java.lang.String getPatchSuffix()
        Gets the additional patch suffix
        Returns:
        the additional patch suffix
      • setPatchNumber

        public Version setPatchNumber​(java.lang.String patchNumber)
        Sets the patch number
        Parameters:
        patchNumber - the patch number to set
        Returns:
        the new version
      • isGreaterThan

        public boolean isGreaterThan​(java.lang.String version)
        Checks if the version is greater than another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is greater than the provided version
      • isGreaterThan

        public boolean isGreaterThan​(Version version)
        Checks if the version is greater than another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is greater than the provided version
      • isGreaterThanOrEqualTo

        public boolean isGreaterThanOrEqualTo​(java.lang.String version)
        Checks if the version is greater than or equal to another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is greater than or equal to the provided version
      • isGreaterThanOrEqualTo

        public boolean isGreaterThanOrEqualTo​(Version version)
        Checks if the version is greater than or equal to another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is greater than or equal to the provided version
      • isLowerThan

        public boolean isLowerThan​(java.lang.String version)
        Checks if the version is lower than another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is lower than the provided version
      • isLowerThan

        public boolean isLowerThan​(Version version)
        Checks if the version is lower than another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is lower than the provided version
      • isLowerThanOrEqualTo

        public boolean isLowerThanOrEqualTo​(java.lang.String version)
        Checks if the version is lower than or equal to another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is lower than or equal to the provided version
      • isLowerThanOrEqualTo

        public boolean isLowerThanOrEqualTo​(Version version)
        Checks if the version is lower than or equal to another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version is lower than or equal to the provided version
      • isEqualTo

        public boolean isEqualTo​(java.lang.String version)
        Checks if the version equals another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version equals the provided version
      • isEqualTo

        public boolean isEqualTo​(Version version)
        Checks if the version equals another version
        Parameters:
        version - the version to compare
        Returns:
        true if the current version equals the provided version
      • isStable

        public boolean isStable()
        Determines if the current version is stable or not. Stable version have a major version number strictly positive and no suffix tokens.
        Returns:
        true if the current version is stable
      • diff

        public VersionDiff diff​(java.lang.String version)
        Returns the greatest difference between 2 versions. For example, if the current version is "1.2.3" and compared version is "1.3.0", the biggest difference is the 'MINOR' number.
        Parameters:
        version - the version to compare
        Returns:
        the greatest difference
      • diff

        public VersionDiff diff​(Version version)
        Returns the greatest difference between 2 versions. For example, if the current version is "1.2.3" and compared version is "1.3.0", the biggest difference is the 'MINOR' number.
        Parameters:
        version - the version to compare
        Returns:
        the greatest difference
      • withIncrementMajor

        public Version withIncrementMajor()
        Get version with incremented major version
        Returns:
        the version
      • withIncrementMajor

        public Version withIncrementMajor​(int increment)
        Get version with incremented major version
        Parameters:
        increment - the increment amount
        Returns:
        the version
      • withIncrementMinor

        public Version withIncrementMinor()
        Get version with incremented minor version
        Returns:
        the version
      • withIncrementMinor

        public Version withIncrementMinor​(int increment)
        Get version with incremented minor version
        Parameters:
        increment - the increment amount
        Returns:
        the version
      • withIncrementPatch

        public Version withIncrementPatch()
        Get version with incremented patch version
        Returns:
        the version
      • withIncrementPatch

        public Version withIncrementPatch​(int increment)
        Get version with incremented patch version
        Parameters:
        increment - the increment amount
        Returns:
        the version
      • withClearedSuffix

        public Version withClearedSuffix()
        Get the version with cleared suffix
        Returns:
        the version
      • nextMajor

        public Version nextMajor()
        Get the next major version
        Returns:
        the next major version
      • nextMinor

        public Version nextMinor()
        Get the next minor version
        Returns:
        the next minor version
      • nextPatch

        public Version nextPatch()
        Get the next patch version
        Returns:
        the next patch version
      • compareTo

        public int compareTo​(Version o)
        Specified by:
        compareTo in interface java.lang.Comparable<Version>
        See Also:
        Comparable.compareTo(java.lang.Object)
      • withIncrement

        protected Version withIncrement​(int majorInc,
                                        int minorInc,
                                        int patchInc,
                                        boolean clearSuffix)
        Get version with incremented numbers
        Parameters:
        majorInc - the major increment
        minorInc - the minor increment
        patchInc - the patch increment
        clearSuffix - true to clear the suffix
        Returns:
        the version
      • with

        protected Version with​(java.lang.String major,
                               java.lang.String minor,
                               java.lang.String patch)
        Prepare a version
        Parameters:
        major - the major
        minor - the minor
        patch - the patch
        Returns:
        the version
      • create

        protected Version create​(VersionType versionType,
                                 java.lang.String major,
                                 java.lang.String minor,
                                 java.lang.String patch)
        Prepare a version
        Parameters:
        versionType - the version type
        major - the major
        minor - the minor
        patch - the patch
        Returns:
        the version
      • compareMajorVersion

        protected int compareMajorVersion​(Version v)
        Compares the major version number
        Parameters:
        v - the version to compare
        Returns:
        0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
      • compareMinorVersion

        protected int compareMinorVersion​(Version v)
        Compares the minor version number
        Parameters:
        v - the version to compare
        Returns:
        0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
      • comparePatchVersion

        protected int comparePatchVersion​(Version v)
        Compares the patch version number
        Parameters:
        v - the version to compare
        Returns:
        0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
      • compareValues

        protected int compareValues​(int v1,
                                    int v2)
        Compares two integer values
        Parameters:
        v1 - the version to compare
        v2 - the version to compare
        Returns:
        0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
      • compareValues

        protected int compareValues​(java.lang.String v1,
                                    java.lang.String v2)
        Compares two integer values
        Parameters:
        v1 - the version to compare
        v2 - the version to compare
        Returns:
        0< if the object is less; 0 if the objects are equal; >0 if the object is bigger
      • splitNumberAndSuffix

        protected Version.VersionNumberElement splitNumberAndSuffix​(java.lang.String[] data,
                                                                    int idx,
                                                                    java.lang.String errorMessageDetail)
        Splits the given data into number and suffix
        Parameters:
        data - the data to split up
        idx - the index
        errorMessageDetail - the error message detail
        Returns:
        the splitted data
      • buildPatch

        protected java.lang.String[] buildPatch​(java.lang.String[] mainTokens,
                                                int idx,
                                                java.lang.String sep)
        Build the patch
        Parameters:
        mainTokens - the main tokens
        idx - the index
        sep - the separator
        Returns:
        the main tokens
      • toVersion

        protected static java.lang.String toVersion​(int major,
                                                    int minor,
                                                    int patch,
                                                    java.lang.String separator)
        Create a version
        Parameters:
        major - the major number
        minor - the minor number
        patch - the patch number
        separator - the separator
        Returns:
        the version string