Package org.apache.hc.core5.http
Class ProtocolVersion
java.lang.Object
org.apache.hc.core5.http.ProtocolVersion
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
HttpVersion
Represents a protocol version. The "major.minor" numbering
scheme is used to indicate versions of the protocol.
This class defines a protocol version as a combination of
protocol name, major version number, and minor version number.
Note that equals(int, int)
and hashCode()
are defined as
final here, they cannot be overridden in derived classes.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
Major version number of the protocolprivate final int
Minor version number of the protocolprivate final String
Name of the protocol.private static final long
-
Constructor Summary
ConstructorsConstructorDescriptionProtocolVersion
(String protocol, int major, int minor) Create a protocol version designator. -
Method Summary
Modifier and TypeMethodDescriptionint
Compares this protocol version with another one.final boolean
equals
(int major, int minor) Checks whether this instance has the same major and minor version as the arguments.final boolean
Checks equality of this protocol version with an object.format()
Formats this protocol version as a string.final int
getMajor()
Returns the major version number of the protocol.final int
getMinor()
Returns the minor version number of the HTTP protocol.final String
Returns the name of the protocol.final boolean
greaterEquals
(ProtocolVersion version) Tests if this protocol version is greater or equal to the given one.final int
hashCode()
Obtains a hash code consistent withequals(int, int)
.boolean
isComparable
(ProtocolVersion that) Checks whether this protocol can be compared to another one.final boolean
lessEquals
(ProtocolVersion version) Tests if this protocol version is less or equal to the given one.toString()
Converts this protocol version to a string.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
protocol
Name of the protocol. -
major
private final int majorMajor version number of the protocol -
minor
private final int minorMinor version number of the protocol
-
-
Constructor Details
-
ProtocolVersion
Create a protocol version designator.- Parameters:
protocol
- the name of the protocol, for example "HTTP"major
- the major version number of the protocolminor
- the minor version number of the protocol
-
-
Method Details
-
getProtocol
Returns the name of the protocol.- Returns:
- the protocol name
-
getMajor
public final int getMajor()Returns the major version number of the protocol.- Returns:
- the major version number.
-
getMinor
public final int getMinor()Returns the minor version number of the HTTP protocol.- Returns:
- the minor version number.
-
hashCode
public final int hashCode()Obtains a hash code consistent withequals(int, int)
. -
equals
public final boolean equals(int major, int minor) Checks whether this instance has the same major and minor version as the arguments.- Parameters:
major
- the major version to check.minor
- the minor version to check.- Returns:
- whether this instance has the same major and minor version as the arguments.
- Since:
- 5.0
-
equals
Checks equality of this protocol version with an object. The object is equal if it is a protocol version with the same protocol name, major version number, and minor version number. The specific class of the object is not relevant, instances of derived classes with identical attributes are equal to instances of the base class and vice versa. -
format
Formats this protocol version as a string.- Returns:
- a protocol version string, like "HTTP/1.1"
- Since:
- 5.0
-
isComparable
Checks whether this protocol can be compared to another one. Only protocol versions with the same protocol name can becompared
.- Parameters:
that
- the protocol version to consider- Returns:
true
ifcompareToVersion
can be called with the argument,false
otherwise
-
compareToVersion
Compares this protocol version with another one. Only protocol versions with the same protocol name can be compared. This method does not define a total ordering, as it would be required forComparable
.- Parameters:
that
- the protocol version to compare with- Returns:
- a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the argument version.
- Throws:
IllegalArgumentException
- if the argument has a different protocol name than this object, or if the argument isnull
-
greaterEquals
Tests if this protocol version is greater or equal to the given one.- Parameters:
version
- the version against which to check this version- Returns:
true
if this protocol version iscomparable
to the argument andcompares
as greater or equal,false
otherwise
-
lessEquals
Tests if this protocol version is less or equal to the given one.- Parameters:
version
- the version against which to check this version- Returns:
true
if this protocol version iscomparable
to the argument andcompares
as less or equal,false
otherwise
-
toString
Converts this protocol version to a string.
-