Use Java 1.6 String#isEmpty(); minor cleanups

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1561064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-01-24 17:02:45 +00:00
parent 594f2f4b62
commit 715a34c860
30 changed files with 40 additions and 47 deletions

View File

@ -50,6 +50,6 @@ public enum CacheResponseStatus {
/** The response was generated from the cache after validating the /** The response was generated from the cache after validating the
* entry with the origin server. * entry with the origin server.
*/ */
VALIDATED; VALIDATED
} }

View File

@ -337,7 +337,7 @@ public class CachingExec implements ClientExecChain {
} }
final Map<String, Variant> variants = getExistingCacheVariants(target, request); final Map<String, Variant> variants = getExistingCacheVariants(target, request);
if (variants != null && variants.size() > 0) { if (variants != null && !variants.isEmpty()) {
return negotiateResponseFromVariants(route, request, context, return negotiateResponseFromVariants(route, request, context,
execAware, variants); execAware, variants);
} }

View File

@ -37,7 +37,7 @@ public class TestSHA256HashingScheme {
public void canHash() { public void canHash() {
final SHA256KeyHashingScheme impl = new SHA256KeyHashingScheme(); final SHA256KeyHashingScheme impl = new SHA256KeyHashingScheme();
final String result = impl.hash("hello, hashing world"); final String result = impl.hash("hello, hashing world");
assertTrue(result != null && result.length() > 0); assertTrue(result != null && !result.isEmpty());
} }
} }

View File

@ -188,7 +188,7 @@ final class OSGiHttpRoutePlanner extends DefaultRoutePlanner {
} }
private static int toInt(final String value, final int max) { private static int toInt(final String value, final int max) {
if (value == null || value.length() == 0) { if (value == null || value.isEmpty()) {
return max; return max;
} }

View File

@ -148,7 +148,7 @@ public class WindowsNegotiateScheme extends AuthSchemeBase {
final int endIndex) throws MalformedChallengeException { final int endIndex) throws MalformedChallengeException {
this.challenge = buffer.substringTrimmed(beginIndex, endIndex); this.challenge = buffer.substringTrimmed(beginIndex, endIndex);
if (this.challenge.length() == 0) { if (this.challenge.isEmpty()) {
if (clientCred != null) { if (clientCred != null) {
if (continueNeeded) { if (continueNeeded) {
throw new RuntimeException("Unexpected token"); throw new RuntimeException("Unexpected token");
@ -192,7 +192,7 @@ public class WindowsNegotiateScheme extends AuthSchemeBase {
dispose(); dispose();
throw new AuthenticationException("Authentication Failed", t); throw new AuthenticationException("Authentication Failed", t);
} }
} else if (this.challenge == null || this.challenge.length() == 0) { } else if (this.challenge == null || this.challenge.isEmpty()) {
dispose(); dispose();
throw new AuthenticationException("Authentication Failed"); throw new AuthenticationException("Authentication Failed");
} else { } else {

View File

@ -59,7 +59,7 @@ public class NTUserPrincipal implements Principal, Serializable {
} else { } else {
this.domain = null; this.domain = null;
} }
if (this.domain != null && this.domain.length() > 0) { if (this.domain != null && !this.domain.isEmpty()) {
final StringBuilder buffer = new StringBuilder(); final StringBuilder buffer = new StringBuilder();
buffer.append(this.domain); buffer.append(this.domain);
buffer.append('\\'); buffer.append('\\');

View File

@ -85,7 +85,7 @@ public abstract class HttpRequestBase extends AbstractExecutionAwareRequest
if (uri != null) { if (uri != null) {
uritext = uri.toASCIIString(); uritext = uri.toASCIIString();
} }
if (uritext == null || uritext.length() == 0) { if (uritext == null || uritext.isEmpty()) {
uritext = "/"; uritext = "/";
} }
return new BasicRequestLine(method, uritext, ver); return new BasicRequestLine(method, uritext, ver);

View File

@ -110,7 +110,7 @@ public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRe
} else { } else {
requestUri = this.original.getRequestLine().getUri(); requestUri = this.original.getRequestLine().getUri();
} }
if (requestUri == null || requestUri.length() == 0) { if (requestUri == null || requestUri.isEmpty()) {
requestUri = "/"; requestUri = "/";
} }
return new BasicRequestLine(this.method, requestUri, getProtocolVersion()); return new BasicRequestLine(this.method, requestUri, getProtocolVersion());

View File

@ -50,7 +50,7 @@ public class CloneUtils {
final Class<?> clazz = obj.getClass (); final Class<?> clazz = obj.getClass ();
final Method m; final Method m;
try { try {
m = clazz.getMethod("clone", (Class[]) null); m = clazz.getMethod("clone", (Class<?>[]) null);
} catch (final NoSuchMethodException ex) { } catch (final NoSuchMethodException ex) {
throw new NoSuchMethodError(ex.getMessage()); throw new NoSuchMethodError(ex.getMessage());
} }

View File

@ -105,11 +105,11 @@ public class Rfc3492Idn implements Idn {
input = input.substring(lastdelim + 1); input = input.substring(lastdelim + 1);
} }
while (input.length() > 0) { while (!input.isEmpty()) {
final int oldi = i; final int oldi = i;
int w = 1; int w = 1;
for (int k = base;; k += base) { for (int k = base;; k += base) {
if (input.length() == 0) { if (input.isEmpty()) {
break; break;
} }
final char c = input.charAt(0); final char c = input.charAt(0);

View File

@ -91,7 +91,7 @@ public class URIBuilder {
} }
private List <NameValuePair> parseQuery(final String query, final Charset charset) { private List <NameValuePair> parseQuery(final String query, final Charset charset) {
if (query != null && query.length() > 0) { if (query != null && !query.isEmpty()) {
return URLEncodedUtils.parse(query, charset); return URLEncodedUtils.parse(query, charset);
} }
return null; return null;

View File

@ -223,7 +223,7 @@ public class URIUtils {
if (s.startsWith("?")) { if (s.startsWith("?")) {
return resolveReferenceStartingWithQueryString(baseURI, ref); return resolveReferenceStartingWithQueryString(baseURI, ref);
} }
final boolean emptyReference = s.length() == 0; final boolean emptyReference = s.isEmpty();
if (emptyReference) { if (emptyReference) {
ref = URI.create("#"); ref = URI.create("#");
} }
@ -268,7 +268,7 @@ public class URIUtils {
final String[] inputSegments = path.split("/"); final String[] inputSegments = path.split("/");
final Stack<String> outputSegments = new Stack<String>(); final Stack<String> outputSegments = new Stack<String>();
for (final String inputSegment : inputSegments) { for (final String inputSegment : inputSegments) {
if ((inputSegment.length() == 0) if ((inputSegment.isEmpty())
|| (".".equals(inputSegment))) { || (".".equals(inputSegment))) {
// Do nothing // Do nothing
} else if ("..".equals(inputSegment)) { } else if ("..".equals(inputSegment)) {

View File

@ -86,7 +86,7 @@ public class URLEncodedUtils {
*/ */
public static List <NameValuePair> parse(final URI uri, final String charset) { public static List <NameValuePair> parse(final URI uri, final String charset) {
final String query = uri.getRawQuery(); final String query = uri.getRawQuery();
if (query != null && query.length() > 0) { if (query != null && !query.isEmpty()) {
final List<NameValuePair> result = new ArrayList<NameValuePair>(); final List<NameValuePair> result = new ArrayList<NameValuePair>();
final Scanner scanner = new Scanner(query); final Scanner scanner = new Scanner(query);
parse(result, scanner, QP_SEP_PATTERN, charset); parse(result, scanner, QP_SEP_PATTERN, charset);
@ -112,7 +112,7 @@ public class URLEncodedUtils {
final ContentType contentType = ContentType.get(entity); final ContentType contentType = ContentType.get(entity);
if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) { if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) {
final String content = EntityUtils.toString(entity, Consts.ASCII); final String content = EntityUtils.toString(entity, Consts.ASCII);
if (content != null && content.length() > 0) { if (content != null && !content.isEmpty()) {
Charset charset = contentType.getCharset(); Charset charset = contentType.getCharset();
if (charset == null) { if (charset == null) {
charset = HTTP.DEF_CONTENT_CHARSET; charset = HTTP.DEF_CONTENT_CHARSET;
@ -247,7 +247,7 @@ public class URLEncodedUtils {
final List<NameValuePair> list = new ArrayList<NameValuePair>(); final List<NameValuePair> list = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) { while (!cursor.atEnd()) {
final NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, parameterSeparator); final NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, parameterSeparator);
if (nvp.getName().length() > 0) { if (!nvp.getName().isEmpty()) {
list.add(new BasicNameValuePair( list.add(new BasicNameValuePair(
decodeFormFields(nvp.getName(), charset), decodeFormFields(nvp.getName(), charset),
decodeFormFields(nvp.getValue(), charset))); decodeFormFields(nvp.getValue(), charset)));

View File

@ -52,7 +52,7 @@ public final class CookieOrigin {
Args.notNull(path, "Path"); Args.notNull(path, "Path");
this.host = host.toLowerCase(Locale.ENGLISH); this.host = host.toLowerCase(Locale.ENGLISH);
this.port = port; this.port = port;
if (path.trim().length() != 0) { if (!path.trim().isEmpty()) {
this.path = path; this.path = path;
} else { } else {
this.path = "/"; this.path = "/";

View File

@ -104,7 +104,7 @@ public class NTLMScheme extends AuthSchemeBase {
final CharArrayBuffer buffer, final CharArrayBuffer buffer,
final int beginIndex, final int endIndex) throws MalformedChallengeException { final int beginIndex, final int endIndex) throws MalformedChallengeException {
this.challenge = buffer.substringTrimmed(beginIndex, endIndex); this.challenge = buffer.substringTrimmed(beginIndex, endIndex);
if (this.challenge.length() == 0) { if (this.challenge.isEmpty()) {
if (this.state == State.UNINITIATED) { if (this.state == State.UNINITIATED) {
this.state = State.CHALLENGE_RECEIVED; this.state = State.CHALLENGE_RECEIVED;
} else { } else {

View File

@ -116,7 +116,7 @@ public abstract class CloseableHttpClient implements HttpClient, Closeable {
public CloseableHttpResponse execute( public CloseableHttpResponse execute(
final HttpHost target, final HttpHost target,
final HttpRequest request) throws IOException, ClientProtocolException { final HttpRequest request) throws IOException, ClientProtocolException {
return doExecute(target, request, (HttpContext) null); return doExecute(target, request, null);
} }
/** /**

View File

@ -135,7 +135,7 @@ public class RequestWrapper extends AbstractHttpMessage implements HttpUriReques
if (uri != null) { if (uri != null) {
uritext = uri.toASCIIString(); uritext = uri.toASCIIString();
} }
if (uritext == null || uritext.length() == 0) { if (uritext == null || uritext.isEmpty()) {
uritext = "/"; uritext = "/";
} }
return new BasicRequestLine(method, uritext, ver); return new BasicRequestLine(method, uritext, ver);

View File

@ -53,7 +53,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (value == null) { if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute"); throw new MalformedCookieException("Missing value for domain attribute");
} }
if (value.trim().length() == 0) { if (value.trim().isEmpty()) {
throw new MalformedCookieException("Blank value for domain attribute"); throw new MalformedCookieException("Blank value for domain attribute");
} }
cookie.setDomain(value); cookie.setDomain(value);

View File

@ -72,7 +72,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
for (final HeaderElement headerelement : elems) { for (final HeaderElement headerelement : elems) {
final String name = headerelement.getName(); final String name = headerelement.getName();
final String value = headerelement.getValue(); final String value = headerelement.getValue();
if (name == null || name.length() == 0) { if (name == null || name.isEmpty()) {
throw new MalformedCookieException("Cookie name may not be empty"); throw new MalformedCookieException("Cookie name may not be empty");
} }

View File

@ -128,7 +128,7 @@ public class PublicSuffixFilter implements CookieAttributeHandler {
break; break;
} }
domain = "*" + domain.substring(nextdot); domain = "*" + domain.substring(nextdot);
} while (domain.length() > 0); } while (!domain.isEmpty());
return false; return false;
} }

View File

@ -66,7 +66,7 @@ public class PublicSuffixListParser {
while (more) { while (more) {
more = readLine(r, sb); more = readLine(r, sb);
String line = sb.toString(); String line = sb.toString();
if (line.length() == 0) { if (line.isEmpty()) {
continue; continue;
} }
if (line.startsWith("//")) if (line.startsWith("//"))

View File

@ -55,7 +55,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
if (value == null) { if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute"); throw new MalformedCookieException("Missing value for domain attribute");
} }
if (value.trim().length() == 0) { if (value.trim().isEmpty()) {
throw new MalformedCookieException("Blank value for domain attribute"); throw new MalformedCookieException("Blank value for domain attribute");
} }
cookie.setDomain(value); cookie.setDomain(value);

View File

@ -52,7 +52,7 @@ public class RFC2109VersionHandler extends AbstractCookieAttributeHandler {
if (value == null) { if (value == null) {
throw new MalformedCookieException("Missing value for version attribute"); throw new MalformedCookieException("Missing value for version attribute");
} }
if (value.trim().length() == 0) { if (value.trim().isEmpty()) {
throw new MalformedCookieException("Blank value for version attribute"); throw new MalformedCookieException("Blank value for version attribute");
} }
try { try {

View File

@ -63,7 +63,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
throw new MalformedCookieException( throw new MalformedCookieException(
"Missing value for domain attribute"); "Missing value for domain attribute");
} }
if (domain.trim().length() == 0) { if (domain.trim().isEmpty()) {
throw new MalformedCookieException( throw new MalformedCookieException(
"Blank value for domain attribute"); "Blank value for domain attribute");
} }

View File

@ -110,7 +110,7 @@ public class RFC2965PortAttributeHandler implements CookieAttributeHandler {
Args.notNull(cookie, "Cookie"); Args.notNull(cookie, "Cookie");
if (cookie instanceof SetCookie2) { if (cookie instanceof SetCookie2) {
final SetCookie2 cookie2 = (SetCookie2) cookie; final SetCookie2 cookie2 = (SetCookie2) cookie;
if (portValue != null && portValue.trim().length() > 0) { if (portValue != null && !portValue.trim().isEmpty()) {
final int[] ports = parsePortAttribute(portValue); final int[] ports = parsePortAttribute(portValue);
cookie2.setPorts(ports); cookie2.setPorts(ports);
} }

View File

@ -99,7 +99,7 @@ public class RFC2965Spec extends RFC2109Spec {
for (final HeaderElement headerelement : elems) { for (final HeaderElement headerelement : elems) {
final String name = headerelement.getName(); final String name = headerelement.getName();
final String value = headerelement.getValue(); final String value = headerelement.getValue();
if (name == null || name.length() == 0) { if (name == null || name.isEmpty()) {
throw new MalformedCookieException("Cookie name may not be empty"); throw new MalformedCookieException("Cookie name may not be empty");
} }
@ -163,7 +163,7 @@ public class RFC2965Spec extends RFC2109Spec {
if (s != null) { if (s != null) {
buffer.append("; $Port"); buffer.append("; $Port");
buffer.append("=\""); buffer.append("=\"");
if (s.trim().length() > 0) { if (!s.trim().isEmpty()) {
final int[] ports = cookie.getPorts(); final int[] ports = cookie.getPorts();
if (ports != null) { if (ports != null) {
final int len = ports.length; final int len = ports.length;

View File

@ -119,7 +119,7 @@ public class TestExceptions {
public void testConnectionPoolTimeoutException() { public void testConnectionPoolTimeoutException() {
final String msg = "sample exception message"; final String msg = "sample exception message";
ConnectionPoolTimeoutException cptx = new ConnectionPoolTimeoutException(msg); ConnectionPoolTimeoutException cptx = new ConnectionPoolTimeoutException(msg);
Assert.assertFalse(cptx.toString().indexOf(msg) < 0); Assert.assertFalse(!cptx.toString().contains(msg));
Assert.assertSame(msg, cptx.getMessage()); Assert.assertSame(msg, cptx.getMessage());
cptx = new ConnectionPoolTimeoutException(); cptx = new ConnectionPoolTimeoutException();

View File

@ -111,15 +111,15 @@ public class TestHttpRoute {
final String routestr = route.toString(); final String routestr = route.toString();
Assert.assertTrue("missing target in toString", Assert.assertTrue("missing target in toString",
routestr.indexOf(TARGET1.getHostName()) >= 0); routestr.contains(TARGET1.getHostName()));
Assert.assertTrue("missing local address in toString", Assert.assertTrue("missing local address in toString",
routestr.indexOf(LOCAL41.toString()) >= 0); routestr.contains(LOCAL41.toString()));
Assert.assertTrue("missing proxy 1 in toString", Assert.assertTrue("missing proxy 1 in toString",
routestr.indexOf(PROXY1.getHostName()) >= 0); routestr.contains(PROXY1.getHostName()));
Assert.assertTrue("missing proxy 2 in toString", Assert.assertTrue("missing proxy 2 in toString",
routestr.indexOf(PROXY2.getHostName()) >= 0); routestr.contains(PROXY2.getHostName()));
Assert.assertTrue("missing proxy 3 in toString", Assert.assertTrue("missing proxy 3 in toString",
routestr.indexOf(PROXY3.getHostName()) >= 0); routestr.contains(PROXY3.getHostName()));
} }
@Test @Test

View File

@ -701,13 +701,13 @@ public class TestRouteTracker {
if (rt.getLocalAddress() != null) { if (rt.getLocalAddress() != null) {
final String las = rt.getLocalAddress().toString(); final String las = rt.getLocalAddress().toString();
Assert.assertFalse("no local address in toString(): " + rts, Assert.assertFalse("no local address in toString(): " + rts,
rts.indexOf(las) < 0); !rts.contains(las));
} }
for (int i=0; i<rt.getHopCount(); i++) { for (int i=0; i<rt.getHopCount(); i++) {
final String hts = rt.getHopTarget(i).toString(); final String hts = rt.getHopTarget(i).toString();
Assert.assertFalse("hop "+i+" ("+hts+") missing in toString(): " + rts, Assert.assertFalse("hop "+i+" ("+hts+") missing in toString(): " + rts,
rts.indexOf(hts) < 0); !rts.contains(hts));
} }
return rts; return rts;

View File

@ -307,13 +307,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>clirr-maven-plugin</artifactId>
<configuration>
<comparisonVersion>${api.comparison.version}</comparisonVersion>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId> <artifactId>maven-checkstyle-plugin</artifactId>