From aff60e46290f46caf16c7be7de196425c4fbef94 Mon Sep 17 00:00:00 2001
From: Oleg Kalnichevski
Date: Sat, 3 May 2008 10:39:28 +0000
Subject: [PATCH] HTTPCLIENT-770: code cleanups Contributed by Paul Lindner
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@653041 13f79535-47bb-0310-9956-ffa450edef68
---
.../auth/UsernamePasswordCredentials.java | 4 ++--
.../org/apache/http/client/AuthState.java | 6 ++---
.../HttpEntityEnclosingRequestBase.java | 2 +-
.../http/client/methods/HttpOptions.java | 4 ++--
.../client/protocol/RequestAddCookies.java | 10 ++++-----
.../protocol/RequestDefaultHeaders.java | 5 ++---
.../protocol/ResponseProcessCookies.java | 5 ++---
.../apache/http/client/utils/URIUtils.java | 8 +++----
.../conn/MultihomePlainSocketFactory.java | 7 +++---
.../http/conn/params/HttpRouteParams.java | 12 +++++-----
.../apache/http/conn/routing/HttpRoute.java | 15 ++++++-------
.../http/conn/scheme/PlainSocketFactory.java | 2 +-
.../http/conn/ssl/AbstractVerifier.java | 13 +++++------
.../org/apache/http/cookie/CookieOrigin.java | 10 ++++-----
.../http/cookie/CookiePathComparator.java | 2 +-
.../apache/http/impl/auth/BasicScheme.java | 2 +-
.../apache/http/impl/auth/DigestScheme.java | 8 ++-----
.../apache/http/impl/auth/RFC2617Scheme.java | 5 ++---
.../client/AbstractAuthenticationHandler.java | 8 +++----
.../http/impl/client/BasicCookieStore.java | 4 ++--
.../impl/client/BasicCredentialsProvider.java | 2 +-
.../client/DefaultClientRequestDirector.java | 2 +-
.../client/EntityEnclosingRequestWrapper.java | 2 +-
.../http/impl/conn/AbstractPoolEntry.java | 2 +-
.../impl/conn/DefaultClientConnection.java | 8 +++----
.../impl/conn/SingleClientConnManager.java | 3 +--
.../java/org/apache/http/impl/conn/Wire.java | 6 ++---
.../impl/conn/tsccm/AbstractConnPool.java | 2 --
.../http/impl/conn/tsccm/ConnPoolByRoute.java | 2 --
.../impl/conn/tsccm/RouteSpecificPool.java | 4 ++--
.../apache/http/impl/conn/tsccm/package.html | 4 ++--
.../http/impl/cookie/BasicClientCookie.java | 2 +-
.../http/impl/cookie/BasicDomainHandler.java | 6 ++---
.../http/impl/cookie/BasicPathHandler.java | 2 +-
.../http/impl/cookie/BasicSecureHandler.java | 2 +-
.../http/impl/cookie/BestMatchSpec.java | 6 ++---
.../http/impl/cookie/BrowserCompatSpec.java | 2 +-
.../http/impl/cookie/CookieSpecBase.java | 14 +++++-------
.../apache/http/impl/cookie/DateUtils.java | 8 +++----
.../impl/cookie/NetscapeDomainHandler.java | 19 +++++++---------
.../impl/cookie/RFC2109DomainHandler.java | 2 +-
.../apache/http/impl/cookie/RFC2109Spec.java | 12 +++++-----
.../impl/cookie/RFC2109VersionHandler.java | 2 +-
.../cookie/RFC2965DomainAttributeHandler.java | 9 +++-----
.../apache/http/impl/cookie/RFC2965Spec.java | 22 +++++++++----------
45 files changed, 123 insertions(+), 154 deletions(-)
diff --git a/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java b/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
index 9177781b8..6a0e7369c 100644
--- a/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
+++ b/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
@@ -133,9 +133,9 @@ public class UsernamePasswordCredentials implements Credentials {
*/
@Override
public String toString() {
- StringBuffer result = new StringBuffer();
+ StringBuilder result = new StringBuilder();
result.append(this.userName);
- result.append(":");
+ result.append(':');
result.append((this.password == null) ? "null" : this.password);
return result.toString();
}
diff --git a/module-client/src/main/java/org/apache/http/client/AuthState.java b/module-client/src/main/java/org/apache/http/client/AuthState.java
index 24ce9110d..d30d397ac 100644
--- a/module-client/src/main/java/org/apache/http/client/AuthState.java
+++ b/module-client/src/main/java/org/apache/http/client/AuthState.java
@@ -45,13 +45,13 @@ import org.apache.http.auth.Credentials;
public class AuthState {
/** Actual authentication scheme */
- private AuthScheme authScheme = null;
+ private AuthScheme authScheme;
/** Actual authentication scope */
- private AuthScope authScope = null;
+ private AuthScope authScope;
/** Credentials selected for authentication */
- private Credentials credentials = null;
+ private Credentials credentials;
/**
* Default constructor.
diff --git a/module-client/src/main/java/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java b/module-client/src/main/java/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java
index 33343c0dd..79be0cf0c 100644
--- a/module-client/src/main/java/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java
+++ b/module-client/src/main/java/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.java
@@ -48,7 +48,7 @@ import org.apache.http.protocol.HTTP;
abstract class HttpEntityEnclosingRequestBase
extends HttpRequestBase implements HttpEntityEnclosingRequest {
- private HttpEntity entity = null;
+ private HttpEntity entity;
public HttpEntityEnclosingRequestBase() {
super();
diff --git a/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java b/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
index 28b7faa19..1fba84bd1 100644
--- a/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
+++ b/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
@@ -93,8 +93,8 @@ public class HttpOptions extends HttpRequestBase {
while (it.hasNext()) {
Header header = it.nextHeader();
HeaderElement[] elements = header.getElements();
- for (int i = 0; i < elements.length; i++) {
- methods.add(elements[i].getName());
+ for (HeaderElement element : elements) {
+ methods.add(element.getName());
}
}
return methods;
diff --git a/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java b/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
index d4996f6cf..fc2635da7 100644
--- a/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
+++ b/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
@@ -149,8 +149,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
List cookies = cookieStore.getCookies();
// Find cookies matching the given origin
List matchedCookies = new ArrayList();
- for (int i = 0; i < cookies.size(); i++) {
- Cookie cookie = cookies.get(i);
+ for (Cookie cookie : cookies) {
if (cookieSpec.match(cookie, cookieOrigin)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cookie " + cookie + " match " + cookieOrigin);
@@ -161,16 +160,15 @@ public class RequestAddCookies implements HttpRequestInterceptor {
// Generate Cookie request headers
if (!matchedCookies.isEmpty()) {
List headers = cookieSpec.formatCookies(matchedCookies);
- for (int i = 0; i < headers.size(); i++) {
- request.addHeader(headers.get(i));
+ for (Header header : headers) {
+ request.addHeader(header);
}
}
int ver = cookieSpec.getVersion();
if (ver > 0) {
boolean needVersionHeader = false;
- for (int i = 0; i < matchedCookies.size(); i++) {
- Cookie cookie = matchedCookies.get(i);
+ for (Cookie cookie : matchedCookies) {
if (ver != cookie.getVersion()) {
needVersionHeader = true;
}
diff --git a/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java b/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
index 268a21946..b228fc0d0 100644
--- a/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
+++ b/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
@@ -33,7 +33,6 @@ package org.apache.http.client.protocol;
import java.io.IOException;
import java.util.Collection;
-import java.util.Iterator;
import org.apache.http.Header;
import org.apache.http.HttpException;
@@ -66,8 +65,8 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
Collection> defHeaders = (Collection>) request.getParams().getParameter(
ClientPNames.DEFAULT_HEADERS);
if (defHeaders != null) {
- for (Iterator> it = defHeaders.iterator(); it.hasNext(); ) {
- request.addHeader((Header) it.next());
+ for (Object defHeader : defHeaders) {
+ request.addHeader((Header) defHeader);
}
}
}
diff --git a/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java b/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
index d54aa8021..c4fb9862c 100644
--- a/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
+++ b/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
@@ -118,12 +118,11 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
Header header = iterator.nextHeader();
try {
List cookies = cookieSpec.parse(header, cookieOrigin);
- for (int c = 0; c < cookies.size(); c++) {
- Cookie cookie = cookies.get(c);
+ for (Cookie cookie : cookies) {
try {
cookieSpec.validate(cookie, cookieOrigin);
cookieStore.addCookie(cookie);
-
+
if (LOG.isDebugEnabled()) {
LOG.debug("Cookie accepted: \""
+ cookie + "\". ");
diff --git a/module-client/src/main/java/org/apache/http/client/utils/URIUtils.java b/module-client/src/main/java/org/apache/http/client/utils/URIUtils.java
index ef70c5831..79101dfea 100644
--- a/module-client/src/main/java/org/apache/http/client/utils/URIUtils.java
+++ b/module-client/src/main/java/org/apache/http/client/utils/URIUtils.java
@@ -86,22 +86,22 @@ public class URIUtils {
}
buffer.append(host);
if (port > 0) {
- buffer.append(":");
+ buffer.append(':');
buffer.append(port);
}
}
if (path == null || !path.startsWith("/")) {
- buffer.append("/");
+ buffer.append('/');
}
if (path != null) {
buffer.append(path);
}
if (query != null) {
- buffer.append("?");
+ buffer.append('?');
buffer.append(query);
}
if (fragment != null) {
- buffer.append("#");
+ buffer.append('#');
buffer.append(fragment);
}
return new URI(buffer.toString());
diff --git a/module-client/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java b/module-client/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java
index adb3ca3a5..ab19dbc2f 100644
--- a/module-client/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java
+++ b/module-client/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java
@@ -39,6 +39,7 @@ import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Arrays;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.SocketFactory;
@@ -64,7 +65,7 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
* Gets the singleton instance of this class.
* @return the one and only plain socket factory
*/
- public static final MultihomePlainSocketFactory getSocketFactory() {
+ public static MultihomePlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY;
}
@@ -126,9 +127,7 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
InetAddress[] inetadrs = InetAddress.getAllByName(host);
List addresses = new ArrayList(inetadrs.length);
- for (InetAddress inetadr: inetadrs) {
- addresses.add(inetadr);
- }
+ addresses.addAll(Arrays.asList(inetadrs));
Collections.shuffle(addresses);
IOException lastEx = null;
diff --git a/module-client/src/main/java/org/apache/http/conn/params/HttpRouteParams.java b/module-client/src/main/java/org/apache/http/conn/params/HttpRouteParams.java
index d514a1dab..f2b16e570 100644
--- a/module-client/src/main/java/org/apache/http/conn/params/HttpRouteParams.java
+++ b/module-client/src/main/java/org/apache/http/conn/params/HttpRouteParams.java
@@ -84,7 +84,7 @@ public class HttpRouteParams {
* @return the default proxy set in the argument parameters, or
* null
if not set
*/
- public final static HttpHost getDefaultProxy(HttpParams params) {
+ public static HttpHost getDefaultProxy(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
@@ -108,7 +108,7 @@ public class HttpRouteParams {
* null
by {@link #getDefaultProxy},
* to allow for explicit unsetting in hierarchies.
*/
- public final static void setDefaultProxy(HttpParams params,
+ public static void setDefaultProxy(HttpParams params,
HttpHost proxy) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
@@ -128,7 +128,7 @@ public class HttpRouteParams {
* @return the forced route set in the argument parameters, or
* null
if not set
*/
- public final static HttpRoute getForcedRoute(HttpParams params) {
+ public static HttpRoute getForcedRoute(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
@@ -152,7 +152,7 @@ public class HttpRouteParams {
* null
by {@link #getForcedRoute},
* to allow for explicit unsetting in hierarchies.
*/
- public final static void setForcedRoute(HttpParams params,
+ public static void setForcedRoute(HttpParams params,
HttpRoute route) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
@@ -173,7 +173,7 @@ public class HttpRouteParams {
* @return the local address set in the argument parameters, or
* null
if not set
*/
- public final static InetAddress getLocalAddress(HttpParams params) {
+ public static InetAddress getLocalAddress(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
@@ -191,7 +191,7 @@ public class HttpRouteParams {
* @param params the parameters in which to set the value
* @param local the value to set, may be null
*/
- public final static void setLocalAddress(HttpParams params,
+ public static void setLocalAddress(HttpParams params,
InetAddress local) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
diff --git a/module-client/src/main/java/org/apache/http/conn/routing/HttpRoute.java b/module-client/src/main/java/org/apache/http/conn/routing/HttpRoute.java
index e23de4568..c1f6d9ad1 100644
--- a/module-client/src/main/java/org/apache/http/conn/routing/HttpRoute.java
+++ b/module-client/src/main/java/org/apache/http/conn/routing/HttpRoute.java
@@ -239,10 +239,10 @@ public final class HttpRoute implements RouteInfo, Cloneable {
if ((proxies == null) || (proxies.length < 1))
return null;
- for (int i=0; i= hopcount)
throw new IllegalArgumentException
("Hop index " + hop +
- " exceeds route length " + hopcount +".");
+ " exceeds route length " + hopcount);
HttpHost result = null;
if (hop < hopcount-1)
@@ -385,8 +385,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
hc ^= localAddress.hashCode();
if (this.proxyChain != null) {
hc ^= proxyChain.length;
- for (int i=0; i");
if (this.proxyChain != null) {
- for (int i=0; i");
}
}
diff --git a/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java b/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
index a5b9c6034..48ca22d8a 100644
--- a/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
+++ b/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
@@ -57,7 +57,7 @@ public final class PlainSocketFactory implements SocketFactory {
* Gets the singleton instance of this class.
* @return the one and only plain socket factory
*/
- public static final PlainSocketFactory getSocketFactory() {
+ public static PlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY;
}
diff --git a/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java b/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
index 2a3cb88df..9d791d35e 100644
--- a/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
+++ b/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
@@ -162,9 +162,9 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
names.add(cns[0]);
}
if(subjectAlts != null) {
- for(int i = 0; i < subjectAlts.length; i++) {
- if(subjectAlts[i] != null) {
- names.add(subjectAlts[i]);
+ for (String subjectAlt : subjectAlts) {
+ if (subjectAlt != null) {
+ names.add(subjectAlt);
}
}
}
@@ -303,12 +303,11 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
cpe.printStackTrace();
}
if(c != null) {
- Iterator> it = c.iterator();
- while(it.hasNext()) {
- List> list = it.next();
+ for (List> aC : c) {
+ List> list = aC;
int type = ((Integer) list.get(0)).intValue();
// If type is 2, then we've got a dNSName
- if(type == 2) {
+ if (type == 2) {
String s = (String) list.get(1);
subjectAltList.add(s);
}
diff --git a/module-client/src/main/java/org/apache/http/cookie/CookieOrigin.java b/module-client/src/main/java/org/apache/http/cookie/CookieOrigin.java
index 68db99cea..c985aee3b 100644
--- a/module-client/src/main/java/org/apache/http/cookie/CookieOrigin.java
+++ b/module-client/src/main/java/org/apache/http/cookie/CookieOrigin.java
@@ -53,7 +53,7 @@ public final class CookieOrigin {
throw new IllegalArgumentException(
"Host of origin may not be null");
}
- if (host.trim().equals("")) {
+ if (host.trim().length() == 0) {
throw new IllegalArgumentException(
"Host of origin may not be blank");
}
@@ -66,7 +66,7 @@ public final class CookieOrigin {
}
this.host = host.toLowerCase(Locale.ENGLISH);
this.port = port;
- if (!path.trim().equals("")) {
+ if (path.trim().length() != 0) {
this.path = path;
} else {
this.path = "/";
@@ -93,15 +93,15 @@ public final class CookieOrigin {
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
- buffer.append("[");
+ buffer.append('[');
if (this.secure) {
buffer.append("(secure)");
}
buffer.append(this.host);
- buffer.append(":");
+ buffer.append(':');
buffer.append(Integer.toString(this.port));
buffer.append(this.path);
- buffer.append("]");
+ buffer.append(']');
return buffer.toString();
}
diff --git a/module-client/src/main/java/org/apache/http/cookie/CookiePathComparator.java b/module-client/src/main/java/org/apache/http/cookie/CookiePathComparator.java
index 749ddae37..a6aa1865d 100644
--- a/module-client/src/main/java/org/apache/http/cookie/CookiePathComparator.java
+++ b/module-client/src/main/java/org/apache/http/cookie/CookiePathComparator.java
@@ -58,7 +58,7 @@ public class CookiePathComparator implements Serializable, Comparator {
path = "/";
}
if (!path.endsWith("/")) {
- path = path + "/";
+ path = path + '/';
}
return path;
}
diff --git a/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java b/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java
index 23320d435..4786bcb6d 100644
--- a/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java
+++ b/module-client/src/main/java/org/apache/http/impl/auth/BasicScheme.java
@@ -120,7 +120,7 @@ public class BasicScheme extends RFC2617Scheme {
*
* @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated
- * @throws InvalidCredentialsException if authentication credentials
+ * @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials
* are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
diff --git a/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java b/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java
index 7a3ae5252..7bb39f08e 100644
--- a/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java
+++ b/module-client/src/main/java/org/apache/http/impl/auth/DigestScheme.java
@@ -198,7 +198,7 @@ public class DigestScheme extends RFC2617Scheme {
* @param credentials A set of credentials to be used for athentication
* @param request The request being authenticated
*
- * @throws InvalidCredentialsException if authentication credentials
+ * @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials
* are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
@@ -242,10 +242,6 @@ public class DigestScheme extends RFC2617Scheme {
/**
* Creates an MD5 response digest.
*
- * @param uname Username
- * @param pwd Password
- * @param charset The credential charset
- *
* @return The created digest as string. This will be the response tag's
* value in the Authentication HTTP header.
* @throws AuthenticationException when MD5 is an unsupported algorithm
@@ -311,7 +307,7 @@ public class DigestScheme extends RFC2617Scheme {
//we do not have access to the entity-body or its hash
//TODO: add Method ":" digest-uri-value ":" H(entity-body)
} else {
- a2 = method + ":" + uri;
+ a2 = method + ':' + uri;
}
String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2)));
diff --git a/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java b/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
index 0f3a8779b..fac825ecf 100644
--- a/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
+++ b/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
@@ -60,7 +60,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
/**
* Authentication parameter map.
*/
- private Map params = null;
+ private Map params;
/**
* Flag whether authenticating against a proxy.
@@ -131,8 +131,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
}
this.params = new HashMap(elements.length);
- for (int i = 0; i < elements.length; i++) {
- HeaderElement element = elements[i];
+ for (HeaderElement element : elements) {
this.params.put(element.getName(), element.getValue());
}
}
diff --git a/module-client/src/main/java/org/apache/http/impl/client/AbstractAuthenticationHandler.java b/module-client/src/main/java/org/apache/http/impl/client/AbstractAuthenticationHandler.java
index 88c83b0c8..ea7f6fe2f 100644
--- a/module-client/src/main/java/org/apache/http/impl/client/AbstractAuthenticationHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/client/AbstractAuthenticationHandler.java
@@ -33,7 +33,6 @@ package org.apache.http.impl.client;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -73,8 +72,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
final Header[] headers) throws MalformedChallengeException {
Map map = new HashMap(headers.length);
- for (int i = 0; i < headers.length; i++) {
- Header header = headers[i];
+ for (Header header : headers) {
CharArrayBuffer buffer;
int pos;
if (header instanceof FormattedHeader) {
@@ -125,9 +123,9 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
}
AuthScheme authScheme = null;
- for (Iterator it = authPrefs.iterator(); it.hasNext(); ) {
- String id = it.next();
+ for (String id : authPrefs) {
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
+
if (challenge != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(id + " authentication scheme selected");
diff --git a/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java b/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
index c0f283be1..2bb84b9d6 100644
--- a/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
+++ b/module-client/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
@@ -109,8 +109,8 @@ public class BasicCookieStore implements CookieStore {
*/
public synchronized void addCookies(Cookie[] cookies) {
if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- this.addCookie(cookies[i]);
+ for (Cookie cooky : cookies) {
+ this.addCookie(cooky);
}
}
}
diff --git a/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java b/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java
index fedbf6a9e..038842b98 100644
--- a/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java
+++ b/module-client/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java
@@ -85,7 +85,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
* Find matching {@link Credentials credentials} for the given authentication scope.
*
* @param map the credentials hash map
- * @param token the {@link AuthScope authentication scope}
+ * @param authscope the {@link AuthScope authentication scope}
* @return the credentials
*
*/
diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
index ced6db164..b70f22e06 100644
--- a/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
+++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
@@ -761,7 +761,7 @@ public class DefaultClientRequestDirector
StringBuilder buffer = new StringBuilder(host.length() + 6);
buffer.append(host);
- buffer.append(":");
+ buffer.append(':');
buffer.append(Integer.toString(port));
String authority = buffer.toString();
diff --git a/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java b/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
index 67c51f29f..924641689 100644
--- a/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
+++ b/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
@@ -54,7 +54,7 @@ import org.apache.http.protocol.HTTP;
class EntityEnclosingRequestWrapper extends RequestWrapper
implements HttpEntityEnclosingRequest {
- private HttpEntity entity = null;
+ private HttpEntity entity;
public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request)
throws ProtocolException {
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java b/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java
index 7d4506d0d..3328f2a4e 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java
@@ -90,7 +90,7 @@ public abstract class AbstractPoolEntry {
/**
* Creates a new pool entry.
*
- * @param occ the underlying connection for this entry
+ * @param connOperator the Connection Operator for this entry
* @param route the planned route for the connection,
* or null
*/
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java b/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
index 5ffa0cd58..4ce8a5274 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java
@@ -223,8 +223,8 @@ public class DefaultClientConnection extends SocketHttpClientConnection
if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug("<< " + response.getStatusLine().toString());
Header[] headers = response.getAllHeaders();
- for (int i = 0; i < headers.length; i++) {
- HEADERS_LOG.debug("<< " + headers[i].toString());
+ for (Header header : headers) {
+ HEADERS_LOG.debug("<< " + header.toString());
}
}
return response;
@@ -237,8 +237,8 @@ public class DefaultClientConnection extends SocketHttpClientConnection
if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug(">> " + request.getRequestLine().toString());
Header[] headers = request.getAllHeaders();
- for (int i = 0; i < headers.length; i++) {
- HEADERS_LOG.debug(">> " + headers[i].toString());
+ for (Header header : headers) {
+ HEADERS_LOG.debug(">> " + header.toString());
}
}
}
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java b/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
index 11b28a781..b7ecc1e53 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
@@ -361,7 +361,6 @@ public class SingleClientConnManager implements ClientConnectionManager {
/**
* Creates a new pool entry.
*
- * @param occ the underlying connection for this entry
*/
protected PoolEntry() {
super(SingleClientConnManager.this.connOperator, null);
@@ -403,7 +402,7 @@ public class SingleClientConnManager implements ClientConnectionManager {
* Creates a new connection adapter.
*
* @param entry the pool entry for the connection being wrapped
- * @param plan the planned route for this connection
+ * @param route the planned route for this connection
*/
protected ConnAdapter(PoolEntry entry, HttpRoute route) {
super(SingleClientConnManager.this, entry);
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/Wire.java b/module-client/src/main/java/org/apache/http/impl/conn/Wire.java
index 3d76e4f1a..4812d0123 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/Wire.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/Wire.java
@@ -52,7 +52,7 @@ public class Wire {
private void wire(String header, InputStream instream)
throws IOException {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
int ch;
while ((ch = instream.read()) != -1) {
if (ch == 13) {
@@ -72,8 +72,8 @@ public class Wire {
}
}
if (buffer.length() > 0) {
- buffer.append("\"");
- buffer.insert(0, "\"");
+ buffer.append('\"');
+ buffer.insert(0, '\"');
buffer.insert(0, header);
log.debug(buffer.toString());
}
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
index ecdb1e15b..3df138e35 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
@@ -97,8 +97,6 @@ public abstract class AbstractConnPool implements RefQueueHandler {
/**
* Creates a new connection pool.
- *
- * @param mgr the connection manager
*/
protected AbstractConnPool() {
issuedConnections = new HashSet();
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
index 457111102..925215452 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
@@ -251,8 +251,6 @@ public class ConnPoolByRoute extends AbstractConnPool {
* @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the timeout
,
* may be null
only if there is no timeout
- * @param operator the connection operator, in case
- * a connection has to be created
* @param aborter an object which can abort a {@link WaitingThread}.
*
* @return pool entry holding a connection for the route
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
index f5fcab8aa..9dbf3094b 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
@@ -62,10 +62,10 @@ public class RouteSpecificPool {
* This list is managed LIFO, to increase idle times and
* allow for closing connections that are not really needed.
*/
- protected LinkedList freeEntries;
+ protected final LinkedList freeEntries;
/** The list of threads waiting for this pool. */
- protected Queue waitingThreads;
+ protected final Queue waitingThreads;
/** The number of created entries. */
protected int numEntries;
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/package.html b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/package.html
index 1ddcce136..7d3bb6a6d 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/package.html
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/package.html
@@ -37,7 +37,7 @@
The implementation of a thread-safe client connection manager.
-
+
@@ -48,7 +48,7 @@ maintains a Pool (yellow) of connections and waiting threads.
Both Manager and Pool rely on Operations (cyan) to provide the
actual connections.
-
+
In order to allow connection garbage collection, it is
imperative that hard object references between the areas are
restricted to the relations indicated by arrows in the diagram:
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java b/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
index 8088d2b61..376cc064e 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
@@ -363,7 +363,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
private boolean isSecure;
/** The version of the cookie specification I was created from. */
- private int cookieVersion = 0;
+ private int cookieVersion;
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BasicDomainHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/BasicDomainHandler.java
index 0af2c0f56..0b586d720 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BasicDomainHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BasicDomainHandler.java
@@ -50,7 +50,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute");
}
- if (value.trim().equals("")) {
+ if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for domain attribute");
}
cookie.setDomain(value);
@@ -74,7 +74,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (domain == null) {
throw new MalformedCookieException("Cookie domain may not be null");
}
- if (host.indexOf(".") >= 0) {
+ if (host.contains(".")) {
// Not required to have at least two dots. RFC 2965.
// A Set-Cookie2 with Domain=ajax.com will be accepted.
@@ -114,7 +114,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
return true;
}
if (!domain.startsWith(".")) {
- domain = "." + domain;
+ domain = '.' + domain;
}
return host.endsWith(domain) || host.equals(domain.substring(1));
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BasicPathHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/BasicPathHandler.java
index 3c608c7d0..757dee502 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BasicPathHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BasicPathHandler.java
@@ -47,7 +47,7 @@ public class BasicPathHandler implements CookieAttributeHandler {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
- if (value == null || value.trim().equals("")) {
+ if (value == null || value.trim().length() == 0) {
value = "/";
}
cookie.setPath(value);
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BasicSecureHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/BasicSecureHandler.java
index b08988b0c..b7c912553 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BasicSecureHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BasicSecureHandler.java
@@ -57,7 +57,7 @@ public class BasicSecureHandler extends AbstractCookieAttributeHandler {
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
- return cookie.isSecure() ? origin.isSecure() : true;
+ return !cookie.isSecure() || origin.isSecure();
}
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
index c0ade8847..b39becfea 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
@@ -53,9 +53,9 @@ public class BestMatchSpec implements CookieSpec {
private final String[] datepatterns;
private final boolean oneHeader;
- private RFC2965Spec strict = null;
- private BrowserCompatSpec compat = null;
- private NetscapeDraftSpec netscape = null;
+ private RFC2965Spec strict;
+ private BrowserCompatSpec compat;
+ private NetscapeDraftSpec netscape;
public BestMatchSpec(final String[] datepatterns, boolean oneHeader) {
super();
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
index d4b472a47..96793bbe6 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
@@ -113,7 +113,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
if (i1 != -1) {
i1 += "expires=".length();
- int i2 = headervalue.indexOf(";", i1);
+ int i2 = headervalue.indexOf(';', i1);
if (i2 == -1) {
i2 = headervalue.length();
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java b/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
index 35e53a0c8..96626afb1 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
@@ -71,27 +71,25 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
protected List parse(final HeaderElement[] elems, final CookieOrigin origin)
throws MalformedCookieException {
List cookies = new ArrayList(elems.length);
- for (int i = 0; i < elems.length; i++) {
- HeaderElement headerelement = elems[i];
-
+ for (HeaderElement headerelement : elems) {
String name = headerelement.getName();
String value = headerelement.getValue();
- if (name == null || name.equals("")) {
+ if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty");
}
-
+
BasicClientCookie cookie = new BasicClientCookie(name, value);
cookie.setPath(getDefaultPath(origin));
cookie.setDomain(getDefaultDomain(origin));
-
+
// cycle through the parameters
NameValuePair[] attribs = headerelement.getParameters();
for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair attrib = attribs[j];
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
-
+
cookie.setAttribute(s, attrib.getValue());
-
+
CookieAttributeHandler handler = findAttribHandler(s);
if (handler != null) {
handler.parse(cookie, attrib.getValue());
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/DateUtils.java b/module-client/src/main/java/org/apache/http/impl/cookie/DateUtils.java
index 5a1fa3012..59a45a330 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/DateUtils.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/DateUtils.java
@@ -151,16 +151,16 @@ public final class DateUtils {
) {
dateValue = dateValue.substring (1, dateValue.length() - 1);
}
-
- for (int i = 0; i < dateFormats.length; i++) {
- SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormats[i]);
+
+ for (String dateFormat : dateFormats) {
+ SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
dateParser.set2DigitYearStart(startDate);
try {
return dateParser.parse(dateValue);
} catch (ParseException pe) {
// ignore this exception, we will try the next format
- }
+ }
}
// we were unable to parse the date
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDomainHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDomainHandler.java
index 64729ec18..2411c44f0 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDomainHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDomainHandler.java
@@ -50,7 +50,7 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
// Perform Netscape Cookie draft specific validation
String host = origin.getHost();
String domain = cookie.getDomain();
- if (host.indexOf(".") >= 0) {
+ if (host.contains(".")) {
int domainParts = new StringTokenizer(domain, ".").countTokens();
if (isSpecialDomain(domain)) {
@@ -78,16 +78,13 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
*/
private static boolean isSpecialDomain(final String domain) {
final String ucDomain = domain.toUpperCase(Locale.ENGLISH);
- if (ucDomain.endsWith(".COM")
- || ucDomain.endsWith(".EDU")
- || ucDomain.endsWith(".NET")
- || ucDomain.endsWith(".GOV")
- || ucDomain.endsWith(".MIL")
- || ucDomain.endsWith(".ORG")
- || ucDomain.endsWith(".INT")) {
- return true;
- }
- return false;
+ return ucDomain.endsWith(".COM")
+ || ucDomain.endsWith(".EDU")
+ || ucDomain.endsWith(".NET")
+ || ucDomain.endsWith(".GOV")
+ || ucDomain.endsWith(".MIL")
+ || ucDomain.endsWith(".ORG")
+ || ucDomain.endsWith(".INT");
}
@Override
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109DomainHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109DomainHandler.java
index 0bf6ec20d..d0040b060 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109DomainHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109DomainHandler.java
@@ -52,7 +52,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute");
}
- if (value.trim().equals("")) {
+ if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for domain attribute");
}
cookie.setDomain(value);
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
index 65c2879f7..4b4d1d41d 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
@@ -146,8 +146,7 @@ public class RFC2109Spec extends CookieSpecBase {
private List doFormatOneHeader(final List cookies) {
int version = Integer.MAX_VALUE;
// Pick the lowest common denominator
- for (int i = 0; i < cookies.size(); i++) {
- Cookie cookie = cookies.get(i);
+ for (Cookie cookie : cookies) {
if (cookie.getVersion() < version) {
version = cookie.getVersion();
}
@@ -157,9 +156,9 @@ public class RFC2109Spec extends CookieSpecBase {
buffer.append(": ");
buffer.append("$Version=");
buffer.append(Integer.toString(version));
- for (int i = 0; i < cookies.size(); i++) {
+ for (Cookie cooky : cookies) {
buffer.append("; ");
- Cookie cookie = cookies.get(i);
+ Cookie cookie = cooky;
formatCookieAsVer(buffer, cookie, version);
}
List headers = new ArrayList(1);
@@ -168,9 +167,8 @@ public class RFC2109Spec extends CookieSpecBase {
}
private List doFormatManyHeaders(final List cookies) {
- List headers = new ArrayList(cookies.size());
- for (int i = 0; i < cookies.size(); i++) {
- Cookie cookie = cookies.get(i);
+ List headers = new ArrayList(cookies.size());
+ for (Cookie cookie : cookies) {
int version = cookie.getVersion();
CharArrayBuffer buffer = new CharArrayBuffer(40);
buffer.append("Cookie: ");
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109VersionHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109VersionHandler.java
index f7f99eae3..121dd8e5f 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109VersionHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109VersionHandler.java
@@ -49,7 +49,7 @@ public class RFC2109VersionHandler extends AbstractCookieAttributeHandler {
if (value == null) {
throw new MalformedCookieException("Missing value for version attribute");
}
- if (value.trim().equals("")) {
+ if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for version attribute");
}
try {
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java
index 1ec18c99b..d2819c9bc 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965DomainAttributeHandler.java
@@ -65,7 +65,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
throw new MalformedCookieException(
"Missing value for domain attribute");
}
- if (domain.trim().equals("")) {
+ if (domain.trim().length() == 0) {
throw new MalformedCookieException(
"Blank value for domain attribute");
}
@@ -76,7 +76,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
// a dot, the user agent supplies a leading dot ..."
// That effectively implies that the domain attribute
// MAY NOT be an IP address of a host name
- domain = "." + domain;
+ domain = '.' + domain;
}
cookie.setDomain(domain);
}
@@ -189,10 +189,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
// effective host name minus domain must not contain any dots
String effectiveHostWithoutDomain = host.substring(
0, host.length() - cookieDomain.length());
- if (effectiveHostWithoutDomain.indexOf('.') != -1) {
- return false;
- }
- return true;
+ return effectiveHostWithoutDomain.indexOf('.') == -1;
}
}
\ No newline at end of file
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
index d36d8806f..19f587c52 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
@@ -108,12 +108,10 @@ public class RFC2965Spec extends RFC2109Spec {
HeaderElement[] elems = header.getElements();
List cookies = new ArrayList(elems.length);
- for (int i = 0; i < elems.length; i++) {
- HeaderElement headerelement = elems[i];
-
+ for (HeaderElement headerelement : elems) {
String name = headerelement.getName();
String value = headerelement.getValue();
- if (name == null || name.equals("")) {
+ if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty");
}
@@ -123,24 +121,24 @@ public class RFC2965Spec extends RFC2109Spec {
} else {
cookie = createCookie(name, value, origin);
}
-
+
// cycle through the parameters
NameValuePair[] attribs = headerelement.getParameters();
-
+
// Eliminate duplicate attributes. The first occurrence takes precedence
// See RFC2965: 3.2 Origin Server Role
- Map attribmap =
- new HashMap(attribs.length);
+ Map attribmap =
+ new HashMap(attribs.length);
for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair param = attribs[j];
attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
}
- for (Map.Entry entry: attribmap.entrySet()) {
+ for (Map.Entry entry : attribmap.entrySet()) {
NameValuePair attrib = entry.getValue();
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
-
+
cookie.setAttribute(s, attrib.getValue());
-
+
CookieAttributeHandler handler = findAttribHandler(s);
if (handler != null) {
handler.parse(cookie, attrib.getValue());
@@ -214,7 +212,7 @@ public class RFC2965Spec extends RFC2109Spec {
* the effective host name is the same as the host name. Note
* that all effective host names contain at least one dot.
*
- * @param host host name where cookie is received from or being sent to.
+ * @param origin origin where cookie is received from or being sent to.
* @return
*/
private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) {