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:
parent
594f2f4b62
commit
715a34c860
|
@ -50,6 +50,6 @@ public enum CacheResponseStatus {
|
|||
/** The response was generated from the cache after validating the
|
||||
* entry with the origin server.
|
||||
*/
|
||||
VALIDATED;
|
||||
VALIDATED
|
||||
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ public class CachingExec implements ClientExecChain {
|
|||
}
|
||||
|
||||
final Map<String, Variant> variants = getExistingCacheVariants(target, request);
|
||||
if (variants != null && variants.size() > 0) {
|
||||
if (variants != null && !variants.isEmpty()) {
|
||||
return negotiateResponseFromVariants(route, request, context,
|
||||
execAware, variants);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class TestSHA256HashingScheme {
|
|||
public void canHash() {
|
||||
final SHA256KeyHashingScheme impl = new SHA256KeyHashingScheme();
|
||||
final String result = impl.hash("hello, hashing world");
|
||||
assertTrue(result != null && result.length() > 0);
|
||||
assertTrue(result != null && !result.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ final class OSGiHttpRoutePlanner extends DefaultRoutePlanner {
|
|||
}
|
||||
|
||||
private static int toInt(final String value, final int max) {
|
||||
if (value == null || value.length() == 0) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return max;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ public class WindowsNegotiateScheme extends AuthSchemeBase {
|
|||
final int endIndex) throws MalformedChallengeException {
|
||||
this.challenge = buffer.substringTrimmed(beginIndex, endIndex);
|
||||
|
||||
if (this.challenge.length() == 0) {
|
||||
if (this.challenge.isEmpty()) {
|
||||
if (clientCred != null) {
|
||||
if (continueNeeded) {
|
||||
throw new RuntimeException("Unexpected token");
|
||||
|
@ -192,7 +192,7 @@ public class WindowsNegotiateScheme extends AuthSchemeBase {
|
|||
dispose();
|
||||
throw new AuthenticationException("Authentication Failed", t);
|
||||
}
|
||||
} else if (this.challenge == null || this.challenge.length() == 0) {
|
||||
} else if (this.challenge == null || this.challenge.isEmpty()) {
|
||||
dispose();
|
||||
throw new AuthenticationException("Authentication Failed");
|
||||
} else {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class NTUserPrincipal implements Principal, Serializable {
|
|||
} else {
|
||||
this.domain = null;
|
||||
}
|
||||
if (this.domain != null && this.domain.length() > 0) {
|
||||
if (this.domain != null && !this.domain.isEmpty()) {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(this.domain);
|
||||
buffer.append('\\');
|
||||
|
|
|
@ -85,7 +85,7 @@ public abstract class HttpRequestBase extends AbstractExecutionAwareRequest
|
|||
if (uri != null) {
|
||||
uritext = uri.toASCIIString();
|
||||
}
|
||||
if (uritext == null || uritext.length() == 0) {
|
||||
if (uritext == null || uritext.isEmpty()) {
|
||||
uritext = "/";
|
||||
}
|
||||
return new BasicRequestLine(method, uritext, ver);
|
||||
|
|
|
@ -110,7 +110,7 @@ public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRe
|
|||
} else {
|
||||
requestUri = this.original.getRequestLine().getUri();
|
||||
}
|
||||
if (requestUri == null || requestUri.length() == 0) {
|
||||
if (requestUri == null || requestUri.isEmpty()) {
|
||||
requestUri = "/";
|
||||
}
|
||||
return new BasicRequestLine(this.method, requestUri, getProtocolVersion());
|
||||
|
|
|
@ -50,7 +50,7 @@ public class CloneUtils {
|
|||
final Class<?> clazz = obj.getClass ();
|
||||
final Method m;
|
||||
try {
|
||||
m = clazz.getMethod("clone", (Class[]) null);
|
||||
m = clazz.getMethod("clone", (Class<?>[]) null);
|
||||
} catch (final NoSuchMethodException ex) {
|
||||
throw new NoSuchMethodError(ex.getMessage());
|
||||
}
|
||||
|
|
|
@ -105,11 +105,11 @@ public class Rfc3492Idn implements Idn {
|
|||
input = input.substring(lastdelim + 1);
|
||||
}
|
||||
|
||||
while (input.length() > 0) {
|
||||
while (!input.isEmpty()) {
|
||||
final int oldi = i;
|
||||
int w = 1;
|
||||
for (int k = base;; k += base) {
|
||||
if (input.length() == 0) {
|
||||
if (input.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
final char c = input.charAt(0);
|
||||
|
|
|
@ -91,7 +91,7 @@ public class URIBuilder {
|
|||
}
|
||||
|
||||
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 null;
|
||||
|
|
|
@ -223,7 +223,7 @@ public class URIUtils {
|
|||
if (s.startsWith("?")) {
|
||||
return resolveReferenceStartingWithQueryString(baseURI, ref);
|
||||
}
|
||||
final boolean emptyReference = s.length() == 0;
|
||||
final boolean emptyReference = s.isEmpty();
|
||||
if (emptyReference) {
|
||||
ref = URI.create("#");
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ public class URIUtils {
|
|||
final String[] inputSegments = path.split("/");
|
||||
final Stack<String> outputSegments = new Stack<String>();
|
||||
for (final String inputSegment : inputSegments) {
|
||||
if ((inputSegment.length() == 0)
|
||||
if ((inputSegment.isEmpty())
|
||||
|| (".".equals(inputSegment))) {
|
||||
// Do nothing
|
||||
} else if ("..".equals(inputSegment)) {
|
||||
|
|
|
@ -86,7 +86,7 @@ public class URLEncodedUtils {
|
|||
*/
|
||||
public static List <NameValuePair> parse(final URI uri, final String charset) {
|
||||
final String query = uri.getRawQuery();
|
||||
if (query != null && query.length() > 0) {
|
||||
if (query != null && !query.isEmpty()) {
|
||||
final List<NameValuePair> result = new ArrayList<NameValuePair>();
|
||||
final Scanner scanner = new Scanner(query);
|
||||
parse(result, scanner, QP_SEP_PATTERN, charset);
|
||||
|
@ -112,7 +112,7 @@ public class URLEncodedUtils {
|
|||
final ContentType contentType = ContentType.get(entity);
|
||||
if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) {
|
||||
final String content = EntityUtils.toString(entity, Consts.ASCII);
|
||||
if (content != null && content.length() > 0) {
|
||||
if (content != null && !content.isEmpty()) {
|
||||
Charset charset = contentType.getCharset();
|
||||
if (charset == null) {
|
||||
charset = HTTP.DEF_CONTENT_CHARSET;
|
||||
|
@ -247,7 +247,7 @@ public class URLEncodedUtils {
|
|||
final List<NameValuePair> list = new ArrayList<NameValuePair>();
|
||||
while (!cursor.atEnd()) {
|
||||
final NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, parameterSeparator);
|
||||
if (nvp.getName().length() > 0) {
|
||||
if (!nvp.getName().isEmpty()) {
|
||||
list.add(new BasicNameValuePair(
|
||||
decodeFormFields(nvp.getName(), charset),
|
||||
decodeFormFields(nvp.getValue(), charset)));
|
||||
|
|
|
@ -52,7 +52,7 @@ public final class CookieOrigin {
|
|||
Args.notNull(path, "Path");
|
||||
this.host = host.toLowerCase(Locale.ENGLISH);
|
||||
this.port = port;
|
||||
if (path.trim().length() != 0) {
|
||||
if (!path.trim().isEmpty()) {
|
||||
this.path = path;
|
||||
} else {
|
||||
this.path = "/";
|
||||
|
|
|
@ -104,7 +104,7 @@ public class NTLMScheme extends AuthSchemeBase {
|
|||
final CharArrayBuffer buffer,
|
||||
final int beginIndex, final int endIndex) throws MalformedChallengeException {
|
||||
this.challenge = buffer.substringTrimmed(beginIndex, endIndex);
|
||||
if (this.challenge.length() == 0) {
|
||||
if (this.challenge.isEmpty()) {
|
||||
if (this.state == State.UNINITIATED) {
|
||||
this.state = State.CHALLENGE_RECEIVED;
|
||||
} else {
|
||||
|
|
|
@ -116,7 +116,7 @@ public abstract class CloseableHttpClient implements HttpClient, Closeable {
|
|||
public CloseableHttpResponse execute(
|
||||
final HttpHost target,
|
||||
final HttpRequest request) throws IOException, ClientProtocolException {
|
||||
return doExecute(target, request, (HttpContext) null);
|
||||
return doExecute(target, request, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -135,7 +135,7 @@ public class RequestWrapper extends AbstractHttpMessage implements HttpUriReques
|
|||
if (uri != null) {
|
||||
uritext = uri.toASCIIString();
|
||||
}
|
||||
if (uritext == null || uritext.length() == 0) {
|
||||
if (uritext == null || uritext.isEmpty()) {
|
||||
uritext = "/";
|
||||
}
|
||||
return new BasicRequestLine(method, uritext, ver);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
|
|||
if (value == null) {
|
||||
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");
|
||||
}
|
||||
cookie.setDomain(value);
|
||||
|
|
|
@ -72,7 +72,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
|
|||
for (final HeaderElement headerelement : elems) {
|
||||
final String name = headerelement.getName();
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ public class PublicSuffixFilter implements CookieAttributeHandler {
|
|||
break;
|
||||
}
|
||||
domain = "*" + domain.substring(nextdot);
|
||||
} while (domain.length() > 0);
|
||||
} while (!domain.isEmpty());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class PublicSuffixListParser {
|
|||
while (more) {
|
||||
more = readLine(r, sb);
|
||||
String line = sb.toString();
|
||||
if (line.length() == 0) {
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("//"))
|
||||
|
|
|
@ -55,7 +55,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
|
|||
if (value == null) {
|
||||
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");
|
||||
}
|
||||
cookie.setDomain(value);
|
||||
|
|
|
@ -52,7 +52,7 @@ public class RFC2109VersionHandler extends AbstractCookieAttributeHandler {
|
|||
if (value == null) {
|
||||
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");
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
|
|||
throw new MalformedCookieException(
|
||||
"Missing value for domain attribute");
|
||||
}
|
||||
if (domain.trim().length() == 0) {
|
||||
if (domain.trim().isEmpty()) {
|
||||
throw new MalformedCookieException(
|
||||
"Blank value for domain attribute");
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class RFC2965PortAttributeHandler implements CookieAttributeHandler {
|
|||
Args.notNull(cookie, "Cookie");
|
||||
if (cookie instanceof SetCookie2) {
|
||||
final SetCookie2 cookie2 = (SetCookie2) cookie;
|
||||
if (portValue != null && portValue.trim().length() > 0) {
|
||||
if (portValue != null && !portValue.trim().isEmpty()) {
|
||||
final int[] ports = parsePortAttribute(portValue);
|
||||
cookie2.setPorts(ports);
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class RFC2965Spec extends RFC2109Spec {
|
|||
for (final HeaderElement headerelement : elems) {
|
||||
final String name = headerelement.getName();
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ public class RFC2965Spec extends RFC2109Spec {
|
|||
if (s != null) {
|
||||
buffer.append("; $Port");
|
||||
buffer.append("=\"");
|
||||
if (s.trim().length() > 0) {
|
||||
if (!s.trim().isEmpty()) {
|
||||
final int[] ports = cookie.getPorts();
|
||||
if (ports != null) {
|
||||
final int len = ports.length;
|
||||
|
|
|
@ -119,7 +119,7 @@ public class TestExceptions {
|
|||
public void testConnectionPoolTimeoutException() {
|
||||
final String msg = "sample exception message";
|
||||
ConnectionPoolTimeoutException cptx = new ConnectionPoolTimeoutException(msg);
|
||||
Assert.assertFalse(cptx.toString().indexOf(msg) < 0);
|
||||
Assert.assertFalse(!cptx.toString().contains(msg));
|
||||
Assert.assertSame(msg, cptx.getMessage());
|
||||
|
||||
cptx = new ConnectionPoolTimeoutException();
|
||||
|
|
|
@ -111,15 +111,15 @@ public class TestHttpRoute {
|
|||
|
||||
final String routestr = route.toString();
|
||||
Assert.assertTrue("missing target in toString",
|
||||
routestr.indexOf(TARGET1.getHostName()) >= 0);
|
||||
routestr.contains(TARGET1.getHostName()));
|
||||
Assert.assertTrue("missing local address in toString",
|
||||
routestr.indexOf(LOCAL41.toString()) >= 0);
|
||||
routestr.contains(LOCAL41.toString()));
|
||||
Assert.assertTrue("missing proxy 1 in toString",
|
||||
routestr.indexOf(PROXY1.getHostName()) >= 0);
|
||||
routestr.contains(PROXY1.getHostName()));
|
||||
Assert.assertTrue("missing proxy 2 in toString",
|
||||
routestr.indexOf(PROXY2.getHostName()) >= 0);
|
||||
routestr.contains(PROXY2.getHostName()));
|
||||
Assert.assertTrue("missing proxy 3 in toString",
|
||||
routestr.indexOf(PROXY3.getHostName()) >= 0);
|
||||
routestr.contains(PROXY3.getHostName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -701,13 +701,13 @@ public class TestRouteTracker {
|
|||
if (rt.getLocalAddress() != null) {
|
||||
final String las = rt.getLocalAddress().toString();
|
||||
Assert.assertFalse("no local address in toString(): " + rts,
|
||||
rts.indexOf(las) < 0);
|
||||
!rts.contains(las));
|
||||
}
|
||||
|
||||
for (int i=0; i<rt.getHopCount(); i++) {
|
||||
final String hts = rt.getHopTarget(i).toString();
|
||||
Assert.assertFalse("hop "+i+" ("+hts+") missing in toString(): " + rts,
|
||||
rts.indexOf(hts) < 0);
|
||||
!rts.contains(hts));
|
||||
}
|
||||
|
||||
return rts;
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -307,13 +307,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>clirr-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<comparisonVersion>${api.comparison.version}</comparisonVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
|
|
Loading…
Reference in New Issue