1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/* 2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java $ 3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 609106 $ 4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2008-01-05 01:15:42 -0800 (Sat, 05 Jan 2008) $ 5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ==================================================================== 7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Licensed to the Apache Software Foundation (ASF) under one 8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * or more contributor license agreements. See the NOTICE file 9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * distributed with this work for additional information 10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * regarding copyright ownership. The ASF licenses this file 11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to you under the Apache License, Version 2.0 (the 12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * "License"); you may not use this file except in compliance 13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * with the License. You may obtain a copy of the License at 14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Unless required by applicable law or agreed to in writing, 18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * software distributed under the License is distributed on an 19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * KIND, either express or implied. See the License for the 21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * specific language governing permissions and limitations 22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * under the License. 23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ==================================================================== 24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This software consists of voluntary contributions made by many 26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * individuals on behalf of the Apache Software Foundation. For more 27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * information on the Apache Software Foundation, please see 28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <http://www.apache.org/>. 29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpackage org.apache.http; 33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.io.Serializable; 35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.util.CharArrayBuffer; 36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/** 39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Represents a protocol version, as specified in RFC 2616. 40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * RFC 2616 specifies only HTTP versions, like "HTTP/1.1" and "HTTP/1.0". 41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * RFC 3261 specifies a message format that is identical to HTTP except 42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * for the protocol name. It defines a protocol version "SIP/2.0". 43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * There are some nitty-gritty differences between the interpretation 44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * of versions in HTTP and SIP. In those cases, HTTP takes precedence. 45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p> 46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This class defines a protocol version as a combination of 47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * protocol name, major version number, and minor version number. 48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Note that {@link #equals} and {@link #hashCode} are defined as 49069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * final here, they cannot be overridden in derived classes. 50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 51069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a> 52069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> 53069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 54069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @version $Revision: 609106 $ 55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic class ProtocolVersion implements Serializable, Cloneable { 57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project private static final long serialVersionUID = 8950662842175091068L; 59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Name of the protocol. */ 62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected final String protocol; 63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Major version number of the protocol */ 65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected final int major; 66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Minor version number of the protocol */ 68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected final int minor; 69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 70069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 71069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Create a protocol version designator. 73069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param protocol the name of the protocol, for example "HTTP" 75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param major the major version number of the protocol 76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param minor the minor version number of the protocol 77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public ProtocolVersion(String protocol, int major, int minor) { 79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (protocol == null) { 80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Protocol name must not be null."); 82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (major < 0) { 84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Protocol major version number must not be negative."); 86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (minor < 0) { 88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Protocol minor version number may not be negative"); 90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.protocol = protocol; 92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.major = major; 93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.minor = minor; 94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Returns the name of the protocol. 98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the protocol name 100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final String getProtocol() { 102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return protocol; 103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Returns the major version number of the protocol. 107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the major version number. 109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final int getMajor() { 111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return major; 112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Returns the minor version number of the HTTP protocol. 116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the minor version number. 118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final int getMinor() { 120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return minor; 121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Obtains a specific version of this protocol. 126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This can be used by derived classes to instantiate themselves instead 127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * of the base class, and to define constants for commonly used versions. 128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <br/> 129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The default implementation in this class returns <code>this</code> 130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * if the version matches, and creates a new {@link ProtocolVersion} 131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * otherwise. 132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param major the major version 134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param minor the minor version 135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return a protocol version with the same protocol name 137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * and the argument version 138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public ProtocolVersion forVersion(int major, int minor) { 140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 141069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if ((major == this.major) && (minor == this.minor)) { 142069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return this; 143069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 144069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 145069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // argument checking is done in the constructor 146069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return new ProtocolVersion(this.protocol, major, minor); 147069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 148069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 149069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 150069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 151069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Obtains a hash code consistent with {@link #equals}. 152069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 153069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the hashcode of this protocol version 154069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 155069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final int hashCode() { 156069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return this.protocol.hashCode() ^ (this.major * 100000) ^ this.minor; 157069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 158069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 159069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 160069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 161069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Checks equality of this protocol version with an object. 162069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The object is equal if it is a protocl version with the same 163069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * protocol name, major version number, and minor version number. 164069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The specific class of the object is <i>not</i> relevant, 165069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * instances of derived classes with identical attributes are 166069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * equal to instances of the base class and vice versa. 167069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 168069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param obj the object to compare with 169069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 170069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return <code>true</code> if the argument is the same protocol version, 171069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <code>false</code> otherwise 172069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 173069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final boolean equals(Object obj) { 174069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this == obj) { 175069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return true; 176069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 177069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (!(obj instanceof ProtocolVersion)) { 178069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return false; 179069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 180069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ProtocolVersion that = (ProtocolVersion) obj; 181069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 182069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return ((this.protocol.equals(that.protocol)) && 183069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project (this.major == that.major) && 184069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project (this.minor == that.minor)); 185069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 186069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 187069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 188069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 189069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Checks whether this protocol can be compared to another one. 190069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Only protocol versions with the same protocol name can be 191069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link #compareToVersion compared}. 192069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 193069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param that the protocol version to consider 194069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 195069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return <code>true</code> if {@link #compareToVersion compareToVersion} 196069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * can be called with the argument, <code>false</code> otherwise 197069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 198069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public boolean isComparable(ProtocolVersion that) { 199069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return (that != null) && this.protocol.equals(that.protocol); 200069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 201069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 202069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 203069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 204069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Compares this protocol version with another one. 205069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Only protocol versions with the same protocol name can be compared. 206069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This method does <i>not</i> define a total ordering, as it would be 207069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * required for {@link java.lang.Comparable}. 208069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 209069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param that the protocl version to compare with 210069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 211069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return a negative integer, zero, or a positive integer 212069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * as this version is less than, equal to, or greater than 213069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * the argument version. 214069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 215069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @throws IllegalArgumentException 216069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * if the argument has a different protocol name than this object, 217069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * or if the argument is <code>null</code> 218069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 219069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public int compareToVersion(ProtocolVersion that) { 220069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (that == null) { 221069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 222069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Protocol version must not be null."); 223069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 224069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (!this.protocol.equals(that.protocol)) { 225069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 226069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Versions for different protocols cannot be compared. " + 227069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this + " " + that); 228069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 229069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 230069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project int delta = getMajor() - that.getMajor(); 231069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (delta == 0) { 232069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project delta = getMinor() - that.getMinor(); 233069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 234069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return delta; 235069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 236069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 237069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 238069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 239069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Tests if this protocol version is greater or equal to the given one. 240069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 241069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param version the version against which to check this version 242069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 243069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return <code>true</code> if this protocol version is 244069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link #isComparable comparable} to the argument 245069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * and {@link #compareToVersion compares} as greater or equal, 246069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <code>false</code> otherwise 247069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 248069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final boolean greaterEquals(ProtocolVersion version) { 249069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return isComparable(version) && (compareToVersion(version) >= 0); 250069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 251069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 252069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 253069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 254069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Tests if this protocol version is less or equal to the given one. 255069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 256069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param version the version against which to check this version 257069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 258069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return <code>true</code> if this protocol version is 259069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link #isComparable comparable} to the argument 260069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * and {@link #compareToVersion compares} as less or equal, 261069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <code>false</code> otherwise 262069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 263069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public final boolean lessEquals(ProtocolVersion version) { 264069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return isComparable(version) && (compareToVersion(version) <= 0); 265069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 266069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 267069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 268069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 269069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Converts this protocol version to a string. 270069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 271069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return a protocol version string, like "HTTP/1.1" 272069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 273069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public String toString() { 274069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project CharArrayBuffer buffer = new CharArrayBuffer(16); 275069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(this.protocol); 276069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append('/'); 277069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(Integer.toString(this.major)); 278069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append('.'); 279069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(Integer.toString(this.minor)); 280069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return buffer.toString(); 281069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 282069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 283069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public Object clone() throws CloneNotSupportedException { 284069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return super.clone(); 285069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 286069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 287069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project} 288