Stop using ImmutableMap#entrySet

This is the first in a series of changes that will support banning Guava's
ImmutableSet.

Original commit: elastic/x-pack-elasticsearch@7f95900186
This commit is contained in:
Nik Everett 2015-09-22 16:49:10 -04:00
parent 138582db2a
commit f5398a739a
6 changed files with 37 additions and 27 deletions

View File

@ -90,7 +90,7 @@ public interface Permission {
* is configured for any group also the allowed fields and role queries are resolved. * is configured for any group also the allowed fields and role queries are resolved.
*/ */
public IndicesAccessControl authorize(String action, Set<String> requestedIndicesOrAliases, MetaData metaData) { public IndicesAccessControl authorize(String action, Set<String> requestedIndicesOrAliases, MetaData metaData) {
ImmutableMap<String, IndicesAccessControl.IndexAccessControl> indexPermissions = indices.authorize( Map<String, IndicesAccessControl.IndexAccessControl> indexPermissions = indices.authorize(
action, requestedIndicesOrAliases, metaData action, requestedIndicesOrAliases, metaData
); );
@ -283,8 +283,7 @@ public interface Permission {
} }
static interface Indices extends Permission, Iterable<Indices.Group> { static interface Indices extends Permission, Iterable<Indices.Group> {
Map<String, IndicesAccessControl.IndexAccessControl> authorize(String action, Set<String> requestedIndicesOrAliases, MetaData metaData);
ImmutableMap<String, IndicesAccessControl.IndexAccessControl> authorize(String action, Set<String> requestedIndicesOrAliases, MetaData metaData);
public static class Core implements Indices { public static class Core implements Indices {
@ -455,7 +454,7 @@ public interface Permission {
// What this code does is just merge `IndexAccessControl` instances from the permissions this class holds: // What this code does is just merge `IndexAccessControl` instances from the permissions this class holds:
Map<String, IndicesAccessControl.IndexAccessControl> indicesAccessControl = null; Map<String, IndicesAccessControl.IndexAccessControl> indicesAccessControl = null;
for (Global permission : globals) { for (Global permission : globals) {
ImmutableMap<String, IndicesAccessControl.IndexAccessControl> temp = permission.indices().authorize(action, requestedIndicesOrAliases, metaData); Map<String, IndicesAccessControl.IndexAccessControl> temp = permission.indices().authorize(action, requestedIndicesOrAliases, metaData);
if (indicesAccessControl == null) { if (indicesAccessControl == null) {
indicesAccessControl = new HashMap<>(temp); indicesAccessControl = new HashMap<>(temp);
} else { } else {

View File

@ -5,12 +5,14 @@
*/ */
package org.elasticsearch.shield.authz.accesscontrol; package org.elasticsearch.shield.authz.accesscontrol;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@ -18,12 +20,12 @@ import java.util.Set;
*/ */
public class IndicesAccessControl { public class IndicesAccessControl {
public static final IndicesAccessControl ALLOW_ALL = new IndicesAccessControl(true, ImmutableMap.<String, IndexAccessControl>of()); public static final IndicesAccessControl ALLOW_ALL = new IndicesAccessControl(true, Collections.emptyMap());
private final boolean granted; private final boolean granted;
private final ImmutableMap<String, IndexAccessControl> indexPermissions; private final Map<String, IndexAccessControl> indexPermissions;
public IndicesAccessControl(boolean granted, ImmutableMap<String, IndexAccessControl> indexPermissions) { public IndicesAccessControl(boolean granted, Map<String, IndexAccessControl> indexPermissions) {
this.granted = granted; this.granted = granted;
this.indexPermissions = indexPermissions; this.indexPermissions = indexPermissions;
} }

View File

@ -24,6 +24,8 @@ import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap;
public class HttpRequest implements ToXContent { public class HttpRequest implements ToXContent {
final String host; final String host;
@ -31,8 +33,8 @@ public class HttpRequest implements ToXContent {
final Scheme scheme; final Scheme scheme;
final HttpMethod method; final HttpMethod method;
final @Nullable String path; final @Nullable String path;
final ImmutableMap<String, String> params; final Map<String, String> params;
final ImmutableMap<String, String> headers; final Map<String, String> headers;
final @Nullable HttpAuth auth; final @Nullable HttpAuth auth;
final @Nullable String body; final @Nullable String body;
final @Nullable TimeValue connectionTimeout; final @Nullable TimeValue connectionTimeout;
@ -46,8 +48,8 @@ public class HttpRequest implements ToXContent {
this.scheme = scheme != null ? scheme : Scheme.HTTP; this.scheme = scheme != null ? scheme : Scheme.HTTP;
this.method = method != null ? method : HttpMethod.GET; this.method = method != null ? method : HttpMethod.GET;
this.path = path; this.path = path;
this.params = params != null ? params : ImmutableMap.<String, String>of(); this.params = params != null ? params : emptyMap();
this.headers = headers != null ? headers : ImmutableMap.<String, String>of(); this.headers = headers != null ? headers : emptyMap();
this.auth = auth; this.auth = auth;
this.body = body; this.body = body;
this.connectionTimeout = connectionTimeout; this.connectionTimeout = connectionTimeout;

View File

@ -24,9 +24,12 @@ import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpHeaders;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap;
/** /**
*/ */
public class HttpRequestTemplate implements ToXContent { public class HttpRequestTemplate implements ToXContent {
@ -36,8 +39,8 @@ public class HttpRequestTemplate implements ToXContent {
private final int port; private final int port;
private final HttpMethod method; private final HttpMethod method;
private final TextTemplate path; private final TextTemplate path;
private final ImmutableMap<String, TextTemplate> params; private final Map<String, TextTemplate> params;
private final ImmutableMap<String, TextTemplate> headers; private final Map<String, TextTemplate> headers;
private final HttpAuth auth; private final HttpAuth auth;
private final TextTemplate body; private final TextTemplate body;
private final @Nullable TimeValue connectionTimeout; private final @Nullable TimeValue connectionTimeout;
@ -51,8 +54,8 @@ public class HttpRequestTemplate implements ToXContent {
this.scheme = scheme != null ? scheme :Scheme.HTTP; this.scheme = scheme != null ? scheme :Scheme.HTTP;
this.method = method != null ? method : HttpMethod.GET; this.method = method != null ? method : HttpMethod.GET;
this.path = path; this.path = path;
this.params = params != null ? ImmutableMap.copyOf(params) : ImmutableMap.<String, TextTemplate>of(); this.params = params != null ? ImmutableMap.copyOf(params) : emptyMap();
this.headers = headers != null ? ImmutableMap.copyOf(headers) : ImmutableMap.<String, TextTemplate>of(); this.headers = headers != null ? ImmutableMap.copyOf(headers) : emptyMap();
this.auth = auth; this.auth = auth;
this.body = body; this.body = body;
this.connectionTimeout = connectionTimeout; this.connectionTimeout = connectionTimeout;

View File

@ -18,31 +18,35 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpHeaders;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static java.util.Collections.emptyMap;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class HttpResponse implements ToXContent { public class HttpResponse implements ToXContent {
private final int status; private final int status;
private final ImmutableMap<String, String[]> headers; private final Map<String, String[]> headers;
private final BytesReference body; private final BytesReference body;
public HttpResponse(int status) { public HttpResponse(int status) {
this(status, ImmutableMap.<String, String[]>of()); this(status, emptyMap());
} }
public HttpResponse(int status, ImmutableMap<String, String[]> headers) { public HttpResponse(int status, Map<String, String[]> headers) {
this(status, (BytesReference) null, headers); this(status, (BytesReference) null, headers);
} }
public HttpResponse(int status, @Nullable String body) { public HttpResponse(int status, @Nullable String body) {
this(status, body != null ? new BytesArray(body) : null, ImmutableMap.<String, String[]>of()); this(status, body != null ? new BytesArray(body) : null, emptyMap());
} }
public HttpResponse(int status, @Nullable String body, ImmutableMap<String, String[]> headers) { public HttpResponse(int status, @Nullable String body, Map<String, String[]> headers) {
this(status, body != null ? new BytesArray(body) : null, headers); this(status, body != null ? new BytesArray(body) : null, headers);
} }
@ -50,11 +54,11 @@ public class HttpResponse implements ToXContent {
this(status, body != null ? new BytesArray(body) : null, ImmutableMap.<String, String[]>of()); this(status, body != null ? new BytesArray(body) : null, ImmutableMap.<String, String[]>of());
} }
public HttpResponse(int status, @Nullable byte[] body, ImmutableMap<String, String[]> headers) { public HttpResponse(int status, @Nullable byte[] body, Map<String, String[]> headers) {
this(status, body != null ? new BytesArray(body) : null, headers); this(status, body != null ? new BytesArray(body) : null, headers);
} }
public HttpResponse(int status, @Nullable BytesReference body, ImmutableMap<String, String[]> headers) { public HttpResponse(int status, @Nullable BytesReference body, Map<String, String[]> headers) {
this.status = status; this.status = status;
this.body = body; this.body = body;
this.headers = headers; this.headers = headers;
@ -72,7 +76,7 @@ public class HttpResponse implements ToXContent {
return body; return body;
} }
public ImmutableMap<String, String[]> headers() { public Map<String, String[]> headers() {
return headers; return headers;
} }

View File

@ -43,7 +43,7 @@ public class WatchStatus implements ToXContent, Streamable {
private @Nullable DateTime lastChecked; private @Nullable DateTime lastChecked;
private @Nullable DateTime lastMetCondition; private @Nullable DateTime lastMetCondition;
private ImmutableMap<String, ActionStatus> actions; private Map<String, ActionStatus> actions;
private volatile boolean dirty = false; private volatile boolean dirty = false;
@ -51,7 +51,7 @@ public class WatchStatus implements ToXContent, Streamable {
private WatchStatus() { private WatchStatus() {
} }
public WatchStatus(DateTime now, ImmutableMap<String, ActionStatus> actions) { public WatchStatus(DateTime now, Map<String, ActionStatus> actions) {
this(-1, new State(true, now), null, null, actions); this(-1, new State(true, now), null, null, actions);
} }
@ -59,7 +59,7 @@ public class WatchStatus implements ToXContent, Streamable {
this(other.version, other.state, other.lastChecked, other.lastMetCondition, other.actions); this(other.version, other.state, other.lastChecked, other.lastMetCondition, other.actions);
} }
private WatchStatus(long version, State state, DateTime lastChecked, DateTime lastMetCondition, ImmutableMap<String, ActionStatus> actions) { private WatchStatus(long version, State state, DateTime lastChecked, DateTime lastMetCondition, Map<String, ActionStatus> actions) {
this.version = version; this.version = version;
this.lastChecked = lastChecked; this.lastChecked = lastChecked;
this.lastMetCondition = lastMetCondition; this.lastMetCondition = lastMetCondition;