From: "Enrico Weigelt, metux IT consult" <[email protected]>
---
.../gui/panel/colopedia/BuildingDetailPanel.java | 2 +-
src/net/sf/freecol/common/model/Ability.java | 3 +++
src/net/sf/freecol/common/model/Building.java | 2 +-
src/net/sf/freecol/common/model/Colony.java | 12 ++++++---
src/net/sf/freecol/common/model/Europe.java | 16 ++++++------
.../sf/freecol/common/model/FeatureContainer.java | 16 ++++++------
src/net/sf/freecol/common/model/FreeColObject.java | 20 +++++++--------
src/net/sf/freecol/common/model/Specification.java | 10 ++++----
src/net/sf/freecol/common/model/Tile.java | 2 +-
src/net/sf/freecol/common/model/Unit.java | 29 ++++++++++++----------
10 files changed, 63 insertions(+), 49 deletions(-)
diff --git
a/src/net/sf/freecol/client/gui/panel/colopedia/BuildingDetailPanel.java
b/src/net/sf/freecol/client/gui/panel/colopedia/BuildingDetailPanel.java
index 22880927c2c..9e7f21ff76d 100644
--- a/src/net/sf/freecol/client/gui/panel/colopedia/BuildingDetailPanel.java
+++ b/src/net/sf/freecol/client/gui/panel/colopedia/BuildingDetailPanel.java
@@ -243,7 +243,7 @@ public class BuildingDetailPanel
}
});
- for (Ability ability : iterable(buildingType.getAbilities())) {
+ for (Ability ability : buildingType.getAbilities()) {
JComponent component = getAbilityComponent(ability);
if (component != null) {
labels.add(component);
diff --git a/src/net/sf/freecol/common/model/Ability.java
b/src/net/sf/freecol/common/model/Ability.java
index 0b67de495cc..9320f6125dc 100644
--- a/src/net/sf/freecol/common/model/Ability.java
+++ b/src/net/sf/freecol/common/model/Ability.java
@@ -19,6 +19,8 @@
package net.sf.freecol.common.model;
+import java.util.List;
+import java.util.ArrayList;
import javax.xml.stream.XMLStreamException;
import net.sf.freecol.common.io.FreeColXMLReader;
@@ -408,6 +410,7 @@ public final class Ability extends Feature {
public static final String UPGRADE_CONVERT
= "model.ability.upgradeConvert";
+ public static final List<Ability> EMPTY_LIST = new ArrayList<>();
/** The ability value. */
private boolean value = true;
diff --git a/src/net/sf/freecol/common/model/Building.java
b/src/net/sf/freecol/common/model/Building.java
index 46f5f95ee18..f3b13dea0cd 100644
--- a/src/net/sf/freecol/common/model/Building.java
+++ b/src/net/sf/freecol/common/model/Building.java
@@ -641,7 +641,7 @@ public class Building extends WorkLocation
* {@inheritDoc}
*/
@Override
- public Stream<Ability> getAbilities(String id, FreeColSpecObjectType type,
+ public List<Ability> getAbilities(String id, FreeColSpecObjectType type,
Turn turn) {
// Buildings have no abilities independent of their type (for now).
return getType().getAbilities(id, type, turn);
diff --git a/src/net/sf/freecol/common/model/Colony.java
b/src/net/sf/freecol/common/model/Colony.java
index 0fd5cfc0c2b..dcf6e936bd5 100644
--- a/src/net/sf/freecol/common/model/Colony.java
+++ b/src/net/sf/freecol/common/model/Colony.java
@@ -2528,12 +2528,16 @@ loop: for (WorkLocation wl :
getWorkLocationsForProducing(goodsType)) {
* {@inheritDoc}
*/
@Override
- public Stream<Ability> getAbilities(String id, FreeColSpecObjectType type,
+ public List<Ability> getAbilities(String id, FreeColSpecObjectType type,
Turn turn) {
if (turn == null) turn = getGame().getTurn();
- return concat(super.getAbilities(id, type, turn),
- ((owner == null) ? Stream.<Ability>empty()
- : owner.getAbilities(id, type, turn)));
+ List<Ability> result = super.getAbilities(id, type, turn);
+ if (owner != null) {
+ result = new ArrayList<>(result);
+ result.addAll(owner.getAbilities(id, type, turn));
+ }
+
+ return result;
}
diff --git a/src/net/sf/freecol/common/model/Europe.java
b/src/net/sf/freecol/common/model/Europe.java
index 839a60a9655..92f5f70af16 100644
--- a/src/net/sf/freecol/common/model/Europe.java
+++ b/src/net/sf/freecol/common/model/Europe.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@@ -505,13 +504,16 @@ public class Europe extends UnitLocation
* {@inheritDoc}
*/
@Override
- public Stream<Ability> getAbilities(String id, FreeColSpecObjectType fcgot,
+ public List<Ability> getAbilities(String id, FreeColSpecObjectType fcgot,
Turn turn) {
- return concat(super.getAbilities(id, fcgot, turn),
- // Always able to dress a missionary.
- ((id == null || Ability.DRESS_MISSIONARY.equals(id))
- ? Stream.of(ABILITY_DRESS_MISSIONARY)
- : Stream.<Ability>empty()));
+ List<Ability> result = super.getAbilities(id, fcgot, turn);
+
+ if (id == null || Ability.DRESS_MISSIONARY.equals(id)) {
+ result = new ArrayList<>(result);
+ result.add(ABILITY_DRESS_MISSIONARY);
+ }
+
+ return result;
}
diff --git a/src/net/sf/freecol/common/model/FeatureContainer.java
b/src/net/sf/freecol/common/model/FeatureContainer.java
index 3c5dbabe661..7091faaaf6e 100644
--- a/src/net/sf/freecol/common/model/FeatureContainer.java
+++ b/src/net/sf/freecol/common/model/FeatureContainer.java
@@ -18,6 +18,7 @@
*/
package net.sf.freecol.common.model;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -104,9 +105,9 @@ public final class FeatureContainer {
* @param abilities A stream of {@code Ability}s to check.
* @return True if the abilities are `satisfied'.
*/
- public static boolean hasAbility(Stream<Ability> abilities) {
+ public static boolean hasAbility(List<Ability> abilities) {
boolean ret = false;
- for (Ability ability : iterable(abilities)) {
+ for (Ability ability : abilities) {
if (!ability.getValue()) return false;
ret = true;
}
@@ -135,7 +136,7 @@ public final class FeatureContainer {
* @return True if the key is present.
*/
public boolean containsAbilityKey(String key) {
- return first(getAbilities(key, null, null)) != null;
+ return getAbilities(key, null, null).size() > 0;
}
/**
@@ -146,9 +147,9 @@ public final class FeatureContainer {
* @param fcgot An optional {@code FreeColSpecObjectType} the
* ability applies to.
* @param turn An optional applicable {@code Turn}.
- * @return A stream of abilities.
+ * @return A list of abilities.
*/
- public Stream<Ability> getAbilities(String id, FreeColSpecObjectType fcgot,
+ public List<Ability> getAbilities(String id, FreeColSpecObjectType fcgot,
Turn turn) {
Set<Ability> result = new HashSet<>();
if (abilitiesPresent()) {
@@ -164,7 +165,8 @@ public final class FeatureContainer {
}
removeInPlace(result, a -> !a.appliesTo(fcgot, turn));
}
- return result.stream();
+
+ return new ArrayList<>(result);
}
/**
@@ -504,7 +506,7 @@ public final class FeatureContainer {
StringBuilder sb = new StringBuilder(256);
sb.append("[FeatureContainer");
int siz = sb.length();
- for (Ability ability : iterable(getAbilities(null, null, null))) {
+ for (Ability ability : getAbilities(null, null, null)) {
sb.append(' ').append(ability);
}
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 25a8506f749..e93de77f818 100644
--- a/src/net/sf/freecol/common/model/FreeColObject.java
+++ b/src/net/sf/freecol/common/model/FreeColObject.java
@@ -434,7 +434,7 @@ public abstract class FreeColObject
* @return True if the key is present.
*/
public boolean containsAbilityKey(String key) {
- return first(getAbilities(key, null, null)) != null;
+ return getAbilities(key, null, null).size() > 0;
}
/**
@@ -449,9 +449,9 @@ public abstract class FreeColObject
/**
* Gets a copy of the abilities of this object.
*
- * @return A stream of abilities.
+ * @return A set of abilities.
*/
- public final Stream<Ability> getAbilities() {
+ public final List<Ability> getAbilities() {
return getAbilities(null);
}
@@ -459,9 +459,9 @@ public abstract class FreeColObject
* Gets the set of abilities with the given identifier from this object.
*
* @param id The object identifier.
- * @return A stream of abilities.
+ * @return A list of abilities.
*/
- public final Stream<Ability> getAbilities(String id) {
+ public final List<Ability> getAbilities(String id) {
return getAbilities(id, null);
}
@@ -471,9 +471,9 @@ public abstract class FreeColObject
* @param id The object identifier.
* @param fcgot An optional {@code FreeColSpecObjectType} the
* ability applies to.
- * @return A stream of abilities.
+ * @return A list of abilities.
*/
- public final Stream<Ability> getAbilities(String id,
+ public final List<Ability> getAbilities(String id,
FreeColSpecObjectType fcgot) {
return getAbilities(id, fcgot, null);
}
@@ -487,13 +487,13 @@ public abstract class FreeColObject
* @param fcgot An optional {@code FreeColSpecObjectType} the
* ability applies to.
* @param turn An optional applicable {@code Turn}.
- * @return A set of abilities.
+ * @return A list of abilities.
*/
- public Stream<Ability> getAbilities(String id,
+ public List<Ability> getAbilities(String id,
FreeColSpecObjectType fcgot,
Turn turn) {
FeatureContainer fc = getFeatureContainer();
- return (fc == null) ? Stream.<Ability>empty()
+ return (fc == null) ? Ability.EMPTY_LIST
: fc.getAbilities(id, fcgot, turn);
}
diff --git a/src/net/sf/freecol/common/model/Specification.java
b/src/net/sf/freecol/common/model/Specification.java
index 0ca84faa35c..0f949a02da3 100644
--- a/src/net/sf/freecol/common/model/Specification.java
+++ b/src/net/sf/freecol/common/model/Specification.java
@@ -631,8 +631,8 @@ public final class Specification {
// Apply the customs on coast restriction
boolean customsOnCoast = getBoolean(GameOptions.CUSTOMS_ON_COAST);
- for (Ability a : iterable(getBuildingType("model.building.customHouse")
- .getAbilities(Ability.COASTAL_ONLY))) {
+ for (Ability a : getBuildingType("model.building.customHouse")
+ .getAbilities(Ability.COASTAL_ONLY)) {
a.setValue(customsOnCoast);
}
@@ -922,9 +922,9 @@ public final class Specification {
* @param id The object identifier to look for.
* @return A stream of {@code Ability}s.
*/
- public Stream<Ability> getAbilities(String id) {
+ public List<Ability> getAbilities(String id) {
List<Ability> result = allAbilities.get(id);
- return (result == null) ? Stream.<Ability>empty() : result.stream();
+ return (result == null ? Collections.<Ability>emptyList() : result);
}
/**
@@ -2225,7 +2225,7 @@ public final class Specification {
}
// Ambush terrain ability not present in older specs.
- if (first(getAbilities(Ability.AMBUSH_TERRAIN)) == null){
+ if (getAbilities(Ability.AMBUSH_TERRAIN).size() == 0) {
Ability ambush = new Ability(Ability.AMBUSH_TERRAIN, null, true);
addAbility(ambush);
for (TileType tt : transform(getTileTypeList(), tt ->
diff --git a/src/net/sf/freecol/common/model/Tile.java
b/src/net/sf/freecol/common/model/Tile.java
index fab54bf459d..d524ed49f88 100644
--- a/src/net/sf/freecol/common/model/Tile.java
+++ b/src/net/sf/freecol/common/model/Tile.java
@@ -2349,7 +2349,7 @@ public final class Tile extends UnitLocation implements
Named, Ownable {
* {@inheritDoc}
*/
@Override
- public Stream<Ability> getAbilities(String id,
+ public List<Ability> getAbilities(String id,
FreeColSpecObjectType fcgot,
Turn turn) {
// Delegate to type
diff --git a/src/net/sf/freecol/common/model/Unit.java
b/src/net/sf/freecol/common/model/Unit.java
index 0660ebe3ac4..d49e7a004e6 100644
--- a/src/net/sf/freecol/common/model/Unit.java
+++ b/src/net/sf/freecol/common/model/Unit.java
@@ -4185,23 +4185,26 @@ public class Unit extends GoodsLocation
* {@inheritDoc}
*/
@Override
- public Stream <Ability> getAbilities(String id, FreeColSpecObjectType
fcgot,
+ public List<Ability> getAbilities(String id, FreeColSpecObjectType fcgot,
Turn turn) {
final Player owner = getOwner();
final UnitType unitType = getType();
- return concat(
- // UnitType abilities always apply.
- unitType.getAbilities(id),
+ ArrayList<Ability> result = new ArrayList<>();
- // Roles apply with qualification.
- role.getAbilities(id, fcgot, turn),
+ // UnitType abilities always apply.
+ result.addAll(unitType.getAbilities(id));
- // The player's abilities require more qualification.
- owner.getAbilities(id, fcgot, turn),
+ // Roles apply with qualification.
+ result.addAll(role.getAbilities(id, fcgot, turn));
- // Location abilities may apply.
- getLocationAbilities(id, turn));
+ // The player's abilities require more qualification.
+ result.addAll(owner.getAbilities(id, fcgot, turn));
+
+ // Location abilities may apply.
+ result.addAll(getLocationAbilities(id, turn));
+
+ return result;
}
/**
@@ -4219,13 +4222,13 @@ public class Unit extends GoodsLocation
* @param turn The turn that applies.
* @return A stream of {@code Ability}s found.
*/
- private Stream<Ability> getLocationAbilities(String id, Turn turn) {
+ private List<Ability> getLocationAbilities(String id, Turn turn) {
final UnitType unitType = getType();
final Settlement settlement = getSettlement();
if (settlement != null) {
return settlement.getAbilities(id, unitType, turn);
}
- if (!isInEurope()) return Stream.<Ability>empty();
+ if (!isInEurope()) return Ability.EMPTY_LIST;
// @compat 0.10.x
// Europe is special. It makes sense here to do:
@@ -4238,7 +4241,7 @@ public class Unit extends GoodsLocation
: (loc instanceof Unit) ? (Europe)((Unit)loc).getLocation()
: null;
// end @compat 0.10.x
- return (europe == null) ? Stream.<Ability>empty()
+ return (europe == null) ? Ability.EMPTY_LIST
: europe.getAbilities(id, getType(), turn);
}
--
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