From f5398a739a111a09fa33711d6892fec3ca866d77 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 22 Sep 2015 16:49:10 -0400 Subject: [PATCH] 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@7f959001863a4b8d523a3e931d8ef2a4124510f1 --- .../shield/authz/Permission.java | 7 +++---- .../accesscontrol/IndicesAccessControl.java | 10 ++++++---- .../watcher/support/http/HttpRequest.java | 10 ++++++---- .../support/http/HttpRequestTemplate.java | 11 ++++++---- .../watcher/support/http/HttpResponse.java | 20 +++++++++++-------- .../watcher/watch/WatchStatus.java | 6 +++--- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java b/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java index 982f9195d7c..c48788e139e 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java @@ -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 requestedIndicesOrAliases, MetaData metaData) { - ImmutableMap indexPermissions = indices.authorize( + Map indexPermissions = indices.authorize( action, requestedIndicesOrAliases, metaData ); @@ -283,8 +283,7 @@ public interface Permission { } static interface Indices extends Permission, Iterable { - - ImmutableMap authorize(String action, Set requestedIndicesOrAliases, MetaData metaData); + Map authorize(String action, Set 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 indicesAccessControl = null; for (Global permission : globals) { - ImmutableMap temp = permission.indices().authorize(action, requestedIndicesOrAliases, metaData); + Map temp = permission.indices().authorize(action, requestedIndicesOrAliases, metaData); if (indicesAccessControl == null) { indicesAccessControl = new HashMap<>(temp); } else { diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/IndicesAccessControl.java b/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/IndicesAccessControl.java index 485fa08265b..14adc0612a5 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/IndicesAccessControl.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/IndicesAccessControl.java @@ -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.of()); + public static final IndicesAccessControl ALLOW_ALL = new IndicesAccessControl(true, Collections.emptyMap()); private final boolean granted; - private final ImmutableMap indexPermissions; + private final Map indexPermissions; - public IndicesAccessControl(boolean granted, ImmutableMap indexPermissions) { + public IndicesAccessControl(boolean granted, Map indexPermissions) { this.granted = granted; this.indexPermissions = indexPermissions; } diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java index 5a1a3382294..e76e6d6ea42 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java @@ -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 params; - final ImmutableMap headers; + final Map params; + final Map 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.of(); - this.headers = headers != null ? headers : ImmutableMap.of(); + this.params = params != null ? params : emptyMap(); + this.headers = headers != null ? headers : emptyMap(); this.auth = auth; this.body = body; this.connectionTimeout = connectionTimeout; diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java index 4d3b866930c..cb7f157d032 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java @@ -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 params; - private final ImmutableMap headers; + private final Map params; + private final Map 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.of(); - this.headers = headers != null ? ImmutableMap.copyOf(headers) : ImmutableMap.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; diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java index f32592615b3..16f37ac075c 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java @@ -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 headers; + private final Map headers; private final BytesReference body; public HttpResponse(int status) { - this(status, ImmutableMap.of()); + this(status, emptyMap()); } - public HttpResponse(int status, ImmutableMap headers) { + public HttpResponse(int status, Map headers) { this(status, (BytesReference) null, headers); } public HttpResponse(int status, @Nullable String body) { - this(status, body != null ? new BytesArray(body) : null, ImmutableMap.of()); + this(status, body != null ? new BytesArray(body) : null, emptyMap()); } - public HttpResponse(int status, @Nullable String body, ImmutableMap headers) { + public HttpResponse(int status, @Nullable String body, Map 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.of()); } - public HttpResponse(int status, @Nullable byte[] body, ImmutableMap headers) { + public HttpResponse(int status, @Nullable byte[] body, Map headers) { this(status, body != null ? new BytesArray(body) : null, headers); } - public HttpResponse(int status, @Nullable BytesReference body, ImmutableMap headers) { + public HttpResponse(int status, @Nullable BytesReference body, Map headers) { this.status = status; this.body = body; this.headers = headers; @@ -72,7 +76,7 @@ public class HttpResponse implements ToXContent { return body; } - public ImmutableMap headers() { + public Map headers() { return headers; } diff --git a/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java b/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java index 070f6e5004d..2068110bac3 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java @@ -43,7 +43,7 @@ public class WatchStatus implements ToXContent, Streamable { private @Nullable DateTime lastChecked; private @Nullable DateTime lastMetCondition; - private ImmutableMap actions; + private Map actions; private volatile boolean dirty = false; @@ -51,7 +51,7 @@ public class WatchStatus implements ToXContent, Streamable { private WatchStatus() { } - public WatchStatus(DateTime now, ImmutableMap actions) { + public WatchStatus(DateTime now, Map 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 actions) { + private WatchStatus(long version, State state, DateTime lastChecked, DateTime lastMetCondition, Map actions) { this.version = version; this.lastChecked = lastChecked; this.lastMetCondition = lastMetCondition;