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 protected
ClickHouseVersion(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 boolean
belongsTo(ClickHouseVersion version)
Checks if the version belongs to the given series.boolean
belongsTo(String version)
Checks if the version belongs to the given series.boolean
check(String range)
Checks if the version is valid according to the given maven-like version range.static boolean
check(String version, String range)
Checks if the version is valid according to the given maven-like version range.static int
compare(String fromVersion, String toVersion)
Compares two versions part by part, which is not semantical.int
compareTo(ClickHouseVersion o)
protected int
compareTo(ClickHouseVersion o, boolean sameSeriesComparison)
Compares current version and the given one.boolean
equals(Object obj)
int
getBuilderNumber()
Gets build number.int
getFeatureRelease()
Gets feature release.int
getMaintenanceRelease()
Gets maintenance release.int
getMajorVersion()
Gets major version in semantic versioning.int
getMinorVersion()
Gets minor version in semantic versioning.int
getPatch()
Gets patch in semantic versioning.int
getYear()
Gets year number.int
hashCode()
boolean
isLatest()
Checks if the version is latest or not.boolean
isNewerOrEqualTo(ClickHouseVersion version)
Checks if the version is newer or equal to the given one.boolean
isNewerOrEqualTo(String version)
Checks if the version is newer or equal to the given one.boolean
isNewerThan(ClickHouseVersion version)
Checks if the version is newer than the given one.boolean
isNewerThan(String version)
Checks if the version is newer than the given one.boolean
isOlderOrEqualTo(ClickHouseVersion version)
Checks if the version is older or equal to the given one.boolean
isOlderOrEqualTo(String version)
Checks if the version is older or equal to the given one.boolean
isOlderThan(ClickHouseVersion version)
Checks if the version is older than the given one.boolean
isOlderThan(String version)
Checks if the version is older than the given one.static ClickHouseVersion
of(int yearOrMajor, int... more)
Creates a new version object using given numbers.static ClickHouseVersion
of(String version)
Parses the given string to extract version.protected static ClickHouseVersion
parseVersion(String version)
Parses given version without caching.String
toString()
-
-
-
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 as0.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
- versiontoVersion
- version to compare with- Returns:
- positive integer if
fromVersion
is newer thantoVersion
; zero if they're equal; or negative integer iffromVersion
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 as0.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 vrsionmore
- 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 as0.0.0.0
- Returns:
- parsed version
-
compareTo
protected int compareTo(ClickHouseVersion o, boolean sameSeriesComparison)
Compares current version and the given one. WhenincludeEmptyParts
istrue
, 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:
compareTo
in interfaceComparable<ClickHouseVersion>
-
-