From: "Enrico Weigelt, metux IT consult" <enrico.weig...@gr13.net>
Instead of expensive stream operations, just do it via trivial list traversal. Also move that from the consumer logic to the FoundingFather class and provide the key list as a static array. FIXME: check whether the array can be autogenerate that list similar to the implicit values() method. --- src/net/sf/freecol/common/model/FoundingFather.java | 10 ++++++++++ .../freecol/common/networking/ChooseFoundingFatherMessage.java | 8 ++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/net/sf/freecol/common/model/FoundingFather.java b/src/net/sf/freecol/common/model/FoundingFather.java index f199b00a340..df81040eb5d 100644 --- a/src/net/sf/freecol/common/model/FoundingFather.java +++ b/src/net/sf/freecol/common/model/FoundingFather.java @@ -57,6 +57,16 @@ public class FoundingFather extends FreeColSpecObjectType { public String getKey() { return getEnumKey(this); } + + public static String[] getAllKeys() { + FoundingFatherType[] v = values(); + String[] result = new String[v.length]; + for (int x=0; x<v.length; x++) + result[x] = getEnumKey(v[x]); + return result; + } + + public static final String[] allKeys = getAllKeys(); } /** The type of this FoundingFather. */ diff --git a/src/net/sf/freecol/common/networking/ChooseFoundingFatherMessage.java b/src/net/sf/freecol/common/networking/ChooseFoundingFatherMessage.java index 672698353af..3433971b4e2 100644 --- a/src/net/sf/freecol/common/networking/ChooseFoundingFatherMessage.java +++ b/src/net/sf/freecol/common/networking/ChooseFoundingFatherMessage.java @@ -44,10 +44,6 @@ public class ChooseFoundingFatherMessage extends AttributeMessage { public static final String TAG = "chooseFoundingFather"; private static final String FOUNDING_FATHER_TAG = "foundingFather"; - private static final List<String> fatherKeys = Collections.<String> - unmodifiableList(transform(FoundingFatherType.values(), - alwaysTrue(), FoundingFatherType::getKey)); - /** * Create a new {@code ChooseFoundingFatherMessage} with the specified @@ -74,7 +70,7 @@ public class ChooseFoundingFatherMessage extends AttributeMessage { super(TAG, FOUNDING_FATHER_TAG, getStringAttribute(element, FOUNDING_FATHER_TAG)); final Specification spec = game.getSpecification(); - setFatherAttributes(transform(fatherKeys, + setFatherAttributes(transform(FoundingFatherType.allKeys, k -> element.hasAttribute(k), k -> spec.getFoundingFather(getStringAttribute(element, k)))); } @@ -126,7 +122,7 @@ public class ChooseFoundingFatherMessage extends AttributeMessage { */ public final List<FoundingFather> getFathers(Game game) { final Specification spec = game.getSpecification(); - return transform(fatherKeys, tid -> hasAttribute(tid), + return transform(FoundingFatherType.allKeys, tid -> hasAttribute(tid), tid -> spec.getFoundingFather(getStringAttribute(tid))); } -- 2.11.0.rc0.7.gbe5a750 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Freecol-developers mailing list Freecol-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freecol-developers