From: "Enrico Weigelt, metux IT consult" <[email protected]>
---
.../gui/panel/report/ReportCompactColonyPanel.java | 31 ++++++++++++++--------
.../sf/freecol/common/util/CollectionUtils.java | 15 -----------
2 files changed, 20 insertions(+), 26 deletions(-)
diff --git
a/src/net/sf/freecol/client/gui/panel/report/ReportCompactColonyPanel.java
b/src/net/sf/freecol/client/gui/panel/report/ReportCompactColonyPanel.java
index 77e7789262a..e2f0598061f 100644
--- a/src/net/sf/freecol/client/gui/panel/report/ReportCompactColonyPanel.java
+++ b/src/net/sf/freecol/client/gui/panel/report/ReportCompactColonyPanel.java
@@ -30,7 +30,6 @@ import java.util.Map.Entry;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
-import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -99,18 +98,28 @@ public final class ReportCompactColonyPanel extends
ReportPanel
CONSUMPTION, // Positive production but could consume more
};
- public static BinaryOperator<GoodsProduction>
goodsProductionAccumulator
- = (g1, g2) -> {
- g1.amount += g2.amount;
- g1.status = (g1.status == ProductionStatus.NONE
- && g2.status == ProductionStatus.NONE)
+ public static void
accumulateGoodsProduction(Map<GoodsType,GoodsProduction> map, GoodsType key,
GoodsProduction value) {
+ if (!map.containsKey(key)) {
+ map.put(key, value);
+ return;
+ }
+
+ GoodsProduction old = map.get(key);
+ old.amount += value.amount;
+ old.status = (old.status == ProductionStatus.NONE
+ && value.status == ProductionStatus.NONE)
? ProductionStatus.NONE
- : (g1.amount < 0) ? ProductionStatus.BAD
- : (g1.amount > 0) ? ProductionStatus.GOOD
+ : (old.amount < 0) ? ProductionStatus.BAD
+ : (old.amount > 0) ? ProductionStatus.GOOD
: ProductionStatus.ZERO;
- g1.extra = 0;
- return g1;
- };
+ old.extra = 0;
+ map.put(key, old);
+ }
+
+ public static void
accumulateGoodsProduction(Map<GoodsType,GoodsProduction> map,
Map<GoodsType,GoodsProduction> src) {
+ for (Map.Entry<GoodsType,GoodsProduction> e : src.entrySet())
+ accumulateGoodsProduction(map, e.getKey(), e.getValue());
+ }
/** Container class for goods production. */
public static class GoodsProduction {
diff --git a/src/net/sf/freecol/common/util/CollectionUtils.java
b/src/net/sf/freecol/common/util/CollectionUtils.java
index c04755bde02..45cd68c77c1 100644
--- a/src/net/sf/freecol/common/util/CollectionUtils.java
+++ b/src/net/sf/freecol/common/util/CollectionUtils.java
@@ -151,21 +151,6 @@ public class CollectionUtils {
}
}
- public static <K,V> void accumulateToMap(Map<K,V> map, K key, V value,
- BinaryOperator<V> accumulator) {
- if (map.containsKey(key)) {
- map.put(key, accumulator.apply(map.get(key), value));
- } else {
- map.put(key, value);
- }
- }
-
- public static <K,V> void accumulateMap(Map<K,V> map1, Map<K,V> map2,
- BinaryOperator<V> accumulator) {
- forEachMapEntry(map2,
- e -> accumulateToMap(map1, e.getKey(), e.getValue(), accumulator));
- }
-
/**
* Increment the count in an integer valued map for a given key.
*
--
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