@Contract(threading=IMMUTABLE) public class ProtocolVersion extends Object implements Serializable
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.
Constructor and Description |
---|
ProtocolVersion(String protocol,
int major,
int minor)
Create a protocol version designator.
|
Modifier and Type | Method and Description |
---|---|
int |
compareToVersion(ProtocolVersion that)
Compares this protocol version with another one.
|
boolean |
equals(int major,
int minor)
Checks whether this instance has the same major and minor version as the arguments.
|
boolean |
equals(Object obj)
Checks equality of this protocol version with an object.
|
String |
format()
Formats this protocol version as a string.
|
int |
getMajor()
Returns the major version number of the protocol.
|
int |
getMinor()
Returns the minor version number of the HTTP protocol.
|
String |
getProtocol()
Returns the name of the protocol.
|
boolean |
greaterEquals(ProtocolVersion version)
Tests if this protocol version is greater or equal to the given one.
|
int |
hashCode()
Obtains a hash code consistent with
equals(int, int) . |
boolean |
isComparable(ProtocolVersion that)
Checks whether this protocol can be compared to another one.
|
boolean |
lessEquals(ProtocolVersion version)
Tests if this protocol version is less or equal to the given one.
|
String |
toString()
Converts this protocol version to a string.
|
public ProtocolVersion(String protocol, int major, int minor)
protocol
- the name of the protocol, for example "HTTP"major
- the major version number of the protocolminor
- the minor version number of the protocolpublic int compareToVersion(ProtocolVersion that)
Comparable
.that
- the protocol version to compare withIllegalArgumentException
- if the argument has a different protocol name than this object,
or if the argument is null
public final boolean equals(int major, int minor)
major
- the major version to check.minor
- the minor version to check.public final boolean equals(Object obj)
equals
in class Object
obj
- the object to compare withtrue
if the argument is the same protocol version,
false
otherwiseObject.hashCode()
,
HashMap
public String format()
public final int getMajor()
public final int getMinor()
public final String getProtocol()
public final boolean greaterEquals(ProtocolVersion version)
version
- the version against which to check this versiontrue
if this protocol version is
comparable
to the argument
and compares
as greater or equal,
false
otherwisepublic final int hashCode()
equals(int, int)
.hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean isComparable(ProtocolVersion that)
compared
.that
- the protocol version to considertrue
if compareToVersion
can be called with the argument, false
otherwisepublic final boolean lessEquals(ProtocolVersion version)
version
- the version against which to check this versiontrue
if this protocol version is
comparable
to the argument
and compares
as less or equal,
false
otherwise