You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/09/09 09:18:35 UTC
svn commit: r573954 - in
/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http:
HttpVersion.java ProtocolVersion.java
Author: rolandw
Date: Sun Sep 9 00:18:34 2007
New Revision: 573954
URL: http://svn.apache.org/viewvc?rev=573954&view=rev
Log:
HTTPCORE-107: new version factory method in ProtocolVersion
Modified:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpVersion.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpVersion.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpVersion.java?rev=573954&r1=573953&r2=573954&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpVersion.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpVersion.java Sun Sep 9 00:18:34 2007
@@ -70,4 +70,35 @@
super(HTTP, major, minor);
}
+
+ /**
+ * Obtains a specific HTTP version.
+ *
+ * @param major the major version
+ * @param minor the minor version
+ *
+ * @return an instance of {@link HttpVersion} with the argument version
+ */
+ public ProtocolVersion forVersion(int major, int minor) {
+
+ if ((major == this.major) && (minor == this.minor)) {
+ return this;
+ }
+
+ if (major == 1) {
+ if (minor == 0) {
+ return HTTP_1_0;
+ }
+ if (minor == 1) {
+ return HTTP_1_1;
+ }
+ }
+ if ((major == 0) && (minor == 9)) {
+ return HTTP_0_9;
+ }
+
+ // argument checking is done in the constructor
+ return new HttpVersion(major, minor);
+ }
+
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java?rev=573954&r1=573953&r2=573954&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java Sun Sep 9 00:18:34 2007
@@ -122,6 +122,32 @@
/**
+ * 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.
+ * <br/>
+ * The default implementation in this class returns <code>this</code>
+ * if the version matches, and creates a new {@link ProtocolVersion}
+ * otherwise.
+ *
+ * @param major the major version
+ * @param minor the minor version
+ *
+ * @return a protocol version with the same protocol name
+ * and the argument version
+ */
+ public ProtocolVersion forVersion(int major, int minor) {
+
+ if ((major == this.major) && (minor == this.minor)) {
+ return this;
+ }
+
+ // argument checking is done in the constructor
+ return new ProtocolVersion(this.protocol, major, minor);
+ }
+
+
+ /**
* Obtains a hash code consistent with {@link #equals}.
*
* @return the hashcode of this protocol version