mirror of
https://github.com/correl/mage.git
synced 2025-03-16 17:00:13 -09:00
updated implementation as suggested
This commit is contained in:
parent
38fe022fc0
commit
06e069c5db
1 changed files with 14 additions and 5 deletions
|
@ -5,12 +5,19 @@ import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class StaticValue implements DynamicValue {
|
public class StaticValue implements DynamicValue {
|
||||||
|
|
||||||
private static final Map<Integer, StaticValue> staticValueMap = new HashMap();
|
private static final List<StaticValue> staticValues = new ArrayList();
|
||||||
|
|
||||||
|
static {
|
||||||
|
IntStream.rangeClosed(-10, 10)
|
||||||
|
.mapToObj(StaticValue::new)
|
||||||
|
.forEachOrdered(staticValues::add);
|
||||||
|
}
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
|
@ -43,7 +50,9 @@ public class StaticValue implements DynamicValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StaticValue get(int value) {
|
public static StaticValue get(int value) {
|
||||||
staticValueMap.putIfAbsent(value, new StaticValue(value));
|
if (value < -10 || value > 10) {
|
||||||
return staticValueMap.get(value);
|
return new StaticValue(value);
|
||||||
|
}
|
||||||
|
return staticValues.get(value + 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue