Minor Improvement:

* Avoid duplicate code
* Simplify if else
* Inline variables
This commit is contained in:
Arturo Bernal 2021-02-05 14:00:06 +01:00 committed by Oleg Kalnichevski
parent c2e6f92572
commit 0940d35602
15 changed files with 19 additions and 53 deletions

View File

@ -287,10 +287,7 @@ class CachedResponseSuitabilityChecker {
return false;
}
if (hasLastModifiedValidator && !lastModifiedValidatorMatches) {
return false;
}
return true;
return !hasLastModifiedValidator || lastModifiedValidatorMatches;
}
private boolean hasUnsupportedConditionalHeaders(final HttpRequest request) {

View File

@ -325,11 +325,7 @@ public class CachingExecBase {
}
final Header h = request.getFirstHeader(HeaderConstants.MAX_FORWARDS);
if (!"0".equals(h != null ? h.getValue() : null)) {
return false;
}
return true;
return "0".equals(h != null ? h.getValue() : null);
}
boolean revalidationResponseIsTooOld(final HttpResponse backendResponse, final HttpCacheEntry cacheEntry) {

View File

@ -159,11 +159,7 @@ class RequestProtocolCompliance {
return false;
}
if (requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor()) {
return true;
}
return false;
return requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor();
}
protected boolean requestVersionIsTooLow(final HttpRequest request) {

View File

@ -192,10 +192,7 @@ class ResponseCachingPolicy {
if (status >= 400 && status <= 417) {
return false;
}
if (status >= 500 && status <= 505) {
return false;
}
return true;
return status < 500 || status > 505;
}
protected boolean isExplicitlyNonCacheable(final HttpResponse response) {

View File

@ -119,8 +119,7 @@ class WarningValue {
* CHAR = <any US-ASCII character (octets 0 - 127)>
*/
private boolean isChar(final char c) {
final int i = c;
return (i >= 0 && i <= 127);
return ((int) c >= 0 && (int) c <= 127);
}
/*
@ -128,8 +127,7 @@ class WarningValue {
(octets 0 - 31) and DEL (127)>
*/
private boolean isControl(final char c) {
final int i = c;
return (i == 127 || (i >=0 && i <= 31));
return ((int) c == 127 || ((int) c >=0 && (int) c <= 31));
}
/*

View File

@ -87,8 +87,7 @@ public class EchoHandler implements HttpRequestHandler {
contentType = contentTypeStr == null ? null : ContentType.parse(contentTypeStr);
}
final ByteArrayEntity bae = new ByteArrayEntity(data, contentType);
entity = bae;
entity = new ByteArrayEntity(data, contentType);
response.setCode(HttpStatus.SC_OK);
response.setEntity(entity);

View File

@ -71,9 +71,7 @@ public final class BasicUserPrincipal implements Principal, Serializable {
}
if (o instanceof BasicUserPrincipal) {
final BasicUserPrincipal that = (BasicUserPrincipal) o;
if (LangUtils.equals(this.username, that.username)) {
return true;
}
return LangUtils.equals(this.username, that.username);
}
return false;
}

View File

@ -159,11 +159,9 @@ public class NTCredentials implements Credentials, Serializable {
}
if (o instanceof NTCredentials) {
final NTCredentials that = (NTCredentials) o;
if (LangUtils.equals(this.principal, that.principal)
return LangUtils.equals(this.principal, that.principal)
&& LangUtils.equals(this.workstation, that.workstation)
&& LangUtils.equals(this.netbiosDomain, that.netbiosDomain)) {
return true;
}
&& LangUtils.equals(this.netbiosDomain, that.netbiosDomain);
}
return false;
}

View File

@ -99,10 +99,8 @@ public class NTUserPrincipal implements Principal, Serializable {
}
if (o instanceof NTUserPrincipal) {
final NTUserPrincipal that = (NTUserPrincipal) o;
if (LangUtils.equals(this.username, that.username)
&& LangUtils.equals(this.domain, that.domain)) {
return true;
}
return LangUtils.equals(this.username, that.username)
&& LangUtils.equals(this.domain, that.domain);
}
return false;
}

View File

@ -87,9 +87,7 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
}
if (o instanceof UsernamePasswordCredentials) {
final UsernamePasswordCredentials that = (UsernamePasswordCredentials) o;
if (LangUtils.equals(this.principal, that.principal)) {
return true;
}
return LangUtils.equals(this.principal, that.principal);
}
return false;
}

View File

@ -333,12 +333,11 @@ public class DigestScheme implements AuthScheme, Serializable {
final String checksum = formatHex(digester.digest(this.buffer.toByteArray()));
buffer.reset();
buffer.append(checksum).append(":").append(nonce).append(":").append(cnonce);
a1 = buffer.toByteArray();
} else {
// unq(username-value) ":" unq(realm-value) ":" passwd
buffer.append(username).append(":").append(realm).append(":").append(password);
a1 = buffer.toByteArray();
}
a1 = buffer.toByteArray();
final String hasha1 = formatHex(digester.digest(a1));
buffer.reset();
@ -383,13 +382,12 @@ public class DigestScheme implements AuthScheme, Serializable {
final byte[] digestInput;
if (qop == QOP_MISSING) {
buffer.append(hasha1).append(":").append(nonce).append(":").append(hasha2);
digestInput = buffer.toByteArray();
} else {
buffer.append(hasha1).append(":").append(nonce).append(":").append(nc).append(":")
.append(cnonce).append(":").append(qop == QOP_AUTH_INT ? "auth-int" : "auth")
.append(":").append(hasha2);
digestInput = buffer.toByteArray();
}
digestInput = buffer.toByteArray();
buffer.reset();
final String digest = formatHex(digester.digest(digestInput));

View File

@ -103,9 +103,7 @@ public class BasicDomainHandler implements CommonCookieAttributeHandler {
if (prefix == 0) {
return true;
}
if (prefix > 1 && host.charAt(prefix - 1) == '.') {
return true;
}
return prefix > 1 && host.charAt(prefix - 1) == '.';
}
return false;
}

View File

@ -75,9 +75,7 @@ public class BasicPathHandler implements CommonCookieAttributeHandler {
if (uriPath.length() == normalizedCookiePath.length()) {
return true;
}
if (uriPath.charAt(normalizedCookiePath.length()) == '/') {
return true;
}
return uriPath.charAt(normalizedCookiePath.length()) == '/';
}
return false;
}

View File

@ -138,8 +138,7 @@ public final class PublicSuffixMatcher {
if (domain.startsWith(".")) {
return null;
}
final String normalized = DnsUtils.normalize(domain);
String segment = normalized;
String segment = DnsUtils.normalize(domain);
String result = null;
while (segment != null) {
// An exception rule takes priority over any other matching rule.

View File

@ -220,9 +220,7 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
if (strict) {
final String remainder = host.substring(
prefix.length(), host.length() - suffix.length());
if (remainder.contains(".")) {
return false;
}
return !remainder.contains(".");
}
return true;
}