From 8be70f54f764750a80257da8702593e7bbec42e7 Mon Sep 17 00:00:00 2001 From: javanna Date: Sat, 19 Nov 2016 15:15:02 +0100 Subject: [PATCH] Rename ClusterState#lookupPrototypeSafe to `lookupPrototype` and remove previous "unsafe" unused variant The `lookupPrototype` method is not used anywhere. Seems like we rather use its `lookupProrotypeSafe` variant (which also throws exception if the prototype is not found) is always. This commit makes the safer variant the default one, by renaming it to "lookupPrototype" and removes the previous "unsafe" variant. --- .../elasticsearch/cluster/ClusterState.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java index 7699e6fff87c8..c842c57daec50 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -108,13 +108,7 @@ public static void registerPrototype(String type, Custom proto) { registerPrototype(RestoreInProgress.TYPE, RestoreInProgress.PROTO); } - @Nullable public static T lookupPrototype(String type) { - //noinspection unchecked - return (T) customPrototypes.get(type); - } - - public static T lookupPrototypeSafe(String type) { @SuppressWarnings("unchecked") T proto = (T) customPrototypes.get(type); if (proto == null) { @@ -308,7 +302,7 @@ public enum Metric { private final String value; - private Metric(String value) { + Metric(String value) { this.value = value; } @@ -630,10 +624,6 @@ public Builder stateUUID(String uuid) { return this; } - public Custom getCustom(String type) { - return customs.get(type); - } - public Builder putCustom(String type, Custom custom) { customs.put(type, custom); return this; @@ -707,7 +697,7 @@ public ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOE int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { String type = in.readString(); - Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in); + Custom customIndexMetaData = lookupPrototype(type).readFrom(in); builder.putCustom(type, customIndexMetaData); } return builder.build(); @@ -779,12 +769,12 @@ public ClusterStateDiff(StreamInput in, ClusterState proto) throws IOException { new DiffableUtils.DiffableValueSerializer() { @Override public Custom read(StreamInput in, String key) throws IOException { - return lookupPrototypeSafe(key).readFrom(in); + return lookupPrototype(key).readFrom(in); } @Override public Diff readDiff(StreamInput in, String key) throws IOException { - return lookupPrototypeSafe(key).readDiffFrom(in); + return lookupPrototype(key).readDiffFrom(in); } }); }