Merge pull request elastic/elasticsearch#694 from nik9000/immutable_map_entry_set_be_gone

Stop using ImmutableMap#entrySet

Original commit: elastic/x-pack-elasticsearch@43d6598d27
This commit is contained in:
Nik Everett 2015-09-23 08:29:17 -04:00
commit 56bb508254
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.
*/
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
);
@ -283,8 +283,7 @@ public interface Permission {
}
static interface Indices extends Permission, Iterable<Indices.Group> {
ImmutableMap<String, IndicesAccessControl.IndexAccessControl> authorize(String action, Set<String> requestedIndicesOrAliases, MetaData metaData);
Map<String, IndicesAccessControl.IndexAccessControl> authorize(String action, Set<String> requestedIndicesOrAliases, MetaData metaData);
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:
Map<String, IndicesAccessControl.IndexAccessControl> indicesAccessControl = null;
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) {
indicesAccessControl = new HashMap<>(temp);
} else {

View File

@ -5,12 +5,14 @@
*/
package org.elasticsearch.shield.authz.accesscontrol;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
@ -18,12 +20,12 @@ import java.util.Set;
*/
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 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.indexPermissions = indexPermissions;
}

View File

@ -24,6 +24,8 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
import static java.util.Collections.emptyMap;
public class HttpRequest implements ToXContent {
final String host;
@ -31,8 +33,8 @@ public class HttpRequest implements ToXContent {
final Scheme scheme;
final HttpMethod method;
final @Nullable String path;
final ImmutableMap<String, String> params;
final ImmutableMap<String, String> headers;
final Map<String, String> params;
final Map<String, String> headers;
final @Nullable HttpAuth auth;
final @Nullable String body;
final @Nullable TimeValue connectionTimeout;
@ -46,8 +48,8 @@ public class HttpRequest implements ToXContent {
this.scheme = scheme != null ? scheme : Scheme.HTTP;
this.method = method != null ? method : HttpMethod.GET;
this.path = path;
this.params = params != null ? params : ImmutableMap.<String, String>of();
this.headers = headers != null ? headers : ImmutableMap.<String, String>of();
this.params = params != null ? params : emptyMap();
this.headers = headers != null ? headers : emptyMap();
this.auth = auth;
this.body = body;
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 java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.emptyMap;
/**
*/
public class HttpRequestTemplate implements ToXContent {
@ -36,8 +39,8 @@ public class HttpRequestTemplate implements ToXContent {
private final int port;
private final HttpMethod method;
private final TextTemplate path;
private final ImmutableMap<String, TextTemplate> params;
private final ImmutableMap<String, TextTemplate> headers;
private final Map<String, TextTemplate> params;
private final Map<String, TextTemplate> headers;
private final HttpAuth auth;
private final TextTemplate body;
private final @Nullable TimeValue connectionTimeout;
@ -51,8 +54,8 @@ public class HttpRequestTemplate implements ToXContent {
this.scheme = scheme != null ? scheme :Scheme.HTTP;
this.method = method != null ? method : HttpMethod.GET;
this.path = path;
this.params = params != null ? ImmutableMap.copyOf(params) : ImmutableMap.<String, TextTemplate>of();
this.headers = headers != null ? ImmutableMap.copyOf(headers) : ImmutableMap.<String, TextTemplate>of();
this.params = params != null ? ImmutableMap.copyOf(params) : emptyMap();
this.headers = headers != null ? ImmutableMap.copyOf(headers) : emptyMap();
this.auth = auth;
this.body = body;
this.connectionTimeout = connectionTimeout;

View File

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

View File

@ -43,7 +43,7 @@ public class WatchStatus implements ToXContent, Streamable {
private @Nullable DateTime lastChecked;
private @Nullable DateTime lastMetCondition;
private ImmutableMap<String, ActionStatus> actions;
private Map<String, ActionStatus> actions;
private volatile boolean dirty = false;
@ -51,7 +51,7 @@ public class WatchStatus implements ToXContent, Streamable {
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);
}
@ -59,7 +59,7 @@ public class WatchStatus implements ToXContent, Streamable {
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.lastChecked = lastChecked;
this.lastMetCondition = lastMetCondition;