Package org.apache.http
Class ProtocolVersion
java.lang.Object
org.apache.http.ProtocolVersion
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
HttpVersion
public class ProtocolVersion extends Object implements Serializable, Cloneable
Represents a protocol version, as specified in RFC 2616.
RFC 2616 specifies only HTTP versions, like "HTTP/1.1" and "HTTP/1.0".
RFC 3261 specifies a message format that is identical to HTTP except
for the protocol name. It defines a protocol version "SIP/2.0".
There are some nitty-gritty differences between the interpretation
of versions in HTTP and SIP. In those cases, HTTP takes precedence.
This class defines a protocol version as a combination of
protocol name, major version number, and minor version number.
Note that equals(java.lang.Object) and hashCode() are defined as
final here, they cannot be overridden in derived classes.
- Version:
- $Revision: 609106 $
- Author:
- Oleg Kalnichevski, Roland Weber
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ProtocolVersion(String protocol, int major, int minor)Create a protocol version designator. -
Method Summary
Modifier and Type Method Description Objectclone()Creates and returns a copy of thisObject.intcompareToVersion(ProtocolVersion that)Compares this protocol version with another one.booleanequals(Object obj)Checks equality of this protocol version with an object.ProtocolVersionforVersion(int major, int minor)Obtains a specific version of this protocol.intgetMajor()Returns the major version number of the protocol.intgetMinor()Returns the minor version number of the HTTP protocol.StringgetProtocol()Returns the name of the protocol.booleangreaterEquals(ProtocolVersion version)Tests if this protocol version is greater or equal to the given one.inthashCode()Obtains a hash code consistent withequals(java.lang.Object).booleanisComparable(ProtocolVersion that)Checks whether this protocol can be compared to another one.booleanlessEquals(ProtocolVersion version)Tests if this protocol version is less or equal to the given one.StringtoString()Converts this protocol version to a string.
-
Field Details
-
protocol
Name of the protocol. -
major
protected final int majorMajor version number of the protocol -
minor
protected 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.
-
forVersion
Obtains a specific version of this protocol. This can be used by derived classes to instantiate themselves instead of the base class, and to define constants for commonly used versions.
The default implementation in this class returnsthisif the version matches, and creates a newProtocolVersionotherwise.- Parameters:
major- the major versionminor- the minor version- Returns:
- a protocol version with the same protocol name and the argument version
-
hashCode
public final int hashCode()Obtains a hash code consistent withequals(java.lang.Object).- Overrides:
hashCodein classObject- Returns:
- the hashcode of this protocol version
- See Also:
Object.equals(java.lang.Object)
-
equals
Checks equality of this protocol version with an object. The object is equal if it is a protocl 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.- Overrides:
equalsin classObject- Parameters:
obj- the object to compare with- Returns:
trueif the argument is the same protocol version,falseotherwise- See Also:
Object.hashCode()
-
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:
trueifcompareToVersioncan be called with the argument,falseotherwise
-
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 protocl 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:
trueif this protocol version iscomparableto the argument andcomparesas greater or equal,falseotherwise
-
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:
trueif this protocol version iscomparableto the argument andcomparesas less or equal,falseotherwise
-
toString
Converts this protocol version to a string. -
clone
Description copied from class:ObjectCreates and returns a copy of thisObject. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should callsuper.clone()to create the new instance and then create deep copies of the nested, mutable objects.- Overrides:
clonein classObject- Returns:
- a copy of this object.
- Throws:
CloneNotSupportedException- if this object's class does not implement theCloneableinterface.
-