Prefer entrySet and entries over keySet and keys

Also use type inference for ImmutableMultimap.Builder.
This commit is contained in:
Andrew Gaul 2012-03-19 22:38:17 -07:00
parent 73749de4e3
commit 8ad10fabaf
1 changed files with 8 additions and 7 deletions

View File

@ -39,6 +39,8 @@ import java.net.Proxy;
import java.net.ProxySelector; import java.net.ProxySelector;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -125,11 +127,12 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
builder.statusCode(responseCode); builder.statusCode(responseCode);
builder.message(connection.getResponseMessage()); builder.message(connection.getResponseMessage());
Builder<String, String> headerBuilder = ImmutableMultimap.<String, String> builder(); Builder<String, String> headerBuilder = ImmutableMultimap.builder();
for (String header : connection.getHeaderFields().keySet()) { for (Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet()) {
String header = entry.getKey();
// HTTP message comes back as a header without a key // HTTP message comes back as a header without a key
if (header != null) if (header != null)
headerBuilder.putAll(header, connection.getHeaderFields().get(header)); headerBuilder.putAll(header, entry.getValue());
} }
ImmutableMultimap<String, String> headers = headerBuilder.build(); ImmutableMultimap<String, String> headers = headerBuilder.build();
Payload payload = in != null ? newInputStreamPayload(in) : null; Payload payload = in != null ? newInputStreamPayload(in) : null;
@ -204,10 +207,8 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
} }
} }
for (String header : request.getHeaders().keys()) { for (Map.Entry<String, String> entry : request.getHeaders().entries()) {
for (String value : request.getHeaders().get(header)) { connection.setRequestProperty(entry.getKey(), entry.getValue());
connection.setRequestProperty(header, value);
}
} }
connection.setRequestProperty(HttpHeaders.HOST, request.getEndpoint().getHost()); connection.setRequestProperty(HttpHeaders.HOST, request.getEndpoint().getHost());
connection.setRequestProperty(HttpHeaders.USER_AGENT, USER_AGENT); connection.setRequestProperty(HttpHeaders.USER_AGENT, USER_AGENT);