From ce99b1093a9f2e63688b275330dbbbb67d1ffdc0 Mon Sep 17 00:00:00 2001 From: Luke Way Date: Mon, 12 Mar 2018 13:38:46 -0400 Subject: [PATCH] -- Statically initialize value lookup map. This avoids problems when running simulations in multiple threads. -- Replace Maps.newTreeMap with new HashMap<>(). newTreeMap is not necessary in Java 7+, and there's no need for a tree map here. --- .../src/main/java/forge/game/ability/ApiType.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/ApiType.java b/forge-game/src/main/java/forge/game/ability/ApiType.java index 8605e2453fd..603ed40614c 100644 --- a/forge-game/src/main/java/forge/game/ability/ApiType.java +++ b/forge-game/src/main/java/forge/game/ability/ApiType.java @@ -1,10 +1,10 @@ package forge.game.ability; -import com.google.common.collect.Maps; import forge.game.ability.effects.*; import forge.util.ReflectionUtil; +import java.util.HashMap; import java.util.Map; /** @@ -163,7 +163,13 @@ public enum ApiType { private final SpellAbilityEffect instanceEffect; private final Class clsEffect; - private static final Map allValues = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); + private static final Map allValues = new HashMap<>(); + + static { + for(ApiType t : ApiType.values()) { + allValues.put(t.name(), t); + } + } ApiType(Class clsEf) { this(clsEf, true); } ApiType(Class clsEf, final boolean isStateLess) { @@ -172,10 +178,6 @@ public enum ApiType { } public static ApiType smartValueOf(String value) { - if (allValues.isEmpty()) - for(ApiType c : ApiType.values()) - allValues.put(c.toString(), c); - ApiType v = allValues.get(value); if ( v == null ) throw new RuntimeException("Element " + value + " not found in ApiType enum");