Top Description Fields Constructors Methods
org.apache.http

public Class ProtocolVersion

extends Object
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Known Direct Subclasses
org.apache.http.HttpVersion
Annotations
@Contract
threading:IMMUTABLE
Imports
java.io.Serializable, org.apache.http.annotation.ThreadingBehavior, .Contract, org.apache.http.util.Args

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

Since
4.0

Field Summary

Modifier and TypeField and Description
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.

private static final long

Constructor Summary

AccessConstructor and Description
public
ProtocolVersion(final String
the name of the protocol, for example "HTTP"
protocol
,
final int
the major version number of the protocol
major
,
final int
the minor version number of the protocol
minor
)

Create a protocol version designator.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public int

Returns:

a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the argument version.
compareToVersion
(final ProtocolVersion
the protocol version to compare with
that
)

Compares this protocol version with another one.

public final boolean

Returns:

true if the argument is the same protocol version, false otherwise
equals
(final Object
the object to compare with
obj
)

Overrides java.lang.Object.equals.

Checks equality of this protocol version with an object.
public ProtocolVersion

Returns:

a protocol version with the same protocol name and the argument version
forVersion
(final int
the major version
major
,
final int
the minor version
minor
)

Obtains a specific version of this protocol.

public final int

Returns:

the major version number.
getMajor
()

Returns the major version number of the protocol.

public final int

Returns:

the minor version number.
getMinor
()

Returns the minor version number of the HTTP protocol.

public final String

Returns:

the protocol name
getProtocol
()

Returns the name of the protocol.

public final boolean

Returns:

true if this protocol version is comparable to the argument and compares as greater or equal, false otherwise
greaterEquals
(final ProtocolVersion
the version against which to check this version
version
)

Tests if this protocol version is greater or equal to the given one.

public final int

Returns:

the hashcode of this protocol version
hashCode
()

Overrides java.lang.Object.hashCode.

Obtains a hash code consistent with equals.
public boolean

Returns:

true if compareToVersion can be called with the argument, false otherwise
isComparable
(final ProtocolVersion
the protocol version to consider
that
)

Checks whether this protocol can be compared to another one.

public final boolean

Returns:

true if this protocol version is comparable to the argument and compares as less or equal, false otherwise
lessEquals
(final ProtocolVersion
the version against which to check this version
version
)

Tests if this protocol version is less or equal to the given one.

public String

Returns:

a protocol version string, like "HTTP/1.1"
toString
()

Overrides java.lang.Object.toString.

Converts this protocol version to a string.
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

majorback to summary
protected final int major

Major version number of the protocol

minorback to summary
protected final int minor

Minor version number of the protocol

protocolback to summary
protected final String protocol

Name of the protocol.

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ProtocolVersionback to summary
public ProtocolVersion(final String protocol, final int major, final int minor)

Create a protocol version designator.

Parameters
protocol:String

the name of the protocol, for example "HTTP"

major:int

the major version number of the protocol

minor:int

the minor version number of the protocol

Method Detail

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
compareToVersionback to summary
public int compareToVersion(final ProtocolVersion that)

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 java.lang.Comparable.

Parameters
that:ProtocolVersion

the protocol version to compare with

Returns:int

a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the argument version.

Exceptions
IllegalArgumentException:
if the argument has a different protocol name than this object, or if the argument is null
equalsback to summary
public final boolean equals(final Object obj)

Overrides 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.

Parameters
obj:Object

the object to compare with

Returns:boolean

true if the argument is the same protocol version, false otherwise

Annotations
@Override
forVersionback to summary
public ProtocolVersion forVersion(final int major, final int minor)

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:int

the major version

minor:int

the minor version

Returns:ProtocolVersion

a protocol version with the same protocol name and the argument version

getMajorback to summary
public final int getMajor()

Returns the major version number of the protocol.

Returns:int

the major version number.

getMinorback to summary
public final int getMinor()

Returns the minor version number of the HTTP protocol.

Returns:int

the minor version number.

getProtocolback to summary
public final String getProtocol()

Returns the name of the protocol.

Returns:String

the protocol name

greaterEqualsback to summary
public final boolean greaterEquals(final ProtocolVersion version)

Tests if this protocol version is greater or equal to the given one.

Parameters
version:ProtocolVersion

the version against which to check this version

Returns:boolean

true if this protocol version is comparable to the argument and compares as greater or equal, false otherwise

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Obtains a hash code consistent with equals.

Returns:int

the hashcode of this protocol version

Annotations
@Override
isComparableback to summary
public boolean isComparable(final ProtocolVersion that)

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

Parameters
that:ProtocolVersion

the protocol version to consider

Returns:boolean

true if compareToVersion can be called with the argument, false otherwise

lessEqualsback to summary
public final boolean lessEquals(final ProtocolVersion version)

Tests if this protocol version is less or equal to the given one.

Parameters
version:ProtocolVersion

the version against which to check this version

Returns:boolean

true if this protocol version is comparable to the argument and compares as less or equal, false otherwise

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Converts this protocol version to a string.

Returns:String

a protocol version string, like "HTTP/1.1"

Annotations
@Override