Simplify conditions and avoid extra checks.

Inline return variables.
This commit is contained in:
Arturo Bernal 2021-06-13 17:35:55 +02:00 committed by Oleg Kalnichevski
parent 0805cfe582
commit fde3fca687
8 changed files with 16 additions and 53 deletions

View File

@ -84,10 +84,7 @@ public boolean matches(final Object item) {
final byte[] expectedContent = expectedResource != null ? expectedResource.get() : null;
final Resource otherResource = otherValue.getResource();
final byte[] otherContent = otherResource != null ? otherResource.get() : null;
if (!Arrays.equals(expectedContent, otherContent)) {
return false;
}
return true;
return Arrays.equals(expectedContent, otherContent);
} catch (final ResourceIOException ex) {
throw new RuntimeException(ex);
}

View File

@ -258,9 +258,8 @@ public static HttpCacheEntry makeCacheEntry(final Date requestDate,
public static HttpCacheEntry makeCacheEntry(final Date requestDate,
final Date responseDate, final Header[] headers, final byte[] bytes) {
final Map<String,String> variantMap = null;
return makeCacheEntry(requestDate, responseDate, headers, bytes,
variantMap);
null);
}
public static HttpCacheEntry makeCacheEntry(final Map<String,String> variantMap) {

View File

@ -37,8 +37,6 @@
import org.apache.hc.core5.http.config.Registry;
import org.apache.hc.core5.http.config.RegistryBuilder;
import com.sun.jna.platform.win32.Sspi;
/**
* Factory methods for {@link org.apache.hc.client5.http.impl.classic.CloseableHttpClient} instances configured to use integrated
* Windows authentication by default.
@ -54,14 +52,7 @@ private WinHttpClients() {
public static boolean isWinAuthAvailable() {
String os = System.getProperty("os.name");
os = os != null ? os.toLowerCase(Locale.ROOT) : null;
if (os != null && os.contains("windows")) {
try {
return Sspi.MAX_TOKEN_SIZE > 0;
} catch (final Exception ignore) {
// Likely ClassNotFound
}
}
return false;
return os != null && os.contains("windows");
}
private static HttpClientBuilder createBuilder() {

View File

@ -239,9 +239,6 @@ private String getServicePrincipalName(final HttpRequest request, final HttpClie
final RouteInfo route = clientContext.getHttpRoute();
if (route != null) {
spn = "HTTP/" + route.getProxyHost().getHostName();
} else {
// Should not happen
spn = null;
}
} else {
final URIAuthority authority = request.getAuthority();
@ -251,9 +248,6 @@ private String getServicePrincipalName(final HttpRequest request, final HttpClie
final RouteInfo route = clientContext.getHttpRoute();
if (route != null) {
spn = "HTTP/" + route.getTargetHost().getHostName();
} else {
// Should not happen
spn = null;
}
}
}

View File

@ -687,9 +687,6 @@ private static byte[] lmHash(final char[] password) throws NTLMEngineException {
* the NTLM Response and the NTLMv2 and LMv2 Hashes.
*/
private static byte[] ntlmHash(final char[] password) throws NTLMEngineException {
if (UNICODE_LITTLE_UNMARKED == null) {
throw new NTLMEngineException("Unicode not supported");
}
final byte[] unicodePassword = new ByteArrayBuilder()
.charset(UNICODE_LITTLE_UNMARKED).append(password).toByteArray();
final MD4 md4 = new MD4();
@ -705,9 +702,6 @@ private static byte[] ntlmHash(final char[] password) throws NTLMEngineException
*/
private static byte[] lmv2Hash(final String domain, final String user, final byte[] ntlmHash)
throws NTLMEngineException {
if (UNICODE_LITTLE_UNMARKED == null) {
throw new NTLMEngineException("Unicode not supported");
}
final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
// Upper case username, upper case domain!
hmacMD5.update(user.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
@ -725,9 +719,6 @@ private static byte[] lmv2Hash(final String domain, final String user, final byt
*/
private static byte[] ntlmv2Hash(final String domain, final String user, final byte[] ntlmHash)
throws NTLMEngineException {
if (UNICODE_LITTLE_UNMARKED == null) {
throw new NTLMEngineException("Unicode not supported");
}
final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
// Upper case username, mixed case target!!
hmacMD5.update(user.toUpperCase(Locale.ROOT).getBytes(UNICODE_LITTLE_UNMARKED));
@ -1071,9 +1062,6 @@ private static Charset getCharset(final int flags) throws NTLMEngineException
if ((flags & FLAG_REQUEST_UNICODE_ENCODING) == 0) {
return DEFAULT_CHARSET;
}
if (UNICODE_LITTLE_UNMARKED == null) {
throw new NTLMEngineException( "Unicode not supported" );
}
return UNICODE_LITTLE_UNMARKED;
}

View File

@ -44,9 +44,7 @@ public ContentTypeMatcher(final ContentType contentType) {
public boolean matches(final Object item) {
if (item instanceof ContentType) {
final ContentType contentType = (ContentType) item;
if (contentType.isSameMimeType(expectedContentType)) {
return true;
}
return contentType.isSameMimeType(expectedContentType);
}
return false;
}

View File

@ -47,9 +47,7 @@ public HeaderMatcher(final String headerName, final Object headerValue) {
public boolean matches(final Object item) {
if (item instanceof Header) {
final Header header = (Header) item;
if (headerName.equalsIgnoreCase(header.getName()) && LangUtils.equals(headerValue, header.getValue())) {
return true;
}
return headerName.equalsIgnoreCase(header.getName()) && LangUtils.equals(headerValue, header.getValue());
}
return false;
}

View File

@ -50,23 +50,21 @@ public NameValuePairsMatcher(final List<? extends NameValuePair> nameValuePairLi
public boolean matches(final Object item) {
if (item instanceof Collection<?>) {
final Collection<?> collection = (Collection<?>) item;
if (collection.size() == collection.size()) {
int i = 0;
for (final Object obj : collection) {
if (obj instanceof NameValuePair) {
final NameValuePair nvp1 = (NameValuePair) obj;
final NameValuePair nvp2 = expectedNameValuePairList.get(i);
if (!nvp1.getName().equalsIgnoreCase(nvp2.getName())
|| !LangUtils.equals(nvp1.getValue(), nvp2.getValue())) {
return false;
}
} else {
int i = 0;
for (final Object obj : collection) {
if (obj instanceof NameValuePair) {
final NameValuePair nvp1 = (NameValuePair) obj;
final NameValuePair nvp2 = expectedNameValuePairList.get(i);
if (!nvp1.getName().equalsIgnoreCase(nvp2.getName())
|| !LangUtils.equals(nvp1.getValue(), nvp2.getValue())) {
return false;
}
i++;
} else {
return false;
}
return true;
i++;
}
return true;
}
return false;
}