Add ProtocolVersion#betweenInclusive and ProtocolVersion#betweenExclusive (#3690)

This commit is contained in:
EnZaXD 2024-02-13 21:50:19 +01:00 committed by GitHub
parent 621c02f974
commit e449599ae7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 1 deletions

View File

@ -210,7 +210,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
this.versionType = versionType;
this.version = version;
this.snapshotVersion = snapshotVersion;
this.name = name;;
this.name = name;
Preconditions.checkArgument(!(isVersionWildcard() && versionRange == null), "A wildcard name must have a version range");
if (versionRange != null) {
@ -377,6 +377,29 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
return this.compareTo(other) <= 0;
}
/**
* Returns whether this protocol version is between the given protocol versions, inclusive.
*
* @param min minimum version
* @param max maximum version
* @return true if this protocol version is between the given protocol versions, inclusive
*/
public boolean betweenInclusive(final ProtocolVersion min, final ProtocolVersion max) {
return this.higherThanOrEquals(min) && this.lowerThanOrEquals(max);
}
/**
* Returns whether this protocol version is between the given protocol versions, exclusive.
*
* @param min minimum version
* @param max maximum version
* @return true if this protocol version is between the given protocol versions, exclusive
*/
public boolean betweenExclusive(final ProtocolVersion min, final ProtocolVersion max) {
return this.higherThan(min) && this.lowerThan(max);
}
/**
* Returns a custom comparator used to compare protocol versions.
* Must be overridden if the version type is {@link VersionType#SPECIAL}