Class ClickHouseVersion

    • Constructor Detail

      • ClickHouseVersion

        protected ClickHouseVersion​(boolean latest,
                                    int year,
                                    int feature,
                                    int maintenance,
                                    int build)
    • Method Detail

      • check

        public static boolean check​(String version,
                                    String range)
        Checks if the version is valid according to the given maven-like version range. For examples:
        • 21.3 21.3.x.x, short version of [21.3,21.4)
        • [21.3,21.4) 21.3.x.x (included) to 21.4.x.x (not included)
        • [21.3,21.4] 21.3.x.x to 21.4.x.x (both included)
        • [21.3,) 21.3.x.x or higher
        • (,21.3],[21.8,) to 21.3.x.x (included) and 21.8.x.x or higher
        Parameters:
        version - version, null is treated as 0.0.0.0
        range - maven-like version range, null or empty means always invalid
        Returns:
        true if the version is valid; false otherwise
      • compare

        public static int compare​(String fromVersion,
                                  String toVersion)
        Compares two versions part by part, which is not semantical. For example: compare("21.3.1", "21.3") > 0, because "21.3.1.0" is greater than "21.3.0.0". However, check("21.3.1", "(,21.3]") == true, since "21.3.1" is considered as part of "21.3" series.
        Parameters:
        fromVersion - version
        toVersion - version to compare with
        Returns:
        positive integer if fromVersion is newer than toVersion; zero if they're equal; or negative integer if fromVersion is older
      • of

        public static ClickHouseVersion of​(String version)
        Parses the given string to extract version. Behind the scene, cache is used to avoid unnecessary overhead.
        Parameters:
        version - version, null or empty string is treated as 0.0.0.0
        Returns:
        parsed version
      • of

        public static ClickHouseVersion of​(int yearOrMajor,
                                           int... more)
        Creates a new version object using given numbers.
        Parameters:
        yearOrMajor - year or major vrsion
        more - more version numbers if any
        Returns:
        version
      • parseVersion

        protected static ClickHouseVersion parseVersion​(String version)
        Parses given version without caching.
        Parameters:
        version - version, null or empty string is treated as 0.0.0.0
        Returns:
        parsed version
      • compareTo

        protected int compareTo​(ClickHouseVersion o,
                                boolean sameSeriesComparison)
        Compares current version and the given one. When includeEmptyParts is true, this method returns 0(instead of 1) when comparing '21.3.1.2' with '21.3', because they're in the same series of '21.3'.
        Parameters:
        o - the object to be compared
        sameSeriesComparison - whether compare if two version are in same series
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
      • belongsTo

        public boolean belongsTo​(ClickHouseVersion version)
        Checks if the version belongs to the given series. For example: 21.3.1.1 belongs to 21.3 series but not 21.4 or 21.3.2.
        Parameters:
        version - version series, null will be treated as 0.0.0.0
        Returns:
        true if the version belongs to the given series; false otherwise
      • belongsTo

        public boolean belongsTo​(String version)
        Checks if the version belongs to the given series. For example: 21.3.1.1 belongs to 21.3 series but not 21.4 or 21.3.2.
        Parameters:
        version - version series
        Returns:
        true if the version belongs to the given series; false otherwise
      • isLatest

        public boolean isLatest()
        Checks if the version is latest or not.
        Returns:
        true if it's latest; false otherwise
      • getYear

        public int getYear()
        Gets year number.
        Returns:
        year number
      • getFeatureRelease

        public int getFeatureRelease()
        Gets feature release.
        Returns:
        feature release
      • getMaintenanceRelease

        public int getMaintenanceRelease()
        Gets maintenance release.
        Returns:
        maintenance release
      • getBuilderNumber

        public int getBuilderNumber()
        Gets build number.
        Returns:
        build number
      • getMajorVersion

        public int getMajorVersion()
        Gets major version in semantic versioning. Same as getYear().
        Returns:
        major version
      • getMinorVersion

        public int getMinorVersion()
        Gets minor version in semantic versioning. Same as getFeatureRelease().
        Returns:
        minor version
      • getPatch

        public int getPatch()
        Gets patch in semantic versioning. Same a getMaintenanceRelease().
        Returns:
        patch
      • isNewerOrEqualTo

        public boolean isNewerOrEqualTo​(ClickHouseVersion version)
        Checks if the version is newer or equal to the given one. Pay attention that when comparing "21.3.1.1" to "21.3", compareTo(ClickHouseVersion) says the former is greater, but this method will return false(because 21.3.x.x still belongs to 21.3 series).
        Parameters:
        version - version to compare
        Returns:
        true if the version is newer or equal to the given one; false otherwise
      • isNewerOrEqualTo

        public boolean isNewerOrEqualTo​(String version)
        Checks if the version is newer or equal to the given one. Pay attention that when comparing "21.3.1.1" to "21.3", compareTo(ClickHouseVersion) says the former is greater, but this method will return false(because 21.3.x.x still belongs to 21.3 series).
        Parameters:
        version - version to compare
        Returns:
        true if the version is newer or equal to the given one; false otherwise
      • isNewerThan

        public boolean isNewerThan​(ClickHouseVersion version)
        Checks if the version is newer than the given one. Same as compareTo(version) > 0.
        Parameters:
        version - version to compare
        Returns:
        true if the version is newer than the given one; false otherwise
      • isNewerThan

        public boolean isNewerThan​(String version)
        Checks if the version is newer than the given one. Same as compareTo(version) > 0.
        Parameters:
        version - version to compare
        Returns:
        true if the version is newer than the given one; false otherwise
      • isOlderOrEqualTo

        public boolean isOlderOrEqualTo​(ClickHouseVersion version)
        Checks if the version is older or equal to the given one. Pay attention that when comparing "21.3.1.1" to "21.3", compareTo(ClickHouseVersion) says the former is greater, but this method will return true(because 21.3.x.x still belongs to 21.3 series).
        Parameters:
        version - version to compare
        Returns:
        true if the version is older or equal to the given one; false otherwise
      • isOlderOrEqualTo

        public boolean isOlderOrEqualTo​(String version)
        Checks if the version is older or equal to the given one. Pay attention that when comparing "21.3.1.1" to "21.3", compareTo(ClickHouseVersion) says the former is greater, but this method will return true(because 21.3.x.x still belongs to 21.3 series).
        Parameters:
        version - version to compare
        Returns:
        true if the version is older or equal to the given one; false otherwise
      • isOlderThan

        public boolean isOlderThan​(ClickHouseVersion version)
        Checks if the version is older than the given one. Same as compareTo(version) < 0.
        Parameters:
        version - version to compare
        Returns:
        true if the version is older than the given one; false otherwise
      • isOlderThan

        public boolean isOlderThan​(String version)
        Checks if the version is older than the given one. Same as compareTo(version) < 0.
        Parameters:
        version - version to compare
        Returns:
        true if the version is older than the given one; false otherwise
      • check

        public boolean check​(String range)
        Checks if the version is valid according to the given maven-like version range.
        Parameters:
        range - version range, null or empty string means always invalid
        Returns:
        true if the version is valid; false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object