Package com.clickhouse.client
Class ClickHouseVersion
- java.lang.Object
-
- com.clickhouse.client.ClickHouseVersion
-
- All Implemented Interfaces:
Serializable,Comparable<ClickHouseVersion>
public final class ClickHouseVersion extends Object implements Comparable<ClickHouseVersion>, Serializable
Immutable ClickHouse version, which takes the formYear(Major).Feature(Minor).Maintenance(Patch).Build. Prefix like 'v' and suffix like '-[testing|stable|lts]' will be ignored in parsing and comparison.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedClickHouseVersion(boolean latest, int year, int feature, int maintenance, int build)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbelongsTo(ClickHouseVersion version)Checks if the version belongs to the given series.booleanbelongsTo(String version)Checks if the version belongs to the given series.booleancheck(String range)Checks if the version is valid according to the given maven-like version range.static booleancheck(String version, String range)Checks if the version is valid according to the given maven-like version range.static intcompare(String fromVersion, String toVersion)Compares two versions part by part, which is not semantical.intcompareTo(ClickHouseVersion o)protected intcompareTo(ClickHouseVersion o, boolean sameSeriesComparison)Compares current version and the given one.booleanequals(Object obj)intgetBuilderNumber()Gets build number.intgetFeatureRelease()Gets feature release.intgetMaintenanceRelease()Gets maintenance release.intgetMajorVersion()Gets major version in semantic versioning.intgetMinorVersion()Gets minor version in semantic versioning.intgetPatch()Gets patch in semantic versioning.intgetYear()Gets year number.inthashCode()booleanisLatest()Checks if the version is latest or not.booleanisNewerOrEqualTo(ClickHouseVersion version)Checks if the version is newer or equal to the given one.booleanisNewerOrEqualTo(String version)Checks if the version is newer or equal to the given one.booleanisNewerThan(ClickHouseVersion version)Checks if the version is newer than the given one.booleanisNewerThan(String version)Checks if the version is newer than the given one.booleanisOlderOrEqualTo(ClickHouseVersion version)Checks if the version is older or equal to the given one.booleanisOlderOrEqualTo(String version)Checks if the version is older or equal to the given one.booleanisOlderThan(ClickHouseVersion version)Checks if the version is older than the given one.booleanisOlderThan(String version)Checks if the version is older than the given one.static ClickHouseVersionof(String version)Parses the given string to extract version.protected static ClickHouseVersionparseVersion(String version)Parses given version without caching.StringtoString()
-
-
-
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.321.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 as0.0.0.0range- 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- versiontoVersion- version to compare with- Returns:
- positive integer if
fromVersionis newer thantoVersion; zero if they're equal; or negative integer iffromVersionis 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 as0.0.0.0- Returns:
- parsed version
-
parseVersion
protected static ClickHouseVersion parseVersion(String version)
Parses given version without caching.- Parameters:
version- version, null or empty string is treated as0.0.0.0- Returns:
- parsed version
-
compareTo
protected int compareTo(ClickHouseVersion o, boolean sameSeriesComparison)
Compares current version and the given one. WhenincludeEmptyPartsistrue, 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 comparedsameSeriesComparison- 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 as0.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 asgetYear().- Returns:
- major version
-
getMinorVersion
public int getMinorVersion()
Gets minor version in semantic versioning. Same asgetFeatureRelease().- Returns:
- minor version
-
getPatch
public int getPatch()
Gets patch in semantic versioning. Same agetMaintenanceRelease().- 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 ascompareTo(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 ascompareTo(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 ascompareTo(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 ascompareTo(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
-
compareTo
public int compareTo(ClickHouseVersion o)
- Specified by:
compareToin interfaceComparable<ClickHouseVersion>
-
-