From: "Enrico Weigelt, metux IT consult" <[email protected]>
---
.../freecol/client/gui/dialog/PreCombatDialog.java | 5 +-
.../gui/panel/colopedia/ResourcesDetailPanel.java | 5 +-
.../gui/panel/colopedia/UnitDetailPanel.java | 11 ++-
src/net/sf/freecol/common/model/BuildQueue.java | 12 ++-
src/net/sf/freecol/common/model/Building.java | 42 ++++----
src/net/sf/freecol/common/model/Colony.java | 14 +--
src/net/sf/freecol/common/model/ColonyTile.java | 35 +++----
src/net/sf/freecol/common/model/Consumer.java | 17 +++-
.../sf/freecol/common/model/FeatureContainer.java | 83 ++++++++--------
src/net/sf/freecol/common/model/FreeColObject.java | 110 +++++++++++++++------
.../sf/freecol/common/model/LostCityRumour.java | 4 +-
.../sf/freecol/common/model/ProductionCache.java | 4 +-
src/net/sf/freecol/common/model/Resource.java | 8 +-
.../sf/freecol/common/model/SimpleCombatModel.java | 32 +++---
src/net/sf/freecol/common/model/Specification.java | 11 ++-
src/net/sf/freecol/common/model/Tile.java | 18 +++-
.../sf/freecol/common/model/TileImprovement.java | 8 +-
src/net/sf/freecol/common/model/TileItem.java | 21 +++-
.../sf/freecol/common/model/TileItemContainer.java | 7 +-
src/net/sf/freecol/common/model/Unit.java | 31 +++---
src/net/sf/freecol/common/model/WorkLocation.java | 22 ++++-
src/net/sf/freecol/server/ai/NativeAIPlayer.java | 4 +-
src/net/sf/freecol/server/model/ServerPlayer.java | 2 +-
.../net/sf/freecol/common/model/BuildingTest.java | 37 +++----
.../net/sf/freecol/common/model/ColonyTest.java | 8 +-
.../net/sf/freecol/common/model/CombatTest.java | 14 +--
.../freecol/common/model/FoundingFatherTest.java | 4 +-
.../freecol/common/model/IndividualFatherTest.java | 10 +-
.../net/sf/freecol/common/model/ModifierTest.java | 12 +--
.../sf/freecol/common/model/NationTypeTest.java | 4 +-
test/src/net/sf/freecol/common/model/TileTest.java | 8 +-
.../sf/freecol/server/model/ServerUnitTest.java | 5 +-
32 files changed, 357 insertions(+), 251 deletions(-)
diff --git a/src/net/sf/freecol/client/gui/dialog/PreCombatDialog.java
b/src/net/sf/freecol/client/gui/dialog/PreCombatDialog.java
index c9392d30818..3ed3e421266 100644
--- a/src/net/sf/freecol/client/gui/dialog/PreCombatDialog.java
+++ b/src/net/sf/freecol/client/gui/dialog/PreCombatDialog.java
@@ -20,6 +20,7 @@
package net.sf.freecol.client.gui.dialog;
import java.awt.Font;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -137,7 +138,7 @@ public class PreCombatDialog extends FreeColConfirmDialog {
Font bigFont = FontLibrary.createFont(FontLibrary.FontType.NORMAL,
FontLibrary.FontSize.SMALLER, Font.BOLD, lib.getScaleFactor());
float offenceResult
- = FeatureContainer.applyModifiers(0f, turn, attackModifiers);
+ = FeatureContainer.applyModifiers(0f, turn, new
ArrayList<>(attackModifiers));
JLabel finalOffenceLabel = Utility.localizedLabel("finalResult");
finalOffenceLabel.setFont(bigFont);
panel.add(new JSeparator(JSeparator.HORIZONTAL),
@@ -150,7 +151,7 @@ public class PreCombatDialog extends FreeColConfirmDialog {
panel.add(finalOffenceResult);
float defenceResult
- = FeatureContainer.applyModifiers(0f, turn, defenceModifiers);
+ = FeatureContainer.applyModifiers(0f, turn, new
ArrayList<>(defenceModifiers));
JLabel finalDefenceLabel = Utility.localizedLabel("finalResult");
finalDefenceLabel.setFont(bigFont);
panel.add(finalDefenceLabel, "skip");
diff --git
a/src/net/sf/freecol/client/gui/panel/colopedia/ResourcesDetailPanel.java
b/src/net/sf/freecol/client/gui/panel/colopedia/ResourcesDetailPanel.java
index eea89593a5d..a6b89823f8e 100644
--- a/src/net/sf/freecol/client/gui/panel/colopedia/ResourcesDetailPanel.java
+++ b/src/net/sf/freecol/client/gui/panel/colopedia/ResourcesDetailPanel.java
@@ -19,6 +19,7 @@
package net.sf.freecol.client.gui.panel.colopedia;
+import java.util.Collections;
import java.util.List;
import javax.swing.JButton;
@@ -88,8 +89,8 @@ public class ResourcesDetailPanel
panel.add(Utility.localizedLabel("colopedia.resource.bonusProduction"));
JPanel goodsPanel = new JPanel();
goodsPanel.setOpaque(false);
- List<Modifier> mods = sort(type.getModifiers(),
- Modifier.ascendingModifierIndexComparator);
+ List<Modifier> mods = type.getModifiers();
+ Collections.sort(mods, Modifier.ascendingModifierIndexComparator);
for (Modifier modifier : mods) {
String text = ModifierFormat.getModifierAsString(modifier);
if (modifier.hasScope()) {
diff --git a/src/net/sf/freecol/client/gui/panel/colopedia/UnitDetailPanel.java
b/src/net/sf/freecol/client/gui/panel/colopedia/UnitDetailPanel.java
index a48b23ad856..8fb6e9ed4e7 100644
--- a/src/net/sf/freecol/client/gui/panel/colopedia/UnitDetailPanel.java
+++ b/src/net/sf/freecol/client/gui/panel/colopedia/UnitDetailPanel.java
@@ -21,6 +21,7 @@ package net.sf.freecol.client.gui.panel.colopedia;
import java.awt.GridLayout;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -183,11 +184,11 @@ public class UnitDetailPanel extends
ColopediaGameObjectTypePanel<UnitType> {
panel.add(textPane, "span, width 60%");
}
- final Function<GoodsType, Stream<Modifier>> goodsMapper = gt ->
- type.getModifiers(gt.getId());
- List<Modifier> bonusList
- = sort(flatten(spec.getGoodsTypeList(), goodsMapper),
- Modifier.ascendingModifierIndexComparator);
+ List<Modifier> bonusList = new ArrayList<>();
+ for (GoodsType gt : spec.getGoodsTypeList())
+ type.fillModifiers(bonusList, gt.getId());
+ Collections.sort(bonusList, Modifier.ascendingModifierIndexComparator);
+
int bonusNumber = bonusList.size();
if (bonusNumber > 0) {
StringTemplate template = StringTemplate
diff --git a/src/net/sf/freecol/common/model/BuildQueue.java
b/src/net/sf/freecol/common/model/BuildQueue.java
index 4fb6e0248b5..fd73b153bc4 100644
--- a/src/net/sf/freecol/common/model/BuildQueue.java
+++ b/src/net/sf/freecol/common/model/BuildQueue.java
@@ -22,7 +22,6 @@ package net.sf.freecol.common.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.stream.Stream;
import net.sf.freecol.common.option.GameOptions;
import static net.sf.freecol.common.util.CollectionUtils.*;
@@ -218,8 +217,15 @@ public class BuildQueue<T extends BuildableType>
implements Consumer {
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getModifiers(String id) {
- return Stream.<Modifier>empty();
+ public void fillModifiers(List<Modifier> result, String id) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Modifier> getModifiers(String id) {
+ return Collections.<Modifier>emptyList();
}
diff --git a/src/net/sf/freecol/common/model/Building.java
b/src/net/sf/freecol/common/model/Building.java
index 85a1703e33d..653929c6de9 100644
--- a/src/net/sf/freecol/common/model/Building.java
+++ b/src/net/sf/freecol/common/model/Building.java
@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -143,22 +142,21 @@ public class Building extends WorkLocation
* *multiplicative* modifiers, as this would capture the master blacksmith
* doubling.
*
+ * @param result The list to fill into
* @param id The String identifier
* @param turn The turn number of type {@link Turn}
* @param unitType The optional {@code UnitType} to produce them.
* @return A stream of the applicable modifiers.
*/
- public Stream<Modifier> getCompetenceModifiers(String id,
+ private void fillCompetenceModifiers(List<Modifier> result, String id,
UnitType unitType, Turn turn) {
final float competence = getCompetenceFactor();
- return (competence == 1.0f) // Floating comparison OK!
- ? unitType.getModifiers(id, getType(), turn)
- : map(unitType.getModifiers(id, getType(), turn),
- m -> {
- return (m.getType() == Modifier.ModifierType.ADDITIVE)
- ? new Modifier(m).setValue(m.getValue() * competence)
- : m;
- });
+ if (competence == 1.0f) // Floating comparison OK!
+ fillModifiers(result, id, getType(), turn);
+ else
+ for (Modifier m : unitType.getModifiers(id, getType(), turn))
+ result.add((m.getType() == Modifier.ModifierType.ADDITIVE)
+ ? new Modifier(m).setValue(m.getValue() * competence)
: m);
}
/**
@@ -561,7 +559,7 @@ public class Building extends WorkLocation
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
final BuildingType type = getType();
final String id = (goodsType == null) ? null : goodsType.getId();
@@ -569,15 +567,15 @@ public class Building extends WorkLocation
final Player owner = getOwner();
final Turn turn = getGame().getTurn();
- return (unitType != null)
- // With a unit, unit specific bonuses apply
- ? concat(this.getModifiers(id, unitType, turn),
- colony.getProductionModifiers(goodsType, unitType, this),
- getCompetenceModifiers(id, unitType, turn),
- owner.getModifiers(id, unitType, turn))
- // With no unit, only the building-specific bonuses
- : concat(colony.getModifiers(id, type, turn),
- owner.getModifiers(id, type, turn));
+ if (unitType == null) {
+ colony.fillModifiers(result, id, type, turn);
+ owner.fillModifiers(result, id, type, turn);
+ } else {
+ this.fillModifiers(result, id, unitType, turn);
+ colony.fillProductionModifiers(result, goodsType, unitType, this);
+ fillCompetenceModifiers(result, id, unitType, turn);
+ owner.fillModifiers(result, id, unitType, turn);
+ }
}
/**
@@ -652,10 +650,10 @@ public class Building extends WorkLocation
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getModifiers(String id, FreeColSpecObjectType
fcgot,
+ public void fillModifiers(List<Modifier> result, String id,
FreeColSpecObjectType fcgot,
Turn turn) {
// Buildings have no modifiers independent of type
- return getType().getModifiers(id, fcgot, turn);
+ getType().fillModifiers(result, id, fcgot, turn);
}
diff --git a/src/net/sf/freecol/common/model/Colony.java
b/src/net/sf/freecol/common/model/Colony.java
index e960164fd84..67f1a307dad 100644
--- a/src/net/sf/freecol/common/model/Colony.java
+++ b/src/net/sf/freecol/common/model/Colony.java
@@ -32,7 +32,6 @@ import java.util.function.Function;
import java.util.function.ToIntFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -2058,23 +2057,24 @@ public class Colony extends Settlement implements
Nameable, TradeLocation {
/**
- * Get the current production {@code Modifier}, which is
+ * Fill in the current production {@code Modifier}, which is
* generated from the current production bonus.
*
+ * @param result The {@code List} to fill into.
* @param goodsType The {@code GoodsType} to produce.
* @param unitType An optional {@code UnitType} to do the work.
* @param wl The {@link WorkLocation}
* @return A stream of suitable {@code Modifier}s.
*/
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType,
WorkLocation wl) {
- if (productionBonus == 0) return Stream.<Modifier>empty();
+ if (productionBonus == 0) return;
int bonus = (int)Math.floor(productionBonus * wl.getRebelFactor());
Modifier mod = new Modifier(goodsType.getId(), bonus,
Modifier.ModifierType.ADDITIVE,
Specification.SOL_MODIFIER_SOURCE);
mod.setModifierIndex(Modifier.COLONY_PRODUCTION_INDEX);
- return Stream.of(mod);
+ result.add(mod);
}
/**
@@ -2450,12 +2450,12 @@ loop: for (WorkLocation wl :
getWorkLocationsForProducing(goodsType)) {
final Turn turn = getGame().getTurn();
List<Modifier> mods;
- mods = toList(goodsType.getModifiers(Modifier.LIBERTY));
+ mods = goodsType.getModifiers(Modifier.LIBERTY);
if (!mods.isEmpty()) {
modifyLiberty((int)applyModifiers(amount, turn, mods));
}
- mods = toList(goodsType.getModifiers(Modifier.IMMIGRATION));
+ mods = goodsType.getModifiers(Modifier.IMMIGRATION);
if (!mods.isEmpty()) {
int migration = (int)applyModifiers(amount, turn, mods);
modifyImmigration(migration);
diff --git a/src/net/sf/freecol/common/model/ColonyTile.java
b/src/net/sf/freecol/common/model/ColonyTile.java
index e69f75d25aa..fb6ae92b2d8 100644
--- a/src/net/sf/freecol/common/model/ColonyTile.java
+++ b/src/net/sf/freecol/common/model/ColonyTile.java
@@ -22,7 +22,6 @@ package net.sf.freecol.common.model;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -453,9 +452,9 @@ public class ColonyTile extends WorkLocation {
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
- if (!canProduce(goodsType, unitType)) return Stream.<Modifier>empty();
+ if (!canProduce(goodsType, unitType)) return;
final Tile workTile = getWorkTile();
final TileType type = workTile.getType();
@@ -463,22 +462,24 @@ public class ColonyTile extends WorkLocation {
final Colony colony = getColony();
final Player owner = colony.getOwner();
final Turn turn = getGame().getTurn();
- return (unitType != null)
+
+ if (unitType != null) {
// Unit modifiers apply
- ? concat(workTile.getProductionModifiers(goodsType, unitType),
- colony.getProductionModifiers(goodsType, unitType, this),
- unitType.getModifiers(id, type, turn),
- ((owner == null) ? null
- : owner.getModifiers(id, unitType, turn)))
+ workTile.fillProductionModifiers(result, goodsType, unitType);
+ colony.fillProductionModifiers(result, goodsType, unitType, this);
+ unitType.fillModifiers(result, id, type, turn);
+ if (owner != null)
+ owner.fillModifiers(result, id, unitType, turn);
+ } else if (isColonyCenterTile()) {
// Unattended only possible in center, colony modifiers apply
- : (isColonyCenterTile())
- ? concat(workTile.getProductionModifiers(goodsType, null),
- colony.getProductionModifiers(goodsType, null, this),
- colony.getModifiers(id, null, turn),
- ((owner == null) ? null
- : owner.getModifiers(id, type, turn)))
- // Otherwise impossible
- : Stream.<Modifier>empty();
+ workTile.fillProductionModifiers(result, goodsType, null);
+ colony.fillProductionModifiers(result, goodsType, null, this);
+ colony.fillModifiers(result, id, null, turn);
+ if (owner != null)
+ owner.fillModifiers(result, id, type, turn);
+ }
+
+ // Otherwise impossible
}
/**
diff --git a/src/net/sf/freecol/common/model/Consumer.java
b/src/net/sf/freecol/common/model/Consumer.java
index 5563f15033a..00192b2efb9 100644
--- a/src/net/sf/freecol/common/model/Consumer.java
+++ b/src/net/sf/freecol/common/model/Consumer.java
@@ -21,7 +21,6 @@ package net.sf.freecol.common.model;
import java.util.Comparator;
import java.util.List;
-import java.util.stream.Stream;
/**
@@ -91,13 +90,25 @@ public interface Consumer {
/**
+ * Fill in the modifier set with the given id. The modifier most
+ * relevant to consumers is "consumeOnlySurplusProduction", which
+ * implies that the consumer does not consume stored goods (used
+ * by the country and stables).
+ *
+ * @param result The list to fill {@code Modifier}s into.
+ * @param id The object identifier.
+ */
+ public void fillModifiers(List<Modifier> result, String id);
+
+
+ /**
* Get the modifier set with the given id. The modifier most
* relevant to consumers is "consumeOnlySurplusProduction", which
* implies that the consumer does not consume stored goods (used
* by the country and stables).
*
* @param id The object identifier.
- * @return The stream of {@code Modifier}s found.
+ * @return The list of {@code Modifier}s found.
*/
- public Stream<Modifier> getModifiers(String id);
+ public List<Modifier> getModifiers(String id);
}
diff --git a/src/net/sf/freecol/common/model/FeatureContainer.java
b/src/net/sf/freecol/common/model/FeatureContainer.java
index 7091faaaf6e..d2cfb88a312 100644
--- a/src/net/sf/freecol/common/model/FeatureContainer.java
+++ b/src/net/sf/freecol/common/model/FeatureContainer.java
@@ -20,12 +20,13 @@ package net.sf.freecol.common.model;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import static net.sf.freecol.common.util.CollectionUtils.*;
@@ -102,7 +103,7 @@ public final class FeatureContainer {
* Is the given set of abilities non-empty and contains no
* false-valued members?
*
- * @param abilities A stream of {@code Ability}s to check.
+ * @param abilities A list of {@code Ability}s to check.
* @return True if the abilities are `satisfied'.
*/
public static boolean hasAbility(List<Ability> abilities) {
@@ -221,30 +222,53 @@ public final class FeatureContainer {
/**
- * Gets the set of modifiers with the given identifier from this
+ * Fills in the set of modifiers with the given identifier from this
* container.
*
+ * @param result The {@code List} to fill into.
* @param id The object identifier.
* @param fcgot An optional {@code FreeColSpecObjectType} the
* modifier applies to.
* @param turn An optional applicable {@code Turn}.
- * @return A stream of {@code Modifier}s.
*/
- public Stream<Modifier> getModifiers(String id,
+ public void fillModifiers(List<Modifier> result,
+ String id,
FreeColSpecObjectType fcgot,
Turn turn) {
- if (!modifiersPresent()) return Stream.<Modifier>empty();
- Set<Modifier> mset = new HashSet<>();
+ if (!modifiersPresent()) return;
synchronized (modifiersLock) {
if (id == null) {
- for (Set<Modifier> ms : modifiers.values()) mset.addAll(ms);
+ for (Set<Modifier> ms : modifiers.values())
+ for (Modifier m : ms)
+ if (m.appliesTo(fcgot, turn))
+ result.add(m);
} else {
Set<Modifier> ms = modifiers.get(id);
- if (ms != null) mset.addAll(ms);
+ if (ms != null)
+ for (Modifier m : ms)
+ result.add(m);
}
}
- removeInPlace(mset, m -> !m.appliesTo(fcgot, turn));
- return (mset.isEmpty()) ? Stream.<Modifier>empty() : mset.stream();
+ }
+
+ /**
+ * Get a {@code List} of modifiers with the given identifier from this
+ * container.
+ *
+ * @param result The list to fill into.
+ * @param id The object identifier.
+ * @param fcgot An optional {@code FreeColSpecObjectType} the
+ * modifier applies to.
+ * @param turn An optional applicable {@code Turn}.
+ * @return A list of {@code Modifier}s.
+ */
+ public List<Modifier> getModifiers(String id,
+ FreeColSpecObjectType fcgot,
+ Turn turn) {
+ if (!modifiersPresent()) return Collections.<Modifier>emptyList();
+ List<Modifier> result = new ArrayList<>();
+ fillModifiers(result, id, fcgot, turn);
+ return result;
}
/**
@@ -272,39 +296,14 @@ public final class FeatureContainer {
* @return The modified number.
*/
public static float applyModifiers(float number, Turn turn,
- Collection<Modifier> mods) {
- return (mods == null || mods.isEmpty()) ? number
- : applyModifiers_internal(number, turn,
- sort(mods, Modifier.ascendingModifierIndexComparator));
- }
+ List<Modifier> modifiers) {
+ if (modifiers == null)
+ return number;
- /**
- * Applies a stream of modifiers to the given float value.
- *
- * @param number The number to modify.
- * @param turn An optional applicable {@code Turn}.
- * @param mods The {@code Modifier}s to apply.
- * @return The modified number.
- */
- public static float applyModifiers(float number, Turn turn,
- Stream<Modifier> mods) {
- return (mods == null) ? number
- : applyModifiers_internal(number, turn,
- sort(mods, Modifier.ascendingModifierIndexComparator));
- }
+ Collections.sort(modifiers, Modifier.ascendingModifierIndexComparator);
- /**
- * Implement applyModifiers.
- *
- * @param number The number to modify.
- * @param turn An optional applicable {@code Turn}.
- * @param mods The {@code Modifier}s to apply.
- * @return The modified number.
- */
- private static float applyModifiers_internal(float number, Turn turn,
- Collection<Modifier> mods) {
float result = number;
- for (Modifier m : mods) {
+ for (Modifier m : modifiers) {
float value = m.getValue(turn);
if (Float.compare(value, Modifier.UNKNOWN) == 0) {
return value;
@@ -514,7 +513,7 @@ public final class FeatureContainer {
sb.append(']');
}
siz = sb.length();
- for (Modifier modifier : iterable(getModifiers(null, null, null))) {
+ for (Modifier modifier : getModifiers(null, null, null)) {
sb.append(' ').append(modifier);
}
if (sb.length() > siz) {
diff --git a/src/net/sf/freecol/common/model/FreeColObject.java
b/src/net/sf/freecol/common/model/FreeColObject.java
index e93de77f818..f584d08a93f 100644
--- a/src/net/sf/freecol/common/model/FreeColObject.java
+++ b/src/net/sf/freecol/common/model/FreeColObject.java
@@ -29,12 +29,13 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -563,7 +564,7 @@ public abstract class FreeColObject
*/
public boolean hasModifier(String id, FreeColSpecObjectType fcgot,
Turn turn) {
- return any(getModifiers(id, fcgot, turn));
+ return getModifiers(id, fcgot, turn).size() != 0;
}
/**
@@ -573,7 +574,7 @@ public abstract class FreeColObject
* @return True if the key is present.
*/
public final boolean containsModifierKey(String key) {
- return any(getModifiers(key));
+ return getModifiers(key).size() != 0;
}
/**
@@ -582,7 +583,18 @@ public abstract class FreeColObject
* @return A list of modifiers.
*/
public final List<Modifier> getSortedModifiers() {
- return sort(getModifiers(), Modifier.ascendingModifierIndexComparator);
+ List<Modifier> result = getModifiers();
+ Collections.sort(result, Modifier.ascendingModifierIndexComparator);
+ return result;
+ }
+
+ /**
+ * Fill in the modifiers of this object.
+ *
+ * @param result list to fill in the modifiers.
+ */
+ public final void fillModifiers(List<Modifier> result) {
+ fillModifiers(result, null);
}
/**
@@ -590,51 +602,98 @@ public abstract class FreeColObject
*
* @return A set of modifiers.
*/
- public final Stream<Modifier> getModifiers() {
- return getModifiers(null);
+ public final List<Modifier> getModifiers() {
+ List<Modifier> result = new ArrayList<>();
+ fillModifiers(result);
+ return result;
}
/**
- * Gets the set of modifiers with the given identifier from this object.
+ * Fill in the set of modifiers with the given identifier from this object.
*
+ * @param list The list to fill into.
* @param id The object identifier.
+ */
+ public final void fillModifiers(List<Modifier> result, String id) {
+ fillModifiers(result, id, null);
+ }
+
+ /**
+ * Get the set of modifiers with the given identifier from this object.
+ *
+ * @param id The object identifier.
+ *
* @return A set of modifiers.
*/
- public final Stream<Modifier> getModifiers(String id) {
- return getModifiers(id, null);
+ public final List<Modifier> getModifiers(String id) {
+ List<Modifier> result = new ArrayList<>();
+ fillModifiers(result, id);
+ return result;
}
/**
- * Gets the set of modifiers with the given identifier from this object.
+ * Fill in the set of modifiers with the given identifier from this object.
*
+ * @param result The list to fill into.
* @param id The object identifier.
* @param fcgot An optional {@code FreeColSpecObjectType} the
* modifier applies to.
- * @return A set of modifiers.
*/
- public final Stream<Modifier> getModifiers(String id,
+ public final void fillModifiers(List<Modifier> result, String id,
FreeColSpecObjectType fcgot) {
- return getModifiers(id, fcgot, null);
+ fillModifiers(result, id, fcgot, null);
}
/**
* Gets the set of modifiers with the given identifier from this object.
*
+ * @param id The object identifier.
+ * @param fcgot An optional {@code FreeColSpecObjectType} the
+ * modifier applies to.
+ * @return A list of modifiers.
+ */
+ public final List<Modifier> getModifiers(String id,
+ FreeColSpecObjectType fcgot) {
+ List<Modifier> result = new ArrayList<>();
+ fillModifiers(result, id, fcgot);
+ return result;
+ }
+
+ /**
+ * Fills in the set of modifiers with the given identifier from this
object.
+ *
* Subclasses with complex modifier handling may override this
* routine.
*
+ * @param result The list to fill into.
* @param id The object identifier.
* @param fcgot An optional {@code FreeColSpecObjectType} the
* modifier applies to.
* @param turn An optional applicable {@code Turn}.
- * @return A set of modifiers.
*/
- public Stream<Modifier> getModifiers(String id,
+ public void fillModifiers(List<Modifier> result, String id,
FreeColSpecObjectType fcgot,
Turn turn) {
FeatureContainer fc = getFeatureContainer();
- return (fc == null) ? Stream.<Modifier>empty()
- : fc.getModifiers(id, fcgot, turn);
+ if (fc != null)
+ fc.fillModifiers(result, id, fcgot, turn);
+ }
+
+ /**
+ * Gets the set of modifiers with the given identifier from this object.
+ *
+ * @param id The object identifier.
+ * @param fcgot An optional {@code FreeColSpecObjectType} the
+ * modifier applies to.
+ * @param turn An optional applicable {@code Turn}.
+ * @return A list of modifiers.
+ */
+ public List<Modifier> getModifiers(String id,
+ FreeColSpecObjectType fcgot,
+ Turn turn) {
+ List<Modifier> result = new ArrayList<>();
+ fillModifiers(result, id, fcgot, turn);
+ return result;
}
/**
@@ -675,20 +734,7 @@ public abstract class FreeColObject
* @return The modified number.
*/
public static final float applyModifiers(float number, Turn turn,
- Collection<Modifier> mods) {
- return FeatureContainer.applyModifiers(number, turn, mods);
- }
-
- /**
- * Applies a stream of modifiers to the given number.
- *
- * @param number The number to modify.
- * @param turn An optional applicable {@code Turn}.
- * @param mods The {@code Modifier}s to apply.
- * @return The modified number.
- */
- public static final float applyModifiers(float number, Turn turn,
- Stream<Modifier> mods) {
+ List<Modifier> mods) {
return FeatureContainer.applyModifiers(number, turn, mods);
}
@@ -753,7 +799,7 @@ public abstract class FreeColObject
* @return A list of defence {@code Modifier}s.
*/
public List<Modifier> getDefenceModifiers() {
- return toList(getModifiers(Modifier.DEFENCE));
+ return getModifiers(Modifier.DEFENCE);
}
diff --git a/src/net/sf/freecol/common/model/LostCityRumour.java
b/src/net/sf/freecol/common/model/LostCityRumour.java
index 12526637a2c..48ef7947e20 100644
--- a/src/net/sf/freecol/common/model/LostCityRumour.java
+++ b/src/net/sf/freecol/common/model/LostCityRumour.java
@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -343,9 +342,8 @@ public class LostCityRumour extends TileItem {
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
- return Stream.<Modifier>empty();
}
/**
diff --git a/src/net/sf/freecol/common/model/ProductionCache.java
b/src/net/sf/freecol/common/model/ProductionCache.java
index 38433c0329f..7cc7ccbe102 100644
--- a/src/net/sf/freecol/common/model/ProductionCache.java
+++ b/src/net/sf/freecol/common/model/ProductionCache.java
@@ -125,8 +125,8 @@ public class ProductionCache {
List<AbstractGoods> goods = new ArrayList<>();
for (Consumer consumer : colony.getConsumers()) {
- List<Modifier> modifiers = toList(consumer
- .getModifiers(Modifier.CONSUME_ONLY_SURPLUS_PRODUCTION));
+ List<Modifier> modifiers =
+
consumer.getModifiers(Modifier.CONSUME_ONLY_SURPLUS_PRODUCTION);
goods.clear();
for (AbstractGoods g : consumer.getConsumedGoods()) {
goodsUsed.add(g.getType());
diff --git a/src/net/sf/freecol/common/model/Resource.java
b/src/net/sf/freecol/common/model/Resource.java
index d1cc29838a2..37accc50c46 100644
--- a/src/net/sf/freecol/common/model/Resource.java
+++ b/src/net/sf/freecol/common/model/Resource.java
@@ -20,7 +20,7 @@
package net.sf.freecol.common.model;
import java.util.logging.Logger;
-import java.util.stream.Stream;
+import java.util.List;
import javax.xml.stream.XMLStreamException;
@@ -233,10 +233,10 @@ public class Resource extends TileItem {
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
- return (goodsType == null) ? Stream.<Modifier>empty()
- : getType().getModifiers(goodsType.getId(), unitType);
+ if (goodsType != null)
+ getType().fillModifiers(result, goodsType.getId(), unitType);
}
/**
diff --git a/src/net/sf/freecol/common/model/SimpleCombatModel.java
b/src/net/sf/freecol/common/model/SimpleCombatModel.java
index ed992f0ff23..aeea63e63f7 100644
--- a/src/net/sf/freecol/common/model/SimpleCombatModel.java
+++ b/src/net/sf/freecol/common/model/SimpleCombatModel.java
@@ -150,7 +150,7 @@ public class SimpleCombatModel extends CombatModel {
|| combatIsSettlementAttack(attacker, defender)) {
Set<Modifier> mods = getOffensiveModifiers(attacker, defender);
Turn turn = attacker.getGame().getTurn();
- result = FeatureContainer.applyModifiers(0.0f, turn, mods);
+ result = FeatureContainer.applyModifiers(0.0f, turn, new
ArrayList<>(mods));
if (lb != null) {
logModifiers(lb, mods);
lb.add(" = ", result);
@@ -203,7 +203,7 @@ public class SimpleCombatModel extends CombatModel {
|| combatIsBombard(attacker, defender)) {
Set<Modifier> mods = getDefensiveModifiers(attacker, defender);
Turn turn = defender.getGame().getTurn();
- result = FeatureContainer.applyModifiers(0.0f, turn, mods);
+ result = FeatureContainer.applyModifiers(0.0f, turn, new
ArrayList<>(mods));
if (lb != null) {
logModifiers(lb, mods);
lb.add(" = ", result);
@@ -252,9 +252,9 @@ public class SimpleCombatModel extends CombatModel {
// Special bonuses against certain nation types
if (defender instanceof Ownable) {
Player owner = ((Ownable)defender).getOwner();
- result.addAll(toList(attackerUnit
- .getModifiers(Modifier.OFFENCE_AGAINST,
- owner.getNationType())));
+ result.addAll(
+ attackerUnit.getModifiers(Modifier.OFFENCE_AGAINST,
+ owner.getNationType()));
}
// Land/naval specific
@@ -293,7 +293,7 @@ public class SimpleCombatModel extends CombatModel {
Set<Modifier> result) {
// Attack bonus
final Specification spec = attacker.getSpecification();
- result.addAll(toList(spec.getModifiers(Modifier.ATTACK_BONUS)));
+ result.addAll(spec.getModifiers(Modifier.ATTACK_BONUS));
// Goods penalty always applies
int goodsCount = attacker.getGoodsSpaceTaken();
@@ -336,15 +336,15 @@ public class SimpleCombatModel extends CombatModel {
final Specification spec = attacker.getSpecification();
// Attack bonus
- result.addAll(toList(spec.getModifiers(Modifier.ATTACK_BONUS)));
+ result.addAll(spec.getModifiers(Modifier.ATTACK_BONUS));
// Movement penalty
switch (attacker.getMovesLeft()) {
case 1:
-
result.addAll(toList(spec.getModifiers(Modifier.BIG_MOVEMENT_PENALTY)));
+ result.addAll(spec.getModifiers(Modifier.BIG_MOVEMENT_PENALTY));
break;
case 2:
-
result.addAll(toList(spec.getModifiers(Modifier.SMALL_MOVEMENT_PENALTY)));
+ result.addAll(spec.getModifiers(Modifier.SMALL_MOVEMENT_PENALTY));
break;
default:
break;
@@ -352,7 +352,7 @@ public class SimpleCombatModel extends CombatModel {
// Amphibious attack?
if (combatIsAmphibious(attacker, defender)) {
-
result.addAll(toList(spec.getModifiers(Modifier.AMPHIBIOUS_ATTACK)));
+ result.addAll(spec.getModifiers(Modifier.AMPHIBIOUS_ATTACK));
}
if (combatIsAttackMeasurement(attacker, defender)) {
@@ -360,7 +360,7 @@ public class SimpleCombatModel extends CombatModel {
} else if (combatIsSettlementAttack(attacker, defender)) {
// Settlement present, apply bombardment bonus
-
result.addAll(toList(attacker.getModifiers(Modifier.BOMBARD_BONUS)));
+ result.addAll(attacker.getModifiers(Modifier.BOMBARD_BONUS));
// Popular support bonus
if (combatIsWarOfIndependence(attacker, defender)) {
@@ -373,7 +373,7 @@ public class SimpleCombatModel extends CombatModel {
if (tile != null) {
if (tile.hasSettlement()) {
// Bombard bonus applies to settlement defence
-
result.addAll(toList(attacker.getModifiers(Modifier.BOMBARD_BONUS)));
+
result.addAll(attacker.getModifiers(Modifier.BOMBARD_BONUS));
// Popular support bonus
if (combatIsWarOfIndependence(attacker, defender)) {
@@ -400,7 +400,7 @@ public class SimpleCombatModel extends CombatModel {
&& attacker.getSettlement() == null
&& attacker.getState() != Unit.UnitState.FORTIFIED
&& defenderUnit.getSettlement() == null) {
-
result.addAll(toList(spec.getModifiers(Modifier.ARTILLERY_IN_THE_OPEN)));
+
result.addAll(spec.getModifiers(Modifier.ARTILLERY_IN_THE_OPEN));
}
} else {
throw new IllegalStateException("Bogus combat");
@@ -534,7 +534,7 @@ public class SimpleCombatModel extends CombatModel {
// Artillery in the Open penalty
if (defender.hasAbility(Ability.BOMBARD)
&& defender.getState() != Unit.UnitState.FORTIFIED) {
-
result.addAll(toList(spec.getModifiers(Modifier.ARTILLERY_IN_THE_OPEN)));
+
result.addAll(spec.getModifiers(Modifier.ARTILLERY_IN_THE_OPEN));
}
} else { // In settlement
@@ -545,7 +545,7 @@ public class SimpleCombatModel extends CombatModel {
if (defender.hasAbility(Ability.BOMBARD)
&& attacker != null
&& ((Unit)attacker).getOwner().isIndian()) {
-
result.addAll(toList(spec.getModifiers(Modifier.ARTILLERY_AGAINST_RAID)));
+
result.addAll(spec.getModifiers(Modifier.ARTILLERY_AGAINST_RAID));
}
// Automatic defensive role (e.g. Revere)
@@ -565,7 +565,7 @@ public class SimpleCombatModel extends CombatModel {
// Fortify bonus
if (defender.getState() == Unit.UnitState.FORTIFIED
&& !disableFortified) {
- result.addAll(toList(spec.getModifiers(Modifier.FORTIFIED)));
+ result.addAll(spec.getModifiers(Modifier.FORTIFIED));
}
}
}
diff --git a/src/net/sf/freecol/common/model/Specification.java
b/src/net/sf/freecol/common/model/Specification.java
index 8564f3e2a52..63ec6f2461d 100644
--- a/src/net/sf/freecol/common/model/Specification.java
+++ b/src/net/sf/freecol/common/model/Specification.java
@@ -34,7 +34,6 @@ import java.util.function.Predicate;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -947,9 +946,11 @@ public final class Specification {
* @param id The object identifier to look for.
* @return A stream of {@code Modifier}s.
*/
- public Stream<Modifier> getModifiers(String id) {
+ public List<Modifier> getModifiers(String id) {
List<Modifier> result = allModifiers.get(id);
- return (result == null) ? Stream.<Modifier>empty() : result.stream();
+ return ((result == null)
+ ? Collections.<Modifier>emptyList()
+ : new ArrayList<Modifier>(result)); // copy to allow modification
}
@@ -2303,7 +2304,7 @@ public final class Specification {
// @compat 0.11.3
// Added the cargo penalty modifier
- if (none(getModifiers(Modifier.CARGO_PENALTY))) {
+ if (getModifiers(Modifier.CARGO_PENALTY).size() == 0) {
addModifier(new Modifier(Modifier.CARGO_PENALTY, -12.5f,
Modifier.ModifierType.PERCENTAGE, CARGO_PENALTY_SOURCE,
Modifier.GENERAL_COMBAT_INDEX));
@@ -2323,7 +2324,7 @@ public final class Specification {
// @compat 0.11.5
// Added a modifier to hardy pioneer
UnitType hardyPioneer = getUnitType("model.unit.hardyPioneer");
- if
(none(hardyPioneer.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION))) {
+ if
(hardyPioneer.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION).size() == 0) {
Modifier m = new Modifier(Modifier.TILE_TYPE_CHANGE_PRODUCTION,
2.0f, Modifier.ModifierType.MULTIPLICATIVE);
Scope scope = new Scope();
diff --git a/src/net/sf/freecol/common/model/Tile.java
b/src/net/sf/freecol/common/model/Tile.java
index 897fcc70acb..e1ebd454862 100644
--- a/src/net/sf/freecol/common/model/Tile.java
+++ b/src/net/sf/freecol/common/model/Tile.java
@@ -33,7 +33,6 @@ import java.util.function.ToIntFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -1661,15 +1660,24 @@ public final class Tile extends UnitLocation implements
Named, Ownable {
/**
* Get the production modifiers for this tile.
*
+ * @param result The {@code List} to fill into.
* @param goodsType The {@code GoodsType} to produce.
* @param unitType An optional {@code UnitType} to do the work.
* @return A stream of production {@code Modifier}s.
*/
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
- return (canProduce(goodsType, unitType) && tileItemContainer != null)
- ? tileItemContainer.getProductionModifiers(goodsType, unitType)
- : Stream.<Modifier>empty();
+ if (canProduce(goodsType, unitType) && tileItemContainer != null)
+ tileItemContainer.fillProductionModifiers(result, goodsType,
unitType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Modifier> getProductionModifiers(GoodsType goodsType, UnitType
unitType) {
+ List<Modifier> result = new ArrayList<>();
+ fillProductionModifiers(result, goodsType, unitType);
+ return result;
}
/**
diff --git a/src/net/sf/freecol/common/model/TileImprovement.java
b/src/net/sf/freecol/common/model/TileImprovement.java
index e04804c782e..7bde46857e1 100644
--- a/src/net/sf/freecol/common/model/TileImprovement.java
+++ b/src/net/sf/freecol/common/model/TileImprovement.java
@@ -25,7 +25,6 @@ import java.util.Map;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -502,17 +501,16 @@ public class TileImprovement extends TileItem implements
Named {
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
final Specification spec = getSpecification();
Modifier m;
- return (goodsType != null && isComplete()
+ if (goodsType != null && isComplete()
&& !(/* unattended */ !isNatural() && unitType == null
&& !goodsType.isFoodType()
&& spec.getBoolean(GameOptions.ONLY_NATURAL_IMPROVEMENTS))
&& (m = getProductionModifier(goodsType)) != null)
- ? Stream.of(m)
- : Stream.<Modifier>empty();
+ result.add(m);
}
/**
diff --git a/src/net/sf/freecol/common/model/TileItem.java
b/src/net/sf/freecol/common/model/TileItem.java
index 4b98f642fc0..5b9b2ba8f3f 100644
--- a/src/net/sf/freecol/common/model/TileItem.java
+++ b/src/net/sf/freecol/common/model/TileItem.java
@@ -19,8 +19,9 @@
package net.sf.freecol.common.model;
+import java.util.ArrayList;
import java.util.logging.Logger;
-import java.util.stream.Stream;
+import java.util.List;
import javax.xml.stream.XMLStreamException;
@@ -121,14 +122,28 @@ public abstract class TileItem extends FreeColGameObject
UnitType unitType);
/**
+ * Fill in the production modifiers for the given type of goods and unit.
+ *
+ * @param result The {@code List} to fill into.
+ * @param goodsType The {@code GoodsType} to produce.
+ * @param unitType The optional {@code unitType} to produce them.
+ */
+ public abstract void fillProductionModifiers(List<Modifier> mods,
GoodsType goodsType,
+ UnitType unitType);
+
+ /**
* Gets the production modifiers for the given type of goods and unit.
*
* @param goodsType The {@code GoodsType} to produce.
* @param unitType The optional {@code unitType} to produce them.
* @return A stream of the applicable modifiers.
*/
- public abstract Stream<Modifier> getProductionModifiers(GoodsType
goodsType,
- UnitType unitType);
+ public List<Modifier> getProductionModifiers(GoodsType goodsType,
+ UnitType unitType)
{
+ List<Modifier> result = new ArrayList<>();
+ fillProductionModifiers(result, goodsType, unitType);
+ return result;
+ }
/**
* Is this a natural TileItem?
diff --git a/src/net/sf/freecol/common/model/TileItemContainer.java
b/src/net/sf/freecol/common/model/TileItemContainer.java
index 7d4f0aeb7c8..72e04532686 100644
--- a/src/net/sf/freecol/common/model/TileItemContainer.java
+++ b/src/net/sf/freecol/common/model/TileItemContainer.java
@@ -22,7 +22,6 @@ package net.sf.freecol.common.model;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -419,11 +418,11 @@ public class TileItemContainer extends FreeColGameObject {
* @param unitType The optional {@code unitType} to produce them.
* @return A stream of the applicable {@code Modifier}s.
*/
- public Stream<Modifier> getProductionModifiers(GoodsType goodsType,
+ public void fillProductionModifiers(List<Modifier> result, GoodsType
goodsType,
UnitType unitType) {
synchronized (tileItems) {
- return flatten(tileItems,
- ti -> ti.getProductionModifiers(goodsType, unitType));
+ for (TileItem ti : tileItems)
+ ti.fillProductionModifiers(result, goodsType, unitType);
}
}
diff --git a/src/net/sf/freecol/common/model/Unit.java
b/src/net/sf/freecol/common/model/Unit.java
index 41a21952375..f288085f91b 100644
--- a/src/net/sf/freecol/common/model/Unit.java
+++ b/src/net/sf/freecol/common/model/Unit.java
@@ -28,7 +28,6 @@ import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import java.util.logging.Logger;
import javax.xml.stream.XMLStreamException;
@@ -3226,12 +3225,13 @@ public class Unit extends GoodsLocation
*/
public int getLineOfSight() {
final Turn turn = getGame().getTurn();
- return (int)applyModifiers(unitType.getLineOfSight(), turn,
- Stream.concat(this.getModifiers(Modifier.LINE_OF_SIGHT_BONUS,
- unitType, turn),
- ((hasTile() && getTile().isExplored())
- ?
getTile().getType().getModifiers(Modifier.LINE_OF_SIGHT_BONUS, unitType, turn)
- : Stream.<Modifier>empty())));
+ List<Modifier> modifiers = new ArrayList<>();
+
+ this.fillModifiers(modifiers, Modifier.LINE_OF_SIGHT_BONUS, unitType,
turn);
+ if (hasTile() && getTile().isExplored())
+ getTile().getType().fillModifiers(modifiers,
Modifier.LINE_OF_SIGHT_BONUS, unitType, turn);
+
+ return (int)applyModifiers(unitType.getLineOfSight(), turn, modifiers);
}
/**
@@ -4271,17 +4271,16 @@ public class Unit extends GoodsLocation
* {@inheritDoc}
*/
@Override
- public Stream<Modifier> getModifiers(String id, FreeColSpecObjectType
fcgot,
+ public void fillModifiers(List<Modifier> result, String id,
FreeColSpecObjectType fcgot,
Turn turn) {
- final Player owner = getOwner();
- final UnitType unitType = getType();
+ // UnitType modifiers always apply.
+ getType().fillModifiers(result, id, fcgot, turn);
+
+ // The player's modifiers apply.
+ getOwner().fillModifiers(result, id, fcgot, turn);
- return concat(// UnitType modifiers always apply.
- unitType.getModifiers(id, fcgot, turn),
- // The player's modifiers apply.
- owner.getModifiers(id, fcgot, turn),
- // Role modifiers apply.
- role.getModifiers(id, fcgot, turn));
+ // Role modifiers apply.
+ role.fillModifiers(result, id, fcgot, turn);
}
diff --git a/src/net/sf/freecol/common/model/WorkLocation.java
b/src/net/sf/freecol/common/model/WorkLocation.java
index 74362e90ac3..f69039ef2fa 100644
--- a/src/net/sf/freecol/common/model/WorkLocation.java
+++ b/src/net/sf/freecol/common/model/WorkLocation.java
@@ -19,6 +19,7 @@
package net.sf.freecol.common.model;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -26,7 +27,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -872,14 +872,30 @@ public abstract class WorkLocation extends UnitLocation
* unit type. If no unit is specified the unattended production
* is calculated.
*
+ * @param result The result list to fill into.
* @param goodsType The {@code GoodsType} to produce.
* @param unitType The optional {@code UnitType} to produce them.
- * @return A stream of the applicable modifiers.
*/
- public abstract Stream<Modifier> getProductionModifiers(GoodsType
goodsType,
+ public abstract void fillProductionModifiers(List<Modifier> result,
GoodsType goodsType,
UnitType unitType);
/**
+ * Gets the production modifiers for the given type of goods and
+ * unit type. If no unit is specified the unattended production
+ * is calculated.
+ *
+ * @param goodsType The {@code GoodsType} to produce.
+ * @param unitType The optional {@code UnitType} to produce them.
+ * @return A list of the applicable modifiers.
+ */
+ public List<Modifier> getProductionModifiers(GoodsType goodsType,
+ UnitType unitType)
{
+ List<Modifier> result = new ArrayList<>();
+ fillProductionModifiers(result, goodsType, unitType);
+ return result;
+ }
+
+ /**
* Get the production types available for this work location.
*
* @param unattended If true, get unattended production types.
diff --git a/src/net/sf/freecol/server/ai/NativeAIPlayer.java
b/src/net/sf/freecol/server/ai/NativeAIPlayer.java
index 87be4e3bac9..baf90fabdf1 100644
--- a/src/net/sf/freecol/server/ai/NativeAIPlayer.java
+++ b/src/net/sf/freecol/server/ai/NativeAIPlayer.java
@@ -816,7 +816,7 @@ public class NativeAIPlayer extends MissionAIPlayer {
for (NativeTradeItem nti : nt.getUnitToSettlement()) {
if (nti.priceIsSet()) continue;
int price = (int)FeatureContainer.applyModifiers(1.0f / anger
- * is.getPriceToBuy(nti.getGoods()), turn, modifiers);
+ * is.getPriceToBuy(nti.getGoods()), turn, new
ArrayList<>(modifiers));
for (int h = nti.getHaggleCount(); h >= 0; h--) {
price = NativeTrade.haggleUp(price);
}
@@ -837,7 +837,7 @@ public class NativeAIPlayer extends MissionAIPlayer {
}
for (NativeTradeItem nti : nt.getSettlementToUnit()) {
int price = (int)FeatureContainer.applyModifiers((float)anger
- * is.getPriceToSell(nti.getGoods()), turn, modifiers);
+ * is.getPriceToSell(nti.getGoods()), turn, new
ArrayList<>(modifiers));
for (int h = nti.getHaggleCount(); h >= 0; h--) {
price = NativeTrade.haggleDown(price);
}
diff --git a/src/net/sf/freecol/server/model/ServerPlayer.java
b/src/net/sf/freecol/server/model/ServerPlayer.java
index e49d8b2d602..836bdcf29d0 100644
--- a/src/net/sf/freecol/server/model/ServerPlayer.java
+++ b/src/net/sf/freecol/server/model/ServerPlayer.java
@@ -1927,7 +1927,7 @@ outer: for (Effect effect : effects) {
}
// Some modifiers are special
- for (Modifier m : iterable(father.getModifiers())) {
+ for (Modifier m : father.getModifiers()) {
if (Modifier.LINE_OF_SIGHT_BONUS.equals(m.getId())) {
// Check for tiles that are now visible. They need to be
// explored, and always updated so that units are visible.
diff --git a/test/src/net/sf/freecol/common/model/BuildingTest.java
b/test/src/net/sf/freecol/common/model/BuildingTest.java
index 5a1ea0492cc..92adb8eb592 100644
--- a/test/src/net/sf/freecol/common/model/BuildingTest.java
+++ b/test/src/net/sf/freecol/common/model/BuildingTest.java
@@ -689,13 +689,13 @@ public class BuildingTest extends FreeColTestCase {
List<Modifier> modifiers;
Colony colony = getStandardColony(2);
- modifiers = toList(colony.getModifiers(Modifier.DEFENCE));
+ modifiers = colony.getModifiers(Modifier.DEFENCE);
assertEquals(1, modifiers.size());
Modifier modifier = first(modifiers);
assertEquals(50f, modifier.getValue());
assertEquals(ModifierType.PERCENTAGE, modifier.getType());
- modifiers = toList(stockadeType.getModifiers(Modifier.DEFENCE));
+ modifiers = stockadeType.getModifiers(Modifier.DEFENCE);
assertEquals(1, modifiers.size());
modifier = first(modifiers);
assertEquals(100f, modifier.getValue());
@@ -703,7 +703,7 @@ public class BuildingTest extends FreeColTestCase {
assertEquals(0f, stockadeType.applyModifiers(0f, turn,
Modifier.MINIMUM_COLONY_SIZE));
- modifiers = toList(fortType.getModifiers(Modifier.DEFENCE));
+ modifiers = fortType.getModifiers(Modifier.DEFENCE);
assertEquals(1, modifiers.size());
modifier = first(modifiers);
assertEquals(150f, modifier.getValue());
@@ -711,7 +711,7 @@ public class BuildingTest extends FreeColTestCase {
assertEquals(0f, stockadeType.applyModifiers(0f, turn,
Modifier.MINIMUM_COLONY_SIZE));
- modifiers = toList(fortressType.getModifiers(Modifier.DEFENCE));
+ modifiers = fortressType.getModifiers(Modifier.DEFENCE);
assertEquals(1, modifiers.size());
modifier = first(modifiers);
assertEquals(200f, modifier.getValue());
@@ -827,6 +827,13 @@ public class BuildingTest extends FreeColTestCase {
colony.getNetProductionOf(horsesType));
}
+ public static boolean anyMod(List<Modifier> mods, Modifier modifier) {
+ for (Modifier m : mods)
+ if (m == modifier)
+ return true;
+ return false;
+ }
+
public void testTownhallProduction() {
final Game game = getGame();
game.setMap(getTestMap(true));
@@ -843,7 +850,7 @@ public class BuildingTest extends FreeColTestCase {
for (Unit u : building.getUnits()) u.setLocation(tile);
assertTrue("No initial modifiers",
- none(colony.getModifiers("model.goods.bells")));
+ colony.getModifiers("model.goods.bells").size() == 0);
assertEquals("Initial bell production", 1,
building.getTotalProductionOf(bellsType));
@@ -858,29 +865,25 @@ public class BuildingTest extends FreeColTestCase {
// Add Jefferson.
FoundingFather jefferson = spec()
.getFoundingFather("model.foundingFather.thomasJefferson");
- List<Modifier> modifiers =
toList(jefferson.getModifiers("model.goods.bells"));
+ List<Modifier> modifiers = jefferson.getModifiers("model.goods.bells");
assertEquals("Jefferson modifier size", 1, modifiers.size());
Modifier bellsModifier = first(modifiers);
owner.addFather(jefferson);
// Jefferson is a property of the player...
assertTrue("Jefferson should be present in player",
- any(owner.getModifiers("model.goods.bells"),
- m -> m == bellsModifier));
+ anyMod(owner.getModifiers("model.goods.bells"), bellsModifier));
assertTrue("Jefferson should be present in player in building scope",
- any(owner.getModifiers("model.goods.bells", townHallType, turn),
- m -> m == bellsModifier));
+ anyMod(owner.getModifiers("model.goods.bells", townHallType,
turn), bellsModifier));
assertFalse("Jefferson should not be present in player in unit scope",
- any(owner.getModifiers("model.goods.bells", freeColonistType,
turn),
- m -> m == bellsModifier));
+ anyMod(owner.getModifiers("model.goods.bells", freeColonistType,
turn), bellsModifier));
+
// ...not the colony,
assertFalse("Jefferson modifier should not be present in colony",
- any(colony.getModifiers("model.goods.bells"),
- m -> m == bellsModifier));
+ anyMod(colony.getModifiers("model.goods.bells"), bellsModifier));
// ...and the building modifiers do not have it.
assertFalse("Jefferson modifier should not be present in building
modifiers",
- any(building.getModifiers("model.goods.bells"),
- m -> m == bellsModifier));
+ anyMod(building.getModifiers("model.goods.bells"), bellsModifier));
// 3(colonist)
assertEquals("Production(Colonist/Jefferson)", 3,
@@ -1005,7 +1008,7 @@ public class BuildingTest extends FreeColTestCase {
: output.getAmount();
if (expect != output.getAmount()) {
assertTrue("Modifiers expected",
- count(type.getModifiers(outputType.getId())) >
0);
+ type.getModifiers().size() > 0);
}
assertEquals("Wrong productivity for " + type
+ " in " + building, expect, productivity);
diff --git a/test/src/net/sf/freecol/common/model/ColonyTest.java
b/test/src/net/sf/freecol/common/model/ColonyTest.java
index c30fcff0996..a8034b6c074 100644
--- a/test/src/net/sf/freecol/common/model/ColonyTest.java
+++ b/test/src/net/sf/freecol/common/model/ColonyTest.java
@@ -184,8 +184,12 @@ public class ColonyTest extends FreeColTestCase {
}
private int countParties(Colony colony) {
- return count(colony.getModifiers("model.goods.bells"),
- m ->
Specification.COLONY_GOODS_PARTY_SOURCE.equals(m.getSource()));
+ Modifier mods = colony.getModifiers("model.goods.bells");
+ int cnt = 0;
+ for (Modifier m : mods)
+ if (Specification.COLONY_GOODS_PARTY_SOURCE.equals(m.getSource()))
+ cnt++;
+ return cnt;
}
public void testTeaParty() {
diff --git a/test/src/net/sf/freecol/common/model/CombatTest.java
b/test/src/net/sf/freecol/common/model/CombatTest.java
index 7c5858ccbea..2ab01a91908 100644
--- a/test/src/net/sf/freecol/common/model/CombatTest.java
+++ b/test/src/net/sf/freecol/common/model/CombatTest.java
@@ -116,11 +116,11 @@ public class CombatTest extends FreeColTestCase {
assertFalse(colonist.hasAbility(Ability.AMBUSH_PENALTY));
final Modifier bigMovementPenalty
- = first(spec().getModifiers(Modifier.BIG_MOVEMENT_PENALTY));
+ = first(spec().getModifiers(Modifier.BIG_MOVEMENT_PENALTY);
final Modifier attackModifier
= first(spec().getModifiers(Modifier.ATTACK_BONUS));
final List<Modifier> veteranModifiers
- = toList(veteranType.getModifiers(Modifier.OFFENCE));
+ = veteranType.getModifiers(Modifier.OFFENCE);
assertEquals(1, veteranModifiers.size());
final Modifier veteranModifier = first(veteranModifiers);
@@ -139,7 +139,7 @@ public class CombatTest extends FreeColTestCase {
final Modifier fortifiedModifier
= first(spec().getModifiers(Modifier.FORTIFIED));
- final List<Modifier> hillsModifiers =
toList(hills.getDefenceModifiers());
+ final List<Modifier> hillsModifiers = hills.getDefenceModifiers();
assertEquals(1, hillsModifiers.size());
Modifier hillsModifier = first(hillsModifiers);
@@ -311,8 +311,8 @@ public class CombatTest extends FreeColTestCase {
Set<Modifier> defenceModifiers = combatModel
.getDefensiveModifiers(attacker, colonist);
- forEach(soldierRole.getModifiers(Modifier.DEFENCE),
- m -> assertTrue(defenceModifiers.contains(m)));
+ for (Modifier m : soldierRole.getModifiers(Modifier.DEFENCE))
+ assertTrue(defenceModifiers.contains(m));
}
public void testDefendSettlement() {
@@ -345,8 +345,8 @@ public class CombatTest extends FreeColTestCase {
Set<Modifier> defenceModifiers = combatModel
.getDefensiveModifiers(attacker, defender);
- forEach(nativeDragoonRole.getModifiers(Modifier.DEFENCE),
- m -> assertTrue(defenceModifiers.contains(m)));
+ for (Modifier m : nativeDragoonRole.getModifiers(Modifier.DEFENCE))
+ assertTrue(defenceModifiers.contains(m));
}
public void testAttackIgnoresMovementPoints() throws Exception {
diff --git a/test/src/net/sf/freecol/common/model/FoundingFatherTest.java
b/test/src/net/sf/freecol/common/model/FoundingFatherTest.java
index a9bea46ee66..93f75dd1a65 100644
--- a/test/src/net/sf/freecol/common/model/FoundingFatherTest.java
+++ b/test/src/net/sf/freecol/common/model/FoundingFatherTest.java
@@ -69,7 +69,7 @@ public class FoundingFatherTest extends FreeColTestCase {
spec().addModifier(modifier);
dutch.addFather(father2);
- List<Modifier> modifiers =
toList(dutch.getModifiers("some.new.modifier"));
+ List<Modifier> modifiers = dutch.getModifiers("some.new.modifier");
assertEquals(1, modifiers.size());
assertEquals(2f, first(modifiers).getValue());
assertEquals(4f, FeatureContainer.applyModifiers(2, null, modifiers));
@@ -80,7 +80,7 @@ public class FoundingFatherTest extends FreeColTestCase {
ModifierType.ADDITIVE, father3));
dutch.addFather(father3);
- assertTrue(any(dutch.getModifiers("some.new.modifier")));
+ assertTrue(dutch.getModifiers("some.new.modifier").size() > 0);
assertEquals(6f, dutch.applyModifiers(2, null, "some.new.modifier"));
FoundingFather father4 = new FoundingFather("father4", spec());
diff --git a/test/src/net/sf/freecol/common/model/IndividualFatherTest.java
b/test/src/net/sf/freecol/common/model/IndividualFatherTest.java
index d1588e6d6dc..17dfa27230b 100644
--- a/test/src/net/sf/freecol/common/model/IndividualFatherTest.java
+++ b/test/src/net/sf/freecol/common/model/IndividualFatherTest.java
@@ -253,16 +253,16 @@ public class IndividualFatherTest extends FreeColTestCase
{
Unit unit = colony.getFirstUnit();
townHall.add(unit);
- assertTrue(none(player.getModifiers("model.goods.bells")));
- assertTrue(none(colony.getModifiers("model.goods.bells")));
+ assertTrue(player.getModifiers("model.goods.bells").size() == 0);
+ assertTrue(colony.getModifiers("model.goods.bells").size() == 0);
int expected = 4;
assertEquals(expected, townHall.getTotalProductionOf(bellsType));
player.addFather(thomasJefferson);
expected += expected * 0.5; // Add Jefferson bonus
assertEquals(1, count(player.getModifiers("model.goods.bells")));
- assertTrue(none(colony.getModifiers("model.goods.bells")));
- assertEquals(1, count(townHall.getProductionModifiers(bellsType,
null)));
+ assertTrue(colony.getModifiers("model.goods.bells").size() == 0);
+ assertTrue(townHall.getProductionModifiers(bellsType, null).size() ==
1);
assertEquals(expected, townHall.getTotalProductionOf(bellsType));
}
@@ -336,7 +336,7 @@ public class IndividualFatherTest extends FreeColTestCase {
player.recalculateBellsBonus();
assertTrue(player.hasAbility(Ability.ADD_TAX_TO_BELLS));
- List<Modifier> modifiers =
toList(player.getModifiers("model.goods.bells"));
+ List<Modifier> modifiers = player.getModifiers("model.goods.bells");
assertEquals(1, count(modifiers));
Modifier paineModifier = first(modifiers);
diff --git a/test/src/net/sf/freecol/common/model/ModifierTest.java
b/test/src/net/sf/freecol/common/model/ModifierTest.java
index 0911273a633..1be9a53ce48 100644
--- a/test/src/net/sf/freecol/common/model/ModifierTest.java
+++ b/test/src/net/sf/freecol/common/model/ModifierTest.java
@@ -155,12 +155,12 @@ public class ModifierTest extends FreeColTestCase {
assertFalse(modifier1.appliesTo(carpenter));
List<Modifier> result
- = toList(featureContainer.getModifiers("test", frigate, null));
+ = featureContainer.getModifiers("test", frigate, null);
assertEquals(3, result.size());
assertEquals(((1 + 3) * 1.5f) + ((1 + 3) * 1.5f) * 30 / 100,
FeatureContainer.applyModifiers(1, null, result));
- result = toList(featureContainer.getModifiers("test", carpenter,
null));
+ result = featureContainer.getModifiers("test", carpenter, null);
assertEquals(2, result.size());
assertEquals(1.5f + (1.5f * 30) / 100,
FeatureContainer.applyModifiers(1, null, result));
@@ -172,12 +172,12 @@ public class ModifierTest extends FreeColTestCase {
assertTrue(modifier2.appliesTo(frigate));
assertTrue(modifier2.appliesTo(carpenter));
- result = toList(featureContainer.getModifiers("test", frigate, null));
+ result = featureContainer.getModifiers("test", frigate, null);
assertEquals(3, result.size());
assertEquals(((1 + 3) * 1.5f) + ((1 + 3) * 1.5f) * 30 / 100,
FeatureContainer.applyModifiers(1, null, result));
- result = toList(featureContainer.getModifiers("test", carpenter,
null));
+ result = featureContainer.getModifiers("test", carpenter, null);
assertEquals(2, result.size());
assertEquals(1.5f + (1.5f * 30) / 100,
FeatureContainer.applyModifiers(1, null, result));
@@ -210,10 +210,10 @@ public class ModifierTest extends FreeColTestCase {
FeatureContainer featureContainer = new FeatureContainer();
featureContainer.addModifier(modifier1);
featureContainer.addModifier(modifier2);
- List<Modifier> modifiers =
toList(featureContainer.getModifiers("test", frigate, new Turn(15)));
+ List<Modifier> modifiers = featureContainer.getModifiers("test",
frigate, new Turn(15));
assertEquals(1, modifiers.size());
assertEquals(modifier1, first(modifiers));
- modifiers = toList(featureContainer.getModifiers("test", frigate, new
Turn(35)));
+ modifiers = featureContainer.getModifiers("test", frigate, new
Turn(35));
assertEquals(1, modifiers.size());
assertEquals(modifier2, first(modifiers));
}
diff --git a/test/src/net/sf/freecol/common/model/NationTypeTest.java
b/test/src/net/sf/freecol/common/model/NationTypeTest.java
index 629f3f81d6e..e5a5fe2db57 100644
--- a/test/src/net/sf/freecol/common/model/NationTypeTest.java
+++ b/test/src/net/sf/freecol/common/model/NationTypeTest.java
@@ -144,7 +144,7 @@ public class NationTypeTest extends FreeColTestCase {
Colony colony = getStandardColony();
colony.getOwner().changeNationType(spec().getNationType("model.nationType.building"));
- List<Modifier> modifiers =
toList(colony.getOwner().getModifiers("model.goods.hammers"));
+ List<Modifier> modifiers =
colony.getOwner().getModifiers("model.goods.hammers");
assertEquals(1, modifiers.size());
BuildingType carpenterHouse =
spec().getBuildingType("model.building.carpenterHouse");
@@ -157,7 +157,7 @@ public class NationTypeTest extends FreeColTestCase {
colony.getOwner().changeNationType(spec().getNationType("model.nationType.furTrapping"));
- modifiers =
toList(colony.getOwner().getModifiers("model.goods.coats"));
+ modifiers = colony.getOwner().getModifiers("model.goods.coats");
assertEquals(1, modifiers.size());
BuildingType traderHouse =
spec().getBuildingType("model.building.furTraderHouse");
diff --git a/test/src/net/sf/freecol/common/model/TileTest.java
b/test/src/net/sf/freecol/common/model/TileTest.java
index 80888e32cc6..f5cf63b5d28 100644
--- a/test/src/net/sf/freecol/common/model/TileTest.java
+++ b/test/src/net/sf/freecol/common/model/TileTest.java
@@ -20,7 +20,6 @@
package net.sf.freecol.common.model;
import java.util.List;
-import java.util.stream.Stream;
import static net.sf.freecol.common.util.CollectionUtils.*;
import net.sf.freecol.util.test.FreeColTestCase;
@@ -525,9 +524,12 @@ public class TileTest extends FreeColTestCase {
mineralsResource));
}
- private boolean hasBonusFrom(Stream<Modifier> modifierSet,
+ private boolean hasBonusFrom(List<Modifier> modifierSet,
FreeColSpecObjectType source) {
- return any(modifierSet, matchKeyEquals(source, Modifier::getSource));
+ for (Modifier m : modifierSet)
+ if (Utils.equals(source, m.getSource()))
+ return true;
+ return false;
}
diff --git a/test/src/net/sf/freecol/server/model/ServerUnitTest.java
b/test/src/net/sf/freecol/server/model/ServerUnitTest.java
index 324a50d4bd6..bd96aca16dd 100644
--- a/test/src/net/sf/freecol/server/model/ServerUnitTest.java
+++ b/test/src/net/sf/freecol/server/model/ServerUnitTest.java
@@ -484,10 +484,9 @@ public class ServerUnitTest extends FreeColTestCase {
colony.getGoodsCount(lumberType));
// Upgrade to lumber mill
-
assertTrue(none(colony.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION)));
+
assertTrue(colony.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION).size() ==
0);
colony.getBuilding(carpenterHouseType).upgrade();
- assertEquals(1,
- count(colony.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION)));
+
assertTrue(colony.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION).size() ==
1);
// Almost clear another tile
Tile tile2 = tile.getNeighbourOrNull(Direction.N);
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/freecol-developers