to top
Android APIs
public class

ProtocolVersion

extends Object
implements Serializable Cloneable
java.lang.Object
   ↳ org.apache.http.ProtocolVersion
Known Direct Subclasses

Class Overview

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(Object) and hashCode() are defined as final here, they cannot be overridden in derived classes.

Summary

Fields
protected final int major Major version number of the protocol
protected final int minor Minor version number of the protocol
protected final String protocol Name of the protocol.
Public Constructors
ProtocolVersion(String protocol, int major, int minor)
Create a protocol version designator.
Public Methods
Object clone()
Creates and returns a copy of this Object.
int compareToVersion(ProtocolVersion that)
Compares this protocol version with another one.
final boolean equals(Object obj)
Checks equality of this protocol version with an object.
ProtocolVersion forVersion(int major, int minor)
Obtains a specific version of this protocol.
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 getProtocol()
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 with equals(Object).
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.
String toString()
Converts this protocol version to a string.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected final int major

Since: API Level 1

Major version number of the protocol

protected final int minor

Since: API Level 1

Minor version number of the protocol

protected final String protocol

Since: API Level 1

Name of the protocol.

Public Constructors

public ProtocolVersion (String protocol, int major, int minor)

Since: API Level 1

Create a protocol version designator.

Parameters
protocol the name of the protocol, for example "HTTP"
major the major version number of the protocol
minor the minor version number of the protocol

Public Methods

public Object clone ()

Since: API Level 1

Creates and returns a copy of this Object. 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 call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
  • a copy of this object.

public int compareToVersion (ProtocolVersion that)

Since: API Level 1

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 for Comparable.

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 is null

public final boolean equals (Object obj)

Since: API Level 1

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.

Parameters
obj the object to compare with
Returns
  • true if the argument is the same protocol version, false otherwise

public ProtocolVersion forVersion (int major, int minor)

Since: API Level 1

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 returns this if the version matches, and creates a new ProtocolVersion otherwise.

Parameters
major the major version
minor the minor version
Returns
  • a protocol version with the same protocol name and the argument version

public final int getMajor ()

Since: API Level 1

Returns the major version number of the protocol.

Returns
  • the major version number.

public final int getMinor ()

Since: API Level 1

Returns the minor version number of the HTTP protocol.

Returns
  • the minor version number.

public final String getProtocol ()

Since: API Level 1

Returns the name of the protocol.

Returns
  • the protocol name

public final boolean greaterEquals (ProtocolVersion version)

Since: API Level 1

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 is comparable to the argument and compares as greater or equal, false otherwise

public final int hashCode ()

Since: API Level 1

Obtains a hash code consistent with equals(Object).

Returns
  • the hashcode of this protocol version

public boolean isComparable (ProtocolVersion that)

Since: API Level 1

Checks whether this protocol can be compared to another one. Only protocol versions with the same protocol name can be compared.

Parameters
that the protocol version to consider
Returns

public final boolean lessEquals (ProtocolVersion version)

Since: API Level 1

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 is comparable to the argument and compares as less or equal, false otherwise

public String toString ()

Since: API Level 1

Converts this protocol version to a string.

Returns
  • a protocol version string, like "HTTP/1.1"