From 175db96e4f82a7bc9716a317d450ea9cfc9692e5 Mon Sep 17 00:00:00 2001 From: Northmoc Date: Mon, 26 Jul 2021 19:44:19 -0400 Subject: [PATCH] CardFactoryUtil - add getMostProminentCreatureType --- .../java/forge/game/card/CardFactoryUtil.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java b/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java index d8dfbfa04bb..674b7144116 100644 --- a/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java @@ -421,7 +421,7 @@ public class CardFactoryUtil { /** *

- * getMostProminentCreatureType. + * getMostProminentCreatureTypeSize. *

* * @param list @@ -457,6 +457,49 @@ public class CardFactoryUtil { return max + allCreatureType; } + /** + *

+ * getMostProminentCreatureType. + *

+ * + * @param list + * a {@link forge.game.card.CardCollection} object. + * @return a string. + */ + public static String[] getMostProminentCreatureType(final CardCollectionView list) { + if (list.isEmpty()) { + return null; + } + + final Map map = Maps.newHashMap(); + for (final Card c : list) { + // Remove Duplicated types + final Set creatureTypes = c.getType().getCreatureTypes(); + for (String creatureType : creatureTypes) { + Integer count = map.get(creatureType); + map.put(creatureType, count == null ? 1 : count + 1); + } + } + + int max = 0; + for (final Entry entry : map.entrySet()) { + if (max < entry.getValue()) { + max = entry.getValue(); + } + } + if (max == 0) { + return null; + } + StringBuilder sb = new StringBuilder(); + for (final Entry entry : map.entrySet()) { + if (max == entry.getValue()) { + sb.append(entry.getKey()).append(","); + } + } + + return sb.toString().split(","); + } + /** *

* sharedKeywords.