From: "Enrico Weigelt, metux IT consult" <[email protected]>
---
src/net/sf/freecol/common/model/Colony.java | 13 +++++++++----
src/net/sf/freecol/common/model/Tile.java | 8 ++++----
src/net/sf/freecol/common/model/TileImprovement.java | 7 +++----
src/net/sf/freecol/common/model/TileImprovementType.java | 12 ++++++------
src/net/sf/freecol/common/model/TileType.java | 12 ++++++------
5 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/src/net/sf/freecol/common/model/Colony.java
b/src/net/sf/freecol/common/model/Colony.java
index cd62183f987..0fd5cfc0c2b 100644
--- a/src/net/sf/freecol/common/model/Colony.java
+++ b/src/net/sf/freecol/common/model/Colony.java
@@ -929,13 +929,18 @@ public class Colony extends Settlement implements
Nameable, TradeLocation {
* colony. This list comprises all natural disasters that can
* strike the colony's tiles.
*
- * @return A stream of {@code Disaster}s.
+ * @param result List to fill results into {@code Disaster}s.
*/
- public Stream<RandomChoice<Disaster>> getDisasterChoices() {
- return flatten(getColonyTiles(),
- ct -> ct.getWorkTile().getDisasterChoices());
+ public void getDisasterChoices(List<RandomChoice<Disaster>> result) {
+ for (ColonyTile ct : getColonyTiles())
+ ct.getWorkTile().getDisasterChoices(result);
}
+ public List<RandomChoice<Disaster>> getDisasterChoices() {
+ List<RandomChoice<Disaster>> result = new ArrayList<>();
+ getDisasterChoices(result);
+ return result;
+ }
// What are we building? What can we build?
diff --git a/src/net/sf/freecol/common/model/Tile.java
b/src/net/sf/freecol/common/model/Tile.java
index ecbef32a9a5..ed0957a15d0 100644
--- a/src/net/sf/freecol/common/model/Tile.java
+++ b/src/net/sf/freecol/common/model/Tile.java
@@ -1006,10 +1006,10 @@ public final class Tile extends UnitLocation implements
Named, Ownable {
*
* @return A stream of {@code Disaster} choices.
*/
- public Stream<RandomChoice<Disaster>> getDisasterChoices() {
- return concat(type.getDisasterChoices(),
- flatten(getCompleteTileImprovements(),
- ti -> ti.getDisasterChoices()));
+ public void getDisasterChoices(List<RandomChoice<Disaster>> result) {
+ type.getDisasterChoices(result);
+ for (TileImprovement ti : getCompleteTileImprovements())
+ ti.getDisasterChoices(result);
}
diff --git a/src/net/sf/freecol/common/model/TileImprovement.java
b/src/net/sf/freecol/common/model/TileImprovement.java
index 4093d939f73..e04804c782e 100644
--- a/src/net/sf/freecol/common/model/TileImprovement.java
+++ b/src/net/sf/freecol/common/model/TileImprovement.java
@@ -431,10 +431,9 @@ public class TileImprovement extends TileItem implements
Named {
*
* @return A stream of {@code Disaster} choices.
*/
- public Stream<RandomChoice<Disaster>> getDisasterChoices() {
- return (this.type == null)
- ? Stream.<RandomChoice<Disaster>>empty()
- : this.type.getDisasterChoices();
+ public void getDisasterChoices(List<RandomChoice<Disaster>> result) {
+ if (this.type != null)
+ this.type.getDisasterChoices(result);
}
diff --git a/src/net/sf/freecol/common/model/TileImprovementType.java
b/src/net/sf/freecol/common/model/TileImprovementType.java
index 50c18c4a689..85792d37afd 100644
--- a/src/net/sf/freecol/common/model/TileImprovementType.java
+++ b/src/net/sf/freecol/common/model/TileImprovementType.java
@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.stream.Stream;
import javax.xml.stream.XMLStreamException;
@@ -178,10 +177,9 @@ public final class TileImprovementType extends
FreeColSpecObjectType {
*
* @return A stream of {@code Disaster} choices.
*/
- public Stream<RandomChoice<Disaster>> getDisasterChoices() {
- return (disasters == null)
- ? Stream.<RandomChoice<Disaster>>empty()
- : disasters.stream();
+ public void getDisasterChoices(List<RandomChoice<Disaster>> result) {
+ if (disasters != null)
+ result.addAll(disasters);
}
/**
@@ -471,7 +469,9 @@ public final class TileImprovementType extends
FreeColSpecObjectType {
}
}
- for (RandomChoice<Disaster> choice : iterable(getDisasterChoices())) {
+ List<RandomChoice<Disaster>> desasters = new ArrayList<>();
+ getDisasterChoices(desasters);
+ for (RandomChoice<Disaster> choice : desasters) {
xw.writeStartElement(DISASTER_TAG);
xw.writeAttribute(ID_ATTRIBUTE_TAG, choice.getObject().getId());
diff --git a/src/net/sf/freecol/common/model/TileType.java
b/src/net/sf/freecol/common/model/TileType.java
index 860b36c4371..e0e50d35a5d 100644
--- a/src/net/sf/freecol/common/model/TileType.java
+++ b/src/net/sf/freecol/common/model/TileType.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 javax.xml.stream.XMLStreamException;
@@ -262,10 +261,9 @@ public final class TileType extends FreeColSpecObjectType
*
* @return A stream of {@code Disaster} choices.
*/
- public Stream<RandomChoice<Disaster>> getDisasterChoices() {
- return (this.disasters == null)
- ? Stream.<RandomChoice<Disaster>>empty()
- : disasters.stream();
+ public void getDisasterChoices(List<RandomChoice<Disaster>> result) {
+ if (disasters != null)
+ result.addAll(disasters);
}
/**
@@ -474,7 +472,9 @@ public final class TileType extends FreeColSpecObjectType
xw.writeEndElement();
}
- for (RandomChoice<Disaster> choice : iterable(getDisasterChoices())) {
+ List<RandomChoice<Disaster>> desasters = new ArrayList<>();
+ getDisasterChoices(desasters);
+ for (RandomChoice<Disaster> choice : desasters) {
xw.writeStartElement(DISASTER_TAG);
xw.writeAttribute(ID_ATTRIBUTE_TAG, choice.getObject());
--
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