From 06e069c5dbfb024a6b746e964ff81d58aa8cdae3 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 5 Jan 2020 22:35:20 -0500 Subject: [PATCH] updated implementation as suggested --- .../dynamicvalue/common/StaticValue.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/StaticValue.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/StaticValue.java index 12d2b4f4df..360034367d 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/StaticValue.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/StaticValue.java @@ -5,12 +5,19 @@ import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; import mage.game.Game; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.IntStream; public class StaticValue implements DynamicValue { - private static final Map staticValueMap = new HashMap(); + private static final List staticValues = new ArrayList(); + + static { + IntStream.rangeClosed(-10, 10) + .mapToObj(StaticValue::new) + .forEachOrdered(staticValues::add); + } private final int value; @@ -43,7 +50,9 @@ public class StaticValue implements DynamicValue { } public static StaticValue get(int value) { - staticValueMap.putIfAbsent(value, new StaticValue(value)); - return staticValueMap.get(value); + if (value < -10 || value > 10) { + return new StaticValue(value); + } + return staticValues.get(value + 10); } }