Minor Improvements:

* Use Empty collections
* Unnecessary toString
This commit is contained in:
Arturo Bernal 2021-01-25 20:12:15 +01:00 committed by Oleg Kalnichevski
parent b71e2fcb83
commit 3c9f1f85e1
6 changed files with 16 additions and 6 deletions

View File

@ -98,7 +98,7 @@ public class CacheKeyGenerator implements Resolver<URI, String> {
if (headers == null) { if (headers == null) {
return ""; return "";
} }
final StringBuilder buf = new StringBuilder(""); final StringBuilder buf = new StringBuilder();
for (int i = 0; i < headers.length; i++) { for (int i = 0; i < headers.length; i++) {
final Header hdr = headers[i]; final Header hdr = headers[i];
if (i > 0) { if (i > 0) {

View File

@ -121,7 +121,7 @@ class RequestProtocolCompliance {
} }
private String buildHeaderFromElements(final List<HeaderElement> outElts) { private String buildHeaderFromElements(final List<HeaderElement> outElts) {
final StringBuilder newHdr = new StringBuilder(""); final StringBuilder newHdr = new StringBuilder();
boolean first = true; boolean first = true;
for(final HeaderElement elt : outElts) { for(final HeaderElement elt : outElts) {
if (!first) { if (!first) {

View File

@ -96,7 +96,7 @@ public class AsyncRandomHandler implements AsyncServerExchangeHandler {
final String path = uri.getPath(); final String path = uri.getPath();
final int slash = path.lastIndexOf('/'); final int slash = path.lastIndexOf('/');
if (slash != -1) { if (slash != -1) {
final String payload = path.substring(slash + 1, path.length()); final String payload = path.substring(slash + 1);
final long n; final long n;
if (!payload.isEmpty()) { if (!payload.isEmpty()) {
try { try {

View File

@ -87,7 +87,7 @@ public class RandomHandler implements HttpRequestHandler {
final String path = uri.getPath(); final String path = uri.getPath();
final int slash = path.lastIndexOf('/'); final int slash = path.lastIndexOf('/');
if (slash != -1) { if (slash != -1) {
final String payload = path.substring(slash + 1, path.length()); final String payload = path.substring(slash + 1);
final long n; final long n;
if (!payload.isEmpty()) { if (!payload.isEmpty()) {
try { try {

View File

@ -63,6 +63,11 @@ public class MultipartEntityBuilder {
private Charset charset; private Charset charset;
private List<MultipartPart> multipartParts; private List<MultipartPart> multipartParts;
/**
* An empty immutable {@code NameValuePair} array.
*/
private static final NameValuePair[] EMPTY_NAME_VALUE_ARRAY = new NameValuePair[0];
public static MultipartEntityBuilder create() { public static MultipartEntityBuilder create() {
return new MultipartEntityBuilder(); return new MultipartEntityBuilder();
} }
@ -201,7 +206,7 @@ public class MultipartEntityBuilder {
if (charsetCopy != null) { if (charsetCopy != null) {
paramsList.add(new BasicNameValuePair("charset", charsetCopy.name())); paramsList.add(new BasicNameValuePair("charset", charsetCopy.name()));
} }
final NameValuePair[] params = paramsList.toArray(new NameValuePair[paramsList.size()]); final NameValuePair[] params = paramsList.toArray(EMPTY_NAME_VALUE_ARRAY);
final ContentType contentTypeCopy; final ContentType contentTypeCopy;
if (contentType != null) { if (contentType != null) {

View File

@ -75,13 +75,18 @@ public final class ContentCompressionExec implements ExecChainHandler {
private final Lookup<InputStreamFactory> decoderRegistry; private final Lookup<InputStreamFactory> decoderRegistry;
private final boolean ignoreUnknown; private final boolean ignoreUnknown;
/**
* An empty immutable {@code String} array.
*/
private static final String[] EMPTY_STRING_ARRAY = new String[0];
public ContentCompressionExec( public ContentCompressionExec(
final List<String> acceptEncoding, final List<String> acceptEncoding,
final Lookup<InputStreamFactory> decoderRegistry, final Lookup<InputStreamFactory> decoderRegistry,
final boolean ignoreUnknown) { final boolean ignoreUnknown) {
this.acceptEncoding = MessageSupport.format(HttpHeaders.ACCEPT_ENCODING, this.acceptEncoding = MessageSupport.format(HttpHeaders.ACCEPT_ENCODING,
acceptEncoding != null ? acceptEncoding.toArray( acceptEncoding != null ? acceptEncoding.toArray(
new String[acceptEncoding.size()]) : new String[] {"gzip", "x-gzip", "deflate"}); EMPTY_STRING_ARRAY) : new String[] {"gzip", "x-gzip", "deflate"});
this.decoderRegistry = decoderRegistry != null ? decoderRegistry : this.decoderRegistry = decoderRegistry != null ? decoderRegistry :
RegistryBuilder.<InputStreamFactory>create() RegistryBuilder.<InputStreamFactory>create()