Removal of functions from forge.util.closure.Predicate in favour of Guava routines

This commit is contained in:
Maxmtg
2012-09-26 20:11:36 +00:00
parent a54f3e4e8e
commit d0d45034fd
35 changed files with 331 additions and 869 deletions

1
.gitattributes vendored
View File

@@ -12570,6 +12570,7 @@ src/main/java/forge/quest/io/QuestDataIO.java svneol=native#text/plain
src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain
src/main/java/forge/quest/io/package-info.java svneol=native#text/plain src/main/java/forge/quest/io/package-info.java svneol=native#text/plain
src/main/java/forge/quest/package-info.java svneol=native#text/plain src/main/java/forge/quest/package-info.java svneol=native#text/plain
src/main/java/forge/util/Aggregates.java -text
src/main/java/forge/util/Base64Coder.java svneol=native#text/plain src/main/java/forge/util/Base64Coder.java svneol=native#text/plain
src/main/java/forge/util/BinaryUtil.java -text src/main/java/forge/util/BinaryUtil.java -text
src/main/java/forge/util/CopyFiles.java svneol=native#text/plain src/main/java/forge/util/CopyFiles.java svneol=native#text/plain

View File

@@ -19,7 +19,6 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@@ -77,11 +76,11 @@ public class CardList extends ArrayList<Card> {
* criteria; may be empty, but never null. * criteria; may be empty, but never null.
*/ */
public final CardList filter(final Predicate<Card> filt) { public final CardList filter(final Predicate<Card> filt) {
return new CardList(filt.select(this)); return new CardList(Iterables.filter(this, filt));
} }
public final boolean containsName(final String name) { public final boolean containsName(final String name) {
return CardPredicates.nameEquals(name).any(this); return Iterables.any(this, CardPredicates.nameEquals(name));
} }
public final CardList getController(final Player player) { public final CardList getController(final Player player) {

View File

@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
import forge.util.Aggregates;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
/** /**
@@ -237,7 +238,7 @@ public class CardListUtil {
* @return a int. * @return a int.
*/ */
public static int sumCMC(final CardList c) { public static int sumCMC(final CardList c) {
return CardPredicates.Presets.All.sum(c, CardPredicates.Accessors.fnGetCmc); return Aggregates.sum(c, CardPredicates.Accessors.fnGetCmc);
} // sumCMC } // sumCMC
/** /**

View File

@@ -17,6 +17,8 @@
*/ */
package forge; package forge;
import com.google.common.collect.Iterables;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.game.phase.CombatUtil; import forge.game.phase.CombatUtil;
import forge.game.player.Player; import forge.game.player.Player;
@@ -73,7 +75,7 @@ public final class CardPredicates {
return new Predicate<Card>() { return new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return PredicateString.contains(keyword).any(c.getKeyword()); return Iterables.any(c.getKeyword(), PredicateString.contains(keyword));
} }
}; };
} }

View File

@@ -30,6 +30,8 @@ import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Iterables;
import forge.card.CardCharacteristics; import forge.card.CardCharacteristics;
import forge.card.CardManaCost; import forge.card.CardManaCost;
import forge.card.EditionInfo; import forge.card.EditionInfo;
@@ -462,7 +464,7 @@ public final class CardUtil {
return subject.getCode().equals(set); return subject.getCode().equals(set);
} }
}; };
final EditionInfo neededSet = findSetInfo.first(card.getSets()); final EditionInfo neededSet = Iterables.find(card.getSets(), findSetInfo);
final int cntPictures = neededSet == null ? 1 : neededSet.getPicCount(); final int cntPictures = neededSet == null ? 1 : neededSet.getPicCount();
return CardUtil return CardUtil
.buildFilename(card.getName(), card.getCurSetCode(), card.getRandomPicture(), cntPictures, token); .buildFilename(card.getName(), card.getCurSetCode(), card.getRandomPicture(), cntPictures, token);

View File

@@ -24,6 +24,8 @@ import java.util.Map.Entry;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.TreeMap; import java.util.TreeMap;
import com.google.common.collect.Lists;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
@@ -154,7 +156,7 @@ public class NameChanger {
*/ */
public final CardList changeCardsIfNeeded(CardList list) { public final CardList changeCardsIfNeeded(CardList list) {
if (this.shouldChangeCardName()) { if (this.shouldChangeCardName()) {
list = new CardList(fnTransformCard.applyToIterable(list)); list = new CardList( Lists.transform(list, fnTransformCard) );
} }
return list; return list;
} }

View File

@@ -24,6 +24,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.google.common.collect.Iterables;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
@@ -120,7 +122,7 @@ public class BoosterGenerator {
public BoosterGenerator(Predicate<CardPrinted> filter) { public BoosterGenerator(Predicate<CardPrinted> filter) {
this(); this();
for (final CardPrinted c : filter.select(CardDb.instance().getAllCards())) { for (final CardPrinted c : Iterables.filter(CardDb.instance().getAllCards(), filter)) {
this.addToRarity(c); this.addToRarity(c);
// System.out.println(c); // System.out.println(c);
} }

View File

@@ -110,14 +110,6 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
} }
}; };
/** The Constant fn1. */
public static final Lambda1<CardEdition, CardEdition> FN1 = new Lambda1<CardEdition, CardEdition>() {
@Override
public CardEdition apply(final CardEdition arg1) {
return arg1;
}
};
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View File

@@ -637,6 +637,10 @@ public final class CardRules {
return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor); return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
} }
public static Predicate<CardRules> isMonoColor(final byte thatColor) {
return new LeafColor(LeafColor.ColorOperator.Equals, thatColor);
}
/** /**
* Checks for cnt colors. * Checks for cnt colors.
* *

View File

@@ -22,6 +22,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Iterables;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
import forge.Card; import forge.Card;
@@ -495,7 +497,7 @@ public final class AbilityFactoryChangeZone {
if (params.containsKey("Ninjutsu")) { if (params.containsKey("Ninjutsu")) {
if (source.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) { if (source.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
if (CardPredicates.nameEquals(source.getName()).any(list)) { if (Iterables.any(list, CardPredicates.nameEquals(source.getName()))) {
return false; return false;
} }
} }

View File

@@ -23,6 +23,8 @@ import java.util.List;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import com.esotericsoftware.minlog.Log; import com.esotericsoftware.minlog.Log;
import com.google.common.collect.Iterables;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
import forge.Card; import forge.Card;
@@ -73,8 +75,7 @@ public class CardFactoryCreatures {
@Override @Override
public boolean canPlayAI() { public boolean canPlayAI() {
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
return Predicate.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem")).any(list); return Iterables.any(list, Predicate.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem")));
} }
}; };
// Do not remove SpellAbilities created by AbilityFactory or // Do not remove SpellAbilities created by AbilityFactory or

View File

@@ -29,16 +29,13 @@ import forge.Counters;
import forge.GameActionUtil; import forge.GameActionUtil;
import forge.Singletons; import forge.Singletons;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.spellability.Ability;
import forge.card.spellability.AbilityActivated; import forge.card.spellability.AbilityActivated;
import forge.card.spellability.AbilityMana;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.control.input.Input; import forge.control.input.Input;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiUtils;
import forge.gui.match.CMatchUI; import forge.gui.match.CMatchUI;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
import forge.view.ButtonUtil; import forge.view.ButtonUtil;

View File

@@ -26,6 +26,7 @@ import java.util.Random;
import java.util.TreeMap; import java.util.TreeMap;
import com.esotericsoftware.minlog.Log; import com.esotericsoftware.minlog.Log;
import com.google.common.collect.Iterables;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
@@ -72,6 +73,7 @@ import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.gui.match.CMatchUI; import forge.gui.match.CMatchUI;
import forge.util.Aggregates;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
import forge.view.ButtonUtil; import forge.view.ButtonUtil;
@@ -2478,7 +2480,7 @@ public class CardFactoryUtil {
list.add(AllZoneUtil.getCardState((Card) o)); list.add(AllZoneUtil.getCardState((Card) o));
} }
} }
return CardPredicates.Presets.hasSecondStrike.sum(list, CardPredicates.Accessors.fnGetAttack); return Aggregates.sum(Iterables.filter(list, CardPredicates.Presets.hasSecondStrike), CardPredicates.Accessors.fnGetAttack);
} }
if (l[0].contains("RememberedSize")) { if (l[0].contains("RememberedSize")) {

View File

@@ -19,6 +19,8 @@ package forge.card.spellability;
import java.util.HashMap; import java.util.HashMap;
import com.google.common.collect.Iterables;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
import forge.Card; import forge.Card;
@@ -347,7 +349,7 @@ public class SpellPermanent extends Spell {
// check on legendary // check on legendary
if (card.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) { if (card.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
if (CardPredicates.nameEquals(card.getName()).any(list)) { if (Iterables.any(list, CardPredicates.nameEquals(card.getName()))) {
return false; return false;
} }
} }

View File

@@ -24,6 +24,8 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Iterables;
import forge.Constant; import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.card.CardColor; import forge.card.CardColor;
@@ -34,6 +36,7 @@ import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.util.Aggregates;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
@@ -155,10 +158,11 @@ public abstract class GenerateColoredDeckBase {
addSome(diff, tDeck.toFlatList()); addSome(diff, tDeck.toFlatList());
} else if (actualSize > targetSize) { } else if (actualSize > targetSize) {
Predicate<CardRules> exceptBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND); Predicate<CardPrinted> exceptBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).brigde(CardPrinted.FN_GET_RULES);
for (int i = 0; i < 3 && actualSize > targetSize; i++) { for (int i = 0; i < 3 && actualSize > targetSize; i++) {
List<CardPrinted> toRemove = exceptBasicLand.random(tDeck.toFlatList(), CardPrinted.FN_GET_RULES, actualSize - targetSize); Iterable<CardPrinted> matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand);
List<CardPrinted> toRemove = Aggregates.random(matchingCards, actualSize - targetSize);
tDeck.removeAllFlat(toRemove); tDeck.removeAllFlat(toRemove);
for (CardPrinted c : toRemove) { for (CardPrinted c : toRemove) {
@@ -173,7 +177,8 @@ public abstract class GenerateColoredDeckBase {
final List<CardPrinted> curved = new ArrayList<CardPrinted>(); final List<CardPrinted> curved = new ArrayList<CardPrinted>();
for (int i = 0; i < cmcAmounts.length; i++) { for (int i = 0; i < cmcAmounts.length; i++) {
curved.addAll(cmcLevels.get(i).random(source, CardPrinted.FN_GET_RULES, cmcAmounts[i])); Iterable<CardPrinted> matchingCards = Iterables.filter(source, cmcLevels.get(i).brigde(CardPrinted.FN_GET_RULES));
curved.addAll( Aggregates.random(matchingCards, cmcAmounts[i]));
} }
for (CardPrinted c : curved) { for (CardPrinted c : curved) {

View File

@@ -5,6 +5,8 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Iterables;
import forge.Constant; import forge.Constant;
import forge.Constant.Color; import forge.Constant.Color;
import forge.card.CardColor; import forge.card.CardColor;
@@ -46,11 +48,14 @@ public class SealedDeck extends LimitedDeck {
System.out.println(cp.getName() + " " + cp.getCard().getManaCost().toString()); System.out.println(cp.getName() + " " + cp.getCard().getManaCost().toString());
} }
int white = CardRules.Predicates.Presets.IS_WHITE.count(colorChooserList, CardPrinted.FN_GET_RULES); Iterable<CardRules> rules = Iterables.transform(colorChooserList, CardPrinted.FN_GET_RULES);
int blue = CardRules.Predicates.Presets.IS_BLUE.count(colorChooserList, CardPrinted.FN_GET_RULES);
int black = CardRules.Predicates.Presets.IS_BLACK.count(colorChooserList, CardPrinted.FN_GET_RULES); int white = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_WHITE));
int red = CardRules.Predicates.Presets.IS_RED.count(colorChooserList, CardPrinted.FN_GET_RULES); int blue = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_BLUE));
int green = CardRules.Predicates.Presets.IS_GREEN.count(colorChooserList, CardPrinted.FN_GET_RULES); int black = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_BLACK));
int red = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_RED));
int green = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_GREEN));
final int[] colorCounts = { white, blue, black, red, green }; final int[] colorCounts = { white, blue, black, red, green };
final String[] colors = Constant.Color.ONLY_COLORS; final String[] colors = Constant.Color.ONLY_COLORS;
int[] countsCopy = Arrays.copyOf(colorCounts, 5); int[] countsCopy = Arrays.copyOf(colorCounts, 5);

View File

@@ -19,6 +19,8 @@ package forge.game.phase;
import java.util.ArrayList; import java.util.ArrayList;
import com.google.common.collect.Iterables;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
import forge.Card; import forge.Card;
@@ -2279,7 +2281,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.isEnchantment() && c.hasKeyword("Enchant player") return c.isEnchantment() && c.hasKeyword("Enchant player")
&& !source.getEnchantingPlayer().hasProtectionFrom(c) && !source.getEnchantingPlayer().hasProtectionFrom(c)
&& !CardPredicates.nameEquals(c.getName()).any(enchantmentsAttached); && !Iterables.any(enchantmentsAttached, CardPredicates.nameEquals(c.getName()));
} }
}); });
final Player player = source.getController(); final Player player = source.getController();

View File

@@ -22,6 +22,8 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang3.text.translate.AggregateTranslator;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
import forge.Card; import forge.Card;
@@ -53,6 +55,7 @@ import forge.game.phase.CombatUtil;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.util.Aggregates;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
/** /**
@@ -1332,7 +1335,7 @@ public class ComputerUtil {
CardList lands = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); CardList lands = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
lands.addAll(hand); lands.addAll(hand);
lands = lands.getType("Land"); lands = lands.getType("Land");
int maxCmcInHand = Predicate.getTrue(Card.class).max(hand, CardPredicates.Accessors.fnGetCmc); int maxCmcInHand = Aggregates.max(hand, CardPredicates.Accessors.fnGetCmc);
for (final SpellAbility sa : spellAbilities) { for (final SpellAbility sa : spellAbilities) {
if (sa.isCycling()) { if (sa.isCycling()) {
if (lands.size() >= Math.max(maxCmcInHand, 6)) { if (lands.size() >= Math.max(maxCmcInHand, 6)) {
@@ -2216,7 +2219,7 @@ public class ComputerUtil {
final CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Land"); final CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Land");
final CardList landsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getType("Land"); final CardList landsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getType("Land");
final CardList nonLandsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getNotType("Land"); final CardList nonLandsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getNotType("Land");
final int highestCMC = Math.max(6, Predicate.getTrue(Card.class).max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc)); final int highestCMC = Math.max(6, Aggregates.max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc));
final int discardCMC = discard.getCMC(); final int discardCMC = discard.getCMC();
if (discard.isLand()) { if (discard.isLand()) {
if (landsInPlay.size() >= highestCMC if (landsInPlay.size() >= highestCMC

View File

@@ -31,7 +31,6 @@ import forge.card.spellability.Ability;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.staticability.StaticAbility; import forge.card.staticability.StaticAbility;
import forge.game.player.Player; import forge.game.player.Player;
import forge.util.closures.Predicate;
/** /**
* <p> * <p>

View File

@@ -1,6 +1,10 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel;
import com.google.common.collect.Iterables;
import forge.card.CardRules; import forge.card.CardRules;
import forge.gui.deckeditor.views.ITableContainer; import forge.gui.deckeditor.views.ITableContainer;
@@ -9,6 +13,8 @@ import forge.gui.deckeditor.views.VCurrentDeck;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.util.Aggregates;
import forge.util.closures.Predicate;
/** /**
* Static methods for working with top-level editor methods, * Static methods for working with top-level editor methods,
@@ -78,6 +84,11 @@ public final class SEditorUtil {
return (int) Math.round((double) x0 / (double) y0 * 100); return (int) Math.round((double) x0 / (double) y0 * 100);
} }
public static <T extends InventoryItem> void setLabelTextSum(JLabel label, final ItemPoolView<T> deck, Predicate<CardRules> predicate) {
int sum = Aggregates.sum(Iterables.filter(deck, predicate.brigde(deck.getFnToCard())), deck.getFnToCount());
label.setText(String.valueOf(sum));
}
/** /**
* setStats. * setStats.
* *
@@ -88,44 +99,19 @@ public final class SEditorUtil {
public static <T extends InventoryItem> void setStats(final ItemPoolView<T> deck, final ITableContainer view) { public static <T extends InventoryItem> void setStats(final ItemPoolView<T> deck, final ITableContainer view) {
view.getLblTotal().setText(String.valueOf(deck.countAll())); view.getLblTotal().setText(String.valueOf(deck.countAll()));
view.getLblCreature().setText(String.valueOf(CardRules.Predicates.Presets setLabelTextSum(view.getLblCreature(), deck, CardRules.Predicates.Presets.IS_CREATURE);
.IS_CREATURE.sum(deck, deck.getFnToCard(), deck.getFnToCount()))); setLabelTextSum(view.getLblLand(), deck, CardRules.Predicates.Presets.IS_LAND);
setLabelTextSum(view.getLblEnchantment(), deck, CardRules.Predicates.Presets.IS_ENCHANTMENT);
view.getLblLand().setText(String.valueOf(CardRules.Predicates.Presets setLabelTextSum(view.getLblArtifact(), deck, CardRules.Predicates.Presets.IS_ARTIFACT);
.IS_LAND.sum(deck, deck.getFnToCard(), deck.getFnToCount()))); setLabelTextSum(view.getLblInstant(), deck, CardRules.Predicates.Presets.IS_INSTANT);
setLabelTextSum(view.getLblSorcery(), deck, CardRules.Predicates.Presets.IS_SORCERY);
view.getLblEnchantment().setText(String.valueOf(CardRules.Predicates.Presets setLabelTextSum(view.getLblPlaneswalker(), deck, CardRules.Predicates.Presets.IS_PLANESWALKER);
.IS_ENCHANTMENT.sum(deck, deck.getFnToCard(), deck.getFnToCount()))); setLabelTextSum(view.getLblColorless(), deck, CardRules.Predicates.Presets.IS_COLORLESS);
setLabelTextSum(view.getLblBlack(), deck, CardRules.Predicates.Presets.IS_BLACK);
view.getLblArtifact().setText(String.valueOf(CardRules.Predicates.Presets setLabelTextSum(view.getLblBlue(), deck, CardRules.Predicates.Presets.IS_BLUE);
.IS_ARTIFACT.sum(deck, deck.getFnToCard(), deck.getFnToCount()))); setLabelTextSum(view.getLblGreen(), deck, CardRules.Predicates.Presets.IS_GREEN);
setLabelTextSum(view.getLblRed(), deck, CardRules.Predicates.Presets.IS_RED);
view.getLblInstant().setText(String.valueOf(CardRules.Predicates.Presets setLabelTextSum(view.getLblWhite(), deck, CardRules.Predicates.Presets.IS_WHITE);
.IS_INSTANT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblSorcery().setText(String.valueOf(CardRules.Predicates.Presets
.IS_SORCERY.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblPlaneswalker().setText(String.valueOf(CardRules.Predicates.Presets
.IS_PLANESWALKER.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblColorless().setText(String.valueOf(CardRules.Predicates.Presets
.IS_COLORLESS.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblBlack().setText(String.valueOf(CardRules.Predicates.Presets
.IS_BLACK.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblBlue().setText(String.valueOf(CardRules.Predicates.Presets
.IS_BLUE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblGreen().setText(String.valueOf(CardRules.Predicates.Presets
.IS_GREEN.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblRed().setText(String.valueOf(CardRules.Predicates.Presets
.IS_RED.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
view.getLblWhite().setText(String.valueOf(CardRules.Predicates.Presets
.IS_WHITE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
} // getStats() } // getStats()
/** /**

View File

@@ -1,5 +1,7 @@
package forge.gui.deckeditor.controllers; package forge.gui.deckeditor.controllers;
import com.google.common.collect.Iterables;
import forge.Command; import forge.Command;
import forge.card.CardRules; import forge.card.CardRules;
import forge.deck.Deck; import forge.deck.Deck;
@@ -16,6 +18,7 @@ import forge.gui.toolbox.FLabel;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.util.Aggregates;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
/** /**
@@ -75,8 +78,10 @@ public enum CDeckgen implements ICDoc {
final Deck randomDeck = new Deck(); final Deck randomDeck = new Deck();
randomDeck.getMain().addAllFlat(Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND) Predicate<CardPrinted> notBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).brigde(CardPrinted.FN_GET_RULES);
.random(CardDb.instance().getAllUniqueCards(), CardPrinted.FN_GET_RULES, 15 * 5)); Iterable<CardPrinted> source = Iterables.filter(CardDb.instance().getAllUniqueCards(), notBasicLand);
randomDeck.getMain().addAllFlat(Aggregates.random(source, 15*5));
randomDeck.getMain().add("Plains"); randomDeck.getMain().add("Plains");
randomDeck.getMain().add("Island"); randomDeck.getMain().add("Island");
randomDeck.getMain().add("Swamp"); randomDeck.getMain().add("Swamp");

View File

@@ -7,6 +7,9 @@ import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import forge.Command; import forge.Command;
import forge.deck.DeckBase; import forge.deck.DeckBase;
import forge.gui.deckeditor.CDeckEditorUI; import forge.gui.deckeditor.CDeckEditorUI;
@@ -17,7 +20,6 @@ import forge.gui.toolbox.FLabel;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.ItemPredicate; import forge.item.ItemPredicate;
import forge.util.closures.Predicate;
/** /**
* Controls the "filters" panel in the deck editor UI. * Controls the "filters" panel in the deck editor UI.
@@ -160,11 +162,12 @@ public enum CFilters implements ICDoc {
public <TItem extends InventoryItem, TModel extends DeckBase> void buildFilter() { public <TItem extends InventoryItem, TModel extends DeckBase> void buildFilter() {
// The main trick here is to apply a CardPrinted predicate // The main trick here is to apply a CardPrinted predicate
// to the table. CardRules will lead to difficulties. // to the table. CardRules will lead to difficulties.
final List<Predicate<CardPrinted>> lstFilters = new ArrayList<Predicate<CardPrinted>>(); final List<Predicate<? super CardPrinted>> lstFilters = new ArrayList<Predicate<? super CardPrinted>>();
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>) final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
lstFilters.add(Predicates.instanceOf(CardPrinted.class));
lstFilters.add(SFilterUtil.buildColorFilter()); lstFilters.add(SFilterUtil.buildColorFilter());
lstFilters.add(SFilterUtil.buildTypeFilter()); lstFilters.add(SFilterUtil.buildTypeFilter());
lstFilters.add(SFilterUtil.buildSetAndFormatFilter()); lstFilters.add(SFilterUtil.buildSetAndFormatFilter());
@@ -172,11 +175,10 @@ public enum CFilters implements ICDoc {
lstFilters.add(SFilterUtil.buildIntervalFilter()); lstFilters.add(SFilterUtil.buildIntervalFilter());
// Until this is filterable, always show packs and decks in the card shop. // Until this is filterable, always show packs and decks in the card shop.
Predicate<InventoryItem> itemFilter = Predicate.instanceOf( com.google.common.base.Predicate<? super CardPrinted> itemFilter = Predicates.and(lstFilters);
Predicate.and(lstFilters), CardPrinted.class);
itemFilter = Predicate.or(itemFilter, ItemPredicate.Presets.IS_PACK); itemFilter = Predicates.or(itemFilter, ItemPredicate.Presets.IS_PACK);
itemFilter = Predicate.or(itemFilter, ItemPredicate.Presets.IS_DECK); itemFilter = Predicates.or(itemFilter, ItemPredicate.Presets.IS_DECK);
// Apply to table // Apply to table
ed.getTableCatalog().setFilter((Predicate<TItem>) itemFilter); ed.getTableCatalog().setFilter((Predicate<TItem>) itemFilter);

View File

@@ -2,10 +2,13 @@ package forge.gui.deckeditor.controllers;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.swing.JLabel;
import com.google.common.collect.Iterables;
import forge.Command; import forge.Command;
import forge.card.CardColor; import forge.card.CardColor;
import forge.card.CardRules; import forge.card.CardRules;
import forge.card.CardRules.Predicates;
import forge.deck.DeckBase; import forge.deck.DeckBase;
import forge.gui.deckeditor.CDeckEditorUI; import forge.gui.deckeditor.CDeckEditorUI;
import forge.gui.deckeditor.SEditorUtil; import forge.gui.deckeditor.SEditorUtil;
@@ -15,6 +18,7 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.util.Aggregates;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
/** /**
@@ -52,6 +56,12 @@ public enum CStatistics implements ICDoc {
analyze(); analyze();
} }
private void setLabelValue(JLabel label, ItemPoolView<CardPrinted> deck, Predicate<CardRules> predicate, int total) {
int tmp = Aggregates.sum(Iterables.filter(deck, predicate.brigde(deck.getFnToCard())), deck.getFnToCount());
label.setText( tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
}
//========== Other methods //========== Other methods
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends InventoryItem, TModel extends DeckBase> void analyze() { private <T extends InventoryItem, TModel extends DeckBase> void analyze() {
@@ -69,84 +79,22 @@ public enum CStatistics implements ICDoc {
// Hack-ish: avoid /0 cases, but still populate labels :) // Hack-ish: avoid /0 cases, but still populate labels :)
if (total == 0) { total = 1; } if (total == 0) { total = 1; }
tmp = CardRules.Predicates.Presets.IS_MULTICOLOR
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblMulti().setText(String.valueOf(tmp));
tmp = CardRules.Predicates.Presets.IS_CREATURE setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblCreature(), deck, CardRules.Predicates.Presets.IS_CREATURE, total );
.sum(deck, deck.getFnToCard(), deck.getFnToCount()); setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblLand(), deck, CardRules.Predicates.Presets.IS_LAND, total );
VStatistics.SINGLETON_INSTANCE.getLblCreature().setText( setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblEnchantment(), deck, CardRules.Predicates.Presets.IS_ENCHANTMENT, total );
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblArtifact(), deck, CardRules.Predicates.Presets.IS_ARTIFACT, total );
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblInstant(), deck, CardRules.Predicates.Presets.IS_INSTANT, total );
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblSorcery(), deck, CardRules.Predicates.Presets.IS_SORCERY, total );
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker(), deck, CardRules.Predicates.Presets.IS_PLANESWALKER, total );
tmp = CardRules.Predicates.Presets.IS_LAND setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblMulti(), deck, CardRules.Predicates.Presets.IS_MULTICOLOR, total );
.sum(deck, deck.getFnToCard(), deck.getFnToCount()); setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblColorless(), deck, CardRules.Predicates.Presets.IS_COLORLESS, total );
VStatistics.SINGLETON_INSTANCE.getLblLand().setText( setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlack(), deck, CardRules.Predicates.isMonoColor(CardColor.BLACK), total );
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlue(), deck, CardRules.Predicates.isMonoColor(CardColor.BLUE), total );
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblGreen(), deck, CardRules.Predicates.isMonoColor(CardColor.GREEN), total );
tmp = CardRules.Predicates.Presets.IS_ENCHANTMENT setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblRed(), deck, CardRules.Predicates.isMonoColor(CardColor.RED), total );
.sum(deck, deck.getFnToCard(), deck.getFnToCount()); setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblWhite(), deck, CardRules.Predicates.isMonoColor(CardColor.WHITE), total );
VStatistics.SINGLETON_INSTANCE.getLblEnchantment().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_ARTIFACT
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblArtifact().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_INSTANT
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblInstant().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_SORCERY
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblSorcery().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_PLANESWALKER
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = CardRules.Predicates.Presets.IS_COLORLESS
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblColorless().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.BLACK),
Predicates.hasCntColors((byte) 1))
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblBlack().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.BLUE),
Predicates.hasCntColors((byte) 1))
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblBlue().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.GREEN),
Predicates.hasCntColors((byte) 1))
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblGreen().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.RED),
Predicates.hasCntColors((byte) 1))
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblRed().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
tmp = Predicate.and(
Predicates.isColor(CardColor.WHITE),
Predicates.hasCntColors((byte) 1))
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
VStatistics.SINGLETON_INSTANCE.getLblWhite().setText(
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
int cmc0 = 0, cmc1 = 0, cmc2 = 0, cmc3 = 0, cmc4 = 0, cmc5 = 0, cmc6 = 0; int cmc0 = 0, cmc1 = 0, cmc2 = 0, cmc3 = 0, cmc4 = 0, cmc5 = 0, cmc6 = 0;
int tmc = 0; int tmc = 0;

View File

@@ -27,6 +27,8 @@ import javax.swing.JTable;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
import com.google.common.base.Function;
import forge.Singletons; import forge.Singletons;
import forge.card.CardColor; import forge.card.CardColor;
import forge.card.CardEdition; import forge.card.CardEdition;
@@ -39,7 +41,6 @@ import forge.gui.deckeditor.controllers.ACEditorBase;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.InventoryItemFromSet; import forge.item.InventoryItemFromSet;
import forge.util.closures.Lambda1;
/** /**
* A collection of methods pertaining to columns in card catalog and * A collection of methods pertaining to columns in card catalog and
@@ -355,7 +356,7 @@ public final class SColumnUtil {
/** Lamda sort fnQtyCompare. */ /** Lamda sort fnQtyCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_QTY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_QTY_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return from.getValue(); return from.getValue();
@@ -363,7 +364,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnQtyGet. */ /** Lamda sort fnQtyGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_QTY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_QTY_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return from.getValue(); return from.getValue();
@@ -372,7 +373,7 @@ public final class SColumnUtil {
/** Lamda sort fnNameCompare. */ /** Lamda sort fnNameCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_NAME_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_NAME_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getName(); return from.getKey().getName();
@@ -380,7 +381,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnNameGet. */ /** Lamda sort fnNameGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_NAME_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_NAME_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
final String name = from.getKey().getName(); final String name = from.getKey().getName();
@@ -390,7 +391,7 @@ public final class SColumnUtil {
/** Lamda sort fnCostCompare. */ /** Lamda sort fnCostCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_COST_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_COST_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toManaCost(from.getKey()); return SColumnUtil.toManaCost(from.getKey());
@@ -398,7 +399,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnCostGet. */ /** Lamda sort fnCostGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COST_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_COST_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toManaCost(from.getKey()); return SColumnUtil.toManaCost(from.getKey());
@@ -407,7 +408,7 @@ public final class SColumnUtil {
/** Lamda sort fnColorCompare. */ /** Lamda sort fnColorCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_COLOR_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_COLOR_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toColor(from.getKey()); return SColumnUtil.toColor(from.getKey());
@@ -415,7 +416,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnColorGet. */ /** Lamda sort fnColorGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COLOR_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_COLOR_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toColor(from.getKey()); return SColumnUtil.toColor(from.getKey());
@@ -424,7 +425,7 @@ public final class SColumnUtil {
/** Lamda sort fnTypeCompare. */ /** Lamda sort fnTypeCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TYPE_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_TYPE_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getType(); return from.getKey().getType();
@@ -432,7 +433,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnTypeGet. */ /** Lamda sort fnTypeGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TYPE_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_TYPE_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return from.getKey().getType(); return from.getKey().getType();
@@ -441,7 +442,7 @@ public final class SColumnUtil {
/** Lamda sort fnPowerCompare. */ /** Lamda sort fnPowerCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_POWER_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_POWER_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toPower(from.getKey()); return SColumnUtil.toPower(from.getKey());
@@ -449,7 +450,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnPowerGet. */ /** Lamda sort fnPowerGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_POWER_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_POWER_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toPower(from.getKey()); return SColumnUtil.toPower(from.getKey());
@@ -458,7 +459,7 @@ public final class SColumnUtil {
/** Lamda sort fnToughnessCompare. */ /** Lamda sort fnToughnessCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TOUGHNESS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_TOUGHNESS_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toToughness(from.getKey()); return SColumnUtil.toToughness(from.getKey());
@@ -466,7 +467,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnToughnessGet. */ /** Lamda sort fnToughnessGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TOUGHNESS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_TOUGHNESS_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toToughness(from.getKey()); return SColumnUtil.toToughness(from.getKey());
@@ -475,7 +476,7 @@ public final class SColumnUtil {
/** Lamda sort fnCMCCompare. */ /** Lamda sort fnCMCCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_CMC_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_CMC_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toCMC(from.getKey()); return SColumnUtil.toCMC(from.getKey());
@@ -483,7 +484,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnCMCGet. */ /** Lamda sort fnCMCGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_CMC_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_CMC_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toCMC(from.getKey()); return SColumnUtil.toCMC(from.getKey());
@@ -492,7 +493,7 @@ public final class SColumnUtil {
/** Lamda sort fnRarityCompare. */ /** Lamda sort fnRarityCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_RARITY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_RARITY_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toRarity(from.getKey()); return SColumnUtil.toRarity(from.getKey());
@@ -500,7 +501,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnRarityGet. */ /** Lamda sort fnRarityGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_RARITY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_RARITY_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toRarity(from.getKey()); return SColumnUtil.toRarity(from.getKey());
@@ -509,7 +510,7 @@ public final class SColumnUtil {
/** Lamda sort fnSetCompare. */ /** Lamda sort fnSetCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_SET_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_SET_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toSetCmp(from.getKey()); return SColumnUtil.toSetCmp(from.getKey());
@@ -517,7 +518,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnSetGet. */ /** Lamda sort fnSetGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_SET_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_SET_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toSetStr(from.getKey()); return SColumnUtil.toSetStr(from.getKey());
@@ -526,7 +527,7 @@ public final class SColumnUtil {
/** Lamda sort fnAiStatusCompare. */ /** Lamda sort fnAiStatusCompare. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_AI_STATUS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_AI_STATUS_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<InventoryItem, Integer> from) { public Comparable apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toAiCmp(from.getKey()); return SColumnUtil.toAiCmp(from.getKey());
@@ -534,7 +535,7 @@ public final class SColumnUtil {
}; };
/** Lamda sort fnAiStatusGet. */ /** Lamda sort fnAiStatusGet. */
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_AI_STATUS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() { private static final Function<Entry<InventoryItem, Integer>, Object> FN_AI_STATUS_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
@Override @Override
public Object apply(final Entry<InventoryItem, Integer> from) { public Object apply(final Entry<InventoryItem, Integer> from) {
return SColumnUtil.toAiStr(from.getKey()); return SColumnUtil.toAiStr(from.getKey());

View File

@@ -21,8 +21,10 @@ import java.util.Map.Entry;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import com.google.common.base.Function;
import forge.gui.deckeditor.tables.SColumnUtil.SortState; import forge.gui.deckeditor.tables.SColumnUtil.SortState;
import forge.util.closures.Lambda1; import forge.item.InventoryItem;
/** /**
* A column object in a TableModel in the card editor. * A column object in a TableModel in the card editor.
@@ -39,8 +41,8 @@ public class TableColumnInfo<T> extends TableColumn {
private boolean show = true; private boolean show = true;
private String enumval; private String enumval;
private Lambda1<Comparable, Entry<T, Integer>> fnSort; private Function<Entry<T, Integer>, Comparable> fnSort;
private Lambda1<Object, Entry<T, Integer>> fnDisplay; private Function<Entry<T, Integer>, Object> fnDisplay;
/** */ /** */
public TableColumnInfo() { public TableColumnInfo() {
@@ -108,7 +110,7 @@ public class TableColumnInfo<T> extends TableColumn {
* *
* @return the fnSort * @return the fnSort
*/ */
public Lambda1<Comparable, Entry<T, Integer>> getFnSort() { public Function<Entry<T, Integer>, Comparable> getFnSort() {
if (fnSort == null) { if (fnSort == null) {
throw new NullPointerException("A sort function hasn't been set for " throw new NullPointerException("A sort function hasn't been set for "
+ "Column " + TableColumnInfo.this.getIdentifier()); + "Column " + TableColumnInfo.this.getIdentifier());
@@ -121,7 +123,7 @@ public class TableColumnInfo<T> extends TableColumn {
* *
* @return the fnDisplay * @return the fnDisplay
*/ */
public Lambda1<Object, Entry<T, Integer>> getFnDisplay() { public Function<Entry<T, Integer>, Object> getFnDisplay() {
if (fnSort == null) { if (fnSort == null) {
throw new NullPointerException("A display function hasn't been set for " throw new NullPointerException("A display function hasn't been set for "
+ "Column " + TableColumnInfo.this.getIdentifier()); + "Column " + TableColumnInfo.this.getIdentifier());
@@ -135,7 +137,7 @@ public class TableColumnInfo<T> extends TableColumn {
* @param lambda0 the fnSort * @param lambda0 the fnSort
* @param lambda1 the fnDisplay * @param lambda1 the fnDisplay
*/ */
public void setSortAndDisplayFunctions(final Lambda1<Comparable, Entry<T, Integer>> lambda0, final Lambda1<Object, Entry<T, Integer>> lambda1) { public void setSortAndDisplayFunctions(final Function<Entry<T, Integer>, Comparable> lambda0, final Function<Entry<T, Integer>, Object> lambda1) {
this.fnSort = lambda0; this.fnSort = lambda0;
this.fnDisplay = lambda1; this.fnDisplay = lambda1;
} }

View File

@@ -20,8 +20,9 @@ package forge.gui.deckeditor.tables;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.google.common.base.Function;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.util.closures.Lambda1;
/** /**
* <p> * <p>
@@ -38,7 +39,7 @@ import forge.util.closures.Lambda1;
public class TableSorter<T> implements Comparator<Entry<T, Integer>> { public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
private final boolean ascending; private final boolean ascending;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private final Lambda1<Comparable, Entry<T, Integer>> field; private final Function<Entry<T, Integer>, Comparable> field;
/** /**
* <p> * <p>
@@ -51,7 +52,7 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
* a boolean. * a boolean.
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public TableSorter(final Lambda1<Comparable, Entry<T, Integer>> field, final boolean inAscending) { public TableSorter(final Function<Entry<T, Integer>, Comparable> field, final boolean inAscending) {
this.field = field; this.field = field;
this.ascending = inAscending; this.ascending = inAscending;
} }
@@ -59,7 +60,7 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
/** The Constant byNameThenSet. */ /** The Constant byNameThenSet. */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final TableSorter<CardPrinted> BY_NAME_THEN_SET = new TableSorter<CardPrinted>( public static final TableSorter<CardPrinted> BY_NAME_THEN_SET = new TableSorter<CardPrinted>(
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() { new Function<Entry<CardPrinted, Integer>, Comparable>() {
@Override @Override
public Comparable apply(final Entry<CardPrinted, Integer> from) { public Comparable apply(final Entry<CardPrinted, Integer> from) {
return from.getKey(); return from.getKey();

View File

@@ -19,13 +19,16 @@ package forge.gui.deckeditor.tables;
import java.awt.Color; import java.awt.Color;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener; import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableColumnModel;
import forge.card.CardRules; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import forge.gui.deckeditor.SEditorUtil; import forge.gui.deckeditor.SEditorUtil;
import forge.gui.deckeditor.views.ITableContainer; import forge.gui.deckeditor.views.ITableContainer;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
@@ -33,7 +36,8 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.util.closures.Predicate; import forge.util.Aggregates;
/** /**
* TableWithCards. * TableWithCards.
@@ -207,7 +211,7 @@ public final class TableView<T extends InventoryItem> {
} }
private boolean isUnfiltered() { private boolean isUnfiltered() {
return (this.filter == null) || this.filter.is1(); return this.filter == null;
} }
/** /**
@@ -270,13 +274,15 @@ public final class TableView<T extends InventoryItem> {
} }
if (useFilter && this.wantUnique) { if (useFilter && this.wantUnique) {
this.model.addCards(this.filter.uniqueByLast(this.pool, this.pool.getFnToCardName(), Predicate<Entry<T, Integer>> filterForPool = forge.util.closures.Predicate.brigde(this.filter, this.pool.getFnToPrinted());
this.pool.getFnToPrinted())); Iterable<Entry<T, Integer>> cards = Aggregates.uniqueByLast(Iterables.filter(this.pool, filterForPool), this.pool.getFnToCardName());
this.model.addCards(cards);
} else if (useFilter) { } else if (useFilter) {
this.model.addCards(this.filter.select(this.pool, this.pool.getFnToPrinted())); Predicate<Entry<T, Integer>> pred = forge.util.closures.Predicate.brigde(this.filter, this.pool.getFnToPrinted());
this.model.addCards(Iterables.filter(this.pool, pred));
} else if (this.wantUnique) { } else if (this.wantUnique) {
this.model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(this.pool, Iterable<Entry<T, Integer>> cards = Aggregates.uniqueByLast(this.pool, this.pool.getFnToCardName());
this.pool.getFnToCardName(), this.pool.getFnToCard())); this.model.addCards(cards);
} else if (!useFilter && bForceFilter) { } else if (!useFilter && bForceFilter) {
this.model.addCards(this.pool); this.model.addCards(this.pool);
} }

View File

@@ -28,6 +28,8 @@ import java.util.List;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import com.google.common.collect.Lists;
import forge.AllZone; import forge.AllZone;
import forge.Card; import forge.Card;
import forge.CardList; import forge.CardList;
@@ -280,7 +282,7 @@ public class CField implements ICDoc {
@Override @Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
final List<Card> src = this.getCardsAsIterable(); final List<Card> src = this.getCardsAsIterable();
final List<Card> choices = AllZone.getNameChanger().shouldChangeCardName() ? AllZone.getNameChanger().fnTransformCard.applyToIterable(src) : getCardsAsIterable(); final List<Card> choices = AllZone.getNameChanger().shouldChangeCardName() ? Lists.transform(src, AllZone.getNameChanger().fnTransformCard) : getCardsAsIterable();
final ArrayList<Card> choices2 = new ArrayList<Card>(); final ArrayList<Card> choices2 = new ArrayList<Card>();

View File

@@ -29,6 +29,9 @@ import java.util.NoSuchElementException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card; import forge.Card;
import forge.Singletons; import forge.Singletons;
import forge.card.CardInSet; import forge.card.CardInSet;
@@ -389,7 +392,7 @@ public final class CardDb {
} else { } else {
// OK, plain name here // OK, plain name here
final Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left); final Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left);
final List<CardPrinted> namedCards = predicate.select(this.allCardsFlat); final List<CardPrinted> namedCards = Lists.newArrayList(Iterables.filter(this.allCardsFlat, predicate));
if (namedCards.isEmpty()) { if (namedCards.isEmpty()) {
throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name)); throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name));
} }

View File

@@ -19,9 +19,12 @@ package forge.item;
import java.util.List; import java.util.List;
import com.google.common.collect.Iterables;
import forge.card.BoosterData; import forge.card.BoosterData;
import forge.card.BoosterGenerator; import forge.card.BoosterGenerator;
import forge.card.CardRules; import forge.card.CardRules;
import forge.util.Aggregates;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
/** /**
@@ -168,9 +171,10 @@ public abstract class OpenablePack implements InventoryItemFromSet {
* @return the random basic lands * @return the random basic lands
*/ */
protected List<CardPrinted> getRandomBasicLands(final String setCode, final int count) { protected List<CardPrinted> getRandomBasicLands(final String setCode, final int count) {
return Predicate.and(CardPrinted.Predicates.printedInSets(setCode), Predicate<CardPrinted> cardsRule = Predicate.and(
CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES).random( CardPrinted.Predicates.printedInSets(setCode),
CardDb.instance().getAllCards(), count); CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES);
return Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), cardsRule), count);
} }
} }

View File

@@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.google.common.collect.Iterables;
import forge.card.BoosterGenerator; import forge.card.BoosterGenerator;
@@ -28,6 +30,7 @@ import forge.card.CardRules;
import forge.card.UnOpenedProduct; import forge.card.UnOpenedProduct;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.util.Aggregates;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.closures.Lambda1; import forge.util.closures.Lambda1;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
@@ -89,7 +92,7 @@ public final class BoosterUtils {
int nRares = numRare, nMythics = 0; int nRares = numRare, nMythics = 0;
final Predicate<CardPrinted> filterMythics = Predicate.and(filter, final Predicate<CardPrinted> filterMythics = Predicate.and(filter,
CardPrinted.Predicates.Presets.IS_MYTHIC_RARE); CardPrinted.Predicates.Presets.IS_MYTHIC_RARE);
final boolean haveMythics = filterMythics.any(cardpool); final boolean haveMythics = Iterables.any(cardpool, filterMythics);
for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) { for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) {
if (MyRandom.getRandom().nextInt(10) < 1) { if (MyRandom.getRandom().nextInt(10) < 1) {
// 10% chance of upgrading a Rare into a Mythic // 10% chance of upgrading a Rare into a Mythic
@@ -139,13 +142,13 @@ public final class BoosterUtils {
if (size > 0) { if (size > 0) {
final Predicate<CardRules> color2 = allowedColors.get(iAttempt % size); final Predicate<CardRules> color2 = allowedColors.get(iAttempt % size);
if (color2 != null) { if (color2 != null) {
card = Predicate.and(filter, color2, CardPrinted.FN_GET_RULES).random(source); card = Aggregates.random(Iterables.filter(source, Predicate.and(filter, color2, CardPrinted.FN_GET_RULES)));
} }
} }
if (card == null) { if (card == null) {
// We can't decide on a color, so just pick a card. // We can't decide on a color, so just pick a card.
card = filter.random(source); card = Aggregates.random(Iterables.filter(source, filter));
} }
if ((card != null) && !result.contains(card)) { if ((card != null) && !result.contains(card)) {
@@ -194,7 +197,7 @@ public final class BoosterUtils {
// constant! // constant!
while ((cntMade < cntNeeded) && (allowedMisses > 0)) { while ((cntMade < cntNeeded) && (allowedMisses > 0)) {
final CardPrinted card = filter.random(source); final CardPrinted card = Aggregates.random(Iterables.filter(source, filter));
if ((card != null) && !result.contains(card)) { if ((card != null) && !result.contains(card)) {
result.add(card); result.add(card);

View File

@@ -27,6 +27,7 @@ import forge.quest.bazaar.QuestItemType;
import forge.quest.data.QuestAssets; import forge.quest.data.QuestAssets;
import forge.quest.data.QuestPreferences; import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref; import forge.quest.data.QuestPreferences.QPref;
import forge.util.Aggregates;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.closures.Lambda1; import forge.util.closures.Lambda1;
import forge.util.closures.Predicate; import forge.util.closures.Predicate;
@@ -35,6 +36,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.google.common.collect.Iterables;
/** /**
* This is a helper class to execute operations on QuestData. It has been * This is a helper class to execute operations on QuestData. It has been
* created to decrease complexity of questData class * created to decrease complexity of questData class
@@ -139,7 +142,7 @@ public final class QuestUtilCards {
* @return the card printed * @return the card printed
*/ */
public CardPrinted addRandomRare() { public CardPrinted addRandomRare() {
final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards()); final CardPrinted card = Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), QuestUtilCards.RARE_PREDICATE));
this.addSingleCard(card); this.addSingleCard(card);
return card; return card;
} }
@@ -152,7 +155,7 @@ public final class QuestUtilCards {
* @return the list * @return the list
*/ */
public List<CardPrinted> addRandomRare(final int n) { public List<CardPrinted> addRandomRare(final int n) {
final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n); final List<CardPrinted> newCards = Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), QuestUtilCards.RARE_PREDICATE), n);
this.addAllCards(newCards); this.addAllCards(newCards);
return newCards; return newCards;
} }
@@ -343,8 +346,8 @@ public final class QuestUtilCards {
final int rollD100 = MyRandom.getRandom().nextInt(100); final int rollD100 = MyRandom.getRandom().nextInt(100);
final Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster final Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster
: (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt); : (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt);
this.qa.getShopList().addAllFlat( Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getModel().getEditions(), filter);
filter.random(Singletons.getModel().getEditions(), 1, BoosterPack.FN_FROM_SET)); this.qa.getShopList().add(BoosterPack.FN_FROM_SET.apply(Aggregates.random(rightEditions)));
} }
} }
@@ -355,15 +358,13 @@ public final class QuestUtilCards {
* the count * the count
*/ */
public void generateTournamentsInShop(final int count) { public void generateTournamentsInShop(final int count) {
Predicate<CardEdition> hasTournament = CardEdition.Predicates.HAS_TOURNAMENT_PACK; Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getModel().getEditions(), CardEdition.Predicates.HAS_TOURNAMENT_PACK);
this.qa.getShopList().addAllFlat(hasTournament.random(Singletons.getModel().getEditions(), this.qa.getShopList().addAllFlat(Aggregates.random(Iterables.transform(rightEditions, TournamentPack.FN_FROM_SET), count));
count,
TournamentPack.FN_FROM_SET));
} }
public void generateFatPacksInShop(final int count) { public void generateFatPacksInShop(final int count) {
Predicate<CardEdition> hasPack = CardEdition.Predicates.HAS_FAT_PACK; Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getModel().getEditions(), CardEdition.Predicates.HAS_FAT_PACK);
this.qa.getShopList().addAllFlat(hasPack.random(Singletons.getModel().getEditions(), count, FatPack.FN_FROM_SET)); this.qa.getShopList().addAllFlat(Aggregates.random(Iterables.transform(rightEditions, FatPack.FN_FROM_SET), count));
} }
/** /**
@@ -379,7 +380,7 @@ public final class QuestUtilCards {
meetRequirements.add(deck); meetRequirements.add(deck);
} }
} }
this.qa.getShopList().addAllFlat(Predicate.getTrue(PreconDeck.class).random(meetRequirements, count)); this.qa.getShopList().addAllFlat(Aggregates.random(meetRequirements, count));
} }
/** /**

View File

@@ -0,0 +1,107 @@
package forge.util;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import com.google.common.base.Predicate;
import forge.util.closures.Lambda1;
/**
* TODO: Write javadoc for this type.
*
*/
public class Aggregates {
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
public final static <T> Integer max(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
if (source == null) { return null; }
int max = Integer.MIN_VALUE;
for (final T c : source) {
int value = valueAccessor.apply(c);
if ( value > max ) {
max = value;
}
}
return max;
}
public final static <T> int sum(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
int result = 0;
if (source != null) {
for (final T c : source) {
result += valueAccessor.apply(c);
}
}
return result;
}
// Random - algorithm adapted from Braid's GeneratorFunctions
/**
* Random.
*
* @param source
* the source
* @return the t
*/
public final static <T> T random(final Iterable<T> source) {
int n = 0;
T candidate = null;
for (final T item : source) {
if ((Math.random() * ++n) < 1) {
candidate = item;
}
}
return candidate;
}
// Get several random values
// should improve to make 1 pass over source and track N candidates at once
/**
* Random.
*
* @param source
* the source
* @param count
* the count
* @return the list
*/
public final static <T> List<T> random(final Iterable<T> source, final int count) {
final List<T> result = new ArrayList<T>();
for (int i = 0; i < count; ++i) {
final T toAdd = Aggregates.random(source);
if (toAdd == null) {
break;
}
result.add(toAdd);
}
return result;
}
/**
* Unique by last.
*
* @param <K>
* the key type
* @param <U>
* the generic type
* @param source
* the source
* @param fnUniqueKey
* the fn unique key
* @param accessor
* the accessor
* @return the iterable
*/
public static final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Lambda1<K, U> fnUniqueKey) { // this might be exotic
final Map<K, U> uniques = new Hashtable<K, U>();
for (final U c : source) {
uniques.put(fnUniqueKey.apply(c), c);
}
return uniques.values();
}
}

View File

@@ -17,8 +17,7 @@
*/ */
package forge.util.closures; package forge.util.closures;
import java.util.ArrayList; import com.google.common.base.Function;
import java.util.List;
/** /**
@@ -29,7 +28,7 @@ import java.util.List;
* @param <A1> * @param <A1>
* the generic type * the generic type
*/ */
public abstract class Lambda1<R, A1> implements Lambda<R> { public abstract class Lambda1<R, A1> implements Lambda<R>, Function<A1, R> {
/** /**
* Apply. * Apply.
@@ -40,14 +39,6 @@ public abstract class Lambda1<R, A1> implements Lambda<R> {
*/ */
public abstract R apply(A1 arg1); public abstract R apply(A1 arg1);
public List<R> applyToIterable(Iterable<A1> arg1) {
List<R> result = new ArrayList<R>();
for(A1 a : arg1) {
result.add(this.apply(a));
}
return result;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View File

@@ -18,19 +18,15 @@
package forge.util.closures; package forge.util.closures;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map; import com.google.common.base.Function;
/** /**
* Predicate class allows to select items or type <U>, which are or contain an * Predicate class allows to select items or type <U>, which are or contain an
* object of type <T>, matching to some criteria set by predicate. No need to * object of type <T>, matching to some criteria set by predicate. No need to
* write that simple operation by hand. * write that simple operation by hand.
* *
* PS: com.google.common.base.Predicates contains almost the same functionality, * Implements com.google.common.base.Predicates, so you may use this in Guava collection management routines.
* except for they keep filtering, transformations aside from the predicate in
* class Iterables
* *
* @param <T> * @param <T>
* - class to check condition against * - class to check condition against
@@ -100,36 +96,6 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
// list.add(transformer(U)) // list.add(transformer(U))
// selects are fun // selects are fun
/**
* Select.
*
* @param source
* the source
* @return the list
*/
public final List<T> select(final Iterable<T> source) {
final ArrayList<T> result = new ArrayList<T>();
if (source != null) {
for (final T c : source) {
if (this.apply(c)) {
result.add(c);
}
}
}
return result;
}
/**
* Select.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @return the list
*/
public final <U> List<U> select(final Iterable<U> source, final Lambda1<T, U> accessor) { public final <U> List<U> select(final Iterable<U> source, final Lambda1<T, U> accessor) {
final ArrayList<U> result = new ArrayList<U>(); final ArrayList<U> result = new ArrayList<U>();
if (source != null) { if (source != null) {
@@ -142,500 +108,8 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
return result; return result;
} }
// Check if any element meeting the criteria is present
/**
* Any.
*
* @param source
* the source
* @return true, if successful
*/
public final boolean any(final Iterable<T> source) {
if (source != null) {
for (final T c : source) {
if (this.apply(c)) {
return true;
}
}
}
return false;
}
/**
* Any.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @return true, if successful
*/
public final <U> boolean any(final Iterable<U> source, final Lambda1<T, U> accessor) {
if (source != null) {
for (final U c : source) {
if (this.apply(accessor.apply(c))) {
return true;
}
}
}
return false;
}
// select top 1
/**
* First.
*
* @param source
* the source
* @return the t
*/
public final T first(final Iterable<T> source) {
if (source != null) {
for (final T c : source) {
if (this.apply(c)) {
return c;
}
}
}
return null;
}
/**
* First.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @return the u
*/
public final <U> U first(final Iterable<U> source, final Lambda1<T, U> accessor) {
if (source != null) {
for (final U c : source) {
if (this.apply(accessor.apply(c))) {
return c;
}
}
}
return null;
}
/**
* First.
*
* @param <U>
* the generic type
* @param <V>
* the value type
* @param source
* the source
* @param cardAccessor
* the card accessor
* @param transformer
* the transformer
* @return the v
*/
public final <U, V> V first(final Iterable<U> source, final Lambda1<T, U> cardAccessor,
final Lambda1<V, U> transformer) {
if (source != null) {
for (final U c : source) {
if (this.apply(cardAccessor.apply(c))) {
return transformer.apply(c);
}
}
}
return null;
}
// splits are even more fun
/**
* Split.
*
* @param source
* the source
* @param trueList
* the true list
* @param falseList
* the false list
*/
public final void split(final Iterable<T> source, final List<T> trueList, final List<T> falseList) {
if (source == null) {
return;
}
for (final T c : source) {
if (this.apply(c)) {
trueList.add(c);
} else {
falseList.add(c);
}
}
}
/**
* Split.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @param trueList
* the true list
* @param falseList
* the false list
*/
public final <U> void split(final Iterable<U> source, final Lambda1<T, U> accessor, final List<U> trueList,
final List<U> falseList) {
if (source == null) {
return;
}
for (final U c : source) {
if (this.apply(accessor.apply(c))) {
trueList.add(c);
} else {
falseList.add(c);
}
}
}
// Unique
/**
* Unique by last.
*
* @param <K>
* the key type
* @param source
* the source
* @param fnUniqueKey
* the fn unique key
* @return the iterable
*/
public final <K> Iterable<T> uniqueByLast(final Iterable<T> source, final Lambda1<K, T> fnUniqueKey) {
final Map<K, T> uniques = new Hashtable<K, T>();
for (final T c : source) {
if (this.apply(c)) {
uniques.put(fnUniqueKey.apply(c), c);
}
}
return uniques.values();
}
/**
* Unique by last.
*
* @param <K>
* the key type
* @param <U>
* the generic type
* @param source
* the source
* @param fnUniqueKey
* the fn unique key
* @param accessor
* the accessor
* @return the iterable
*/
public final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Lambda1<K, U> fnUniqueKey,
final Lambda1<T, U> accessor) { // this might be exotic
final Map<K, U> uniques = new Hashtable<K, U>();
for (final U c : source) {
if (this.apply(accessor.apply(c))) {
uniques.put(fnUniqueKey.apply(c), c);
}
}
return uniques.values();
}
/**
* Unique by first.
*
* @param <K>
* the key type
* @param source
* the source
* @param fnUniqueKey
* the fn unique key
* @return the iterable
*/
public final <K> Iterable<T> uniqueByFirst(final Iterable<T> source, final Lambda1<K, T> fnUniqueKey) {
final Map<K, T> uniques = new Hashtable<K, T>();
for (final T c : source) {
final K key = fnUniqueKey.apply(c);
if (this.apply(c) && !uniques.containsKey(key)) {
uniques.put(fnUniqueKey.apply(c), c);
}
}
return uniques.values();
}
/**
* Unique by first.
*
* @param <K>
* the key type
* @param <U>
* the generic type
* @param source
* the source
* @param fnUniqueKey
* the fn unique key
* @param accessor
* the accessor
* @return the iterable
*/
public final <K, U> Iterable<U> uniqueByFirst(final Iterable<U> source, final Lambda1<K, U> fnUniqueKey,
final Lambda1<T, U> accessor) { // this might be exotic
final Map<K, U> uniques = new Hashtable<K, U>();
for (final U c : source) {
final K key = fnUniqueKey.apply(c);
if (this.apply(accessor.apply(c)) && !uniques.containsKey(key)) {
uniques.put(fnUniqueKey.apply(c), c);
}
}
return uniques.values();
}
// Count
/**
* Count.
*
* @param source
* the source
* @return the int
*/
public final int count(final Iterable<T> source) {
int result = 0;
if (source != null) {
for (final T c : source) {
if (this.apply(c)) {
result++;
}
}
}
return result;
}
/**
* Count.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @return the int
*/
public final <U> int count(final Iterable<U> source, final Lambda1<T, U> accessor) {
int result = 0;
if (source != null) {
for (final U c : source) {
if (this.apply(accessor.apply(c))) {
result++;
}
}
}
return result;
}
// Aggregates?
/**
* Aggregate.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @param valueAccessor
* the value accessor
* @return the int
*/
public final <U> int sum(final Iterable<U> source, final Lambda1<T, U> accessor,
final Lambda1<Integer, U> valueAccessor) {
int result = 0;
if (source != null) {
for (final U c : source) {
if (this.apply(accessor.apply(c))) {
result += valueAccessor.apply(c);
}
}
}
return result;
}
public final int sum(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
int result = 0;
if (source != null) {
for (final T c : source) {
if (this.apply(c)) {
result += valueAccessor.apply(c);
}
}
}
return result;
}
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
public final Integer max(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
if (source == null) { return null; }
int max = Integer.MIN_VALUE;
for (final T c : source) {
if (!this.apply(c)) { continue; }
int value = valueAccessor.apply(c);
if ( value > max ) {
max = value;
}
}
return max;
}
// Returns the element matching predicate conditions with the maximum value of whatever valueAccessor returns.
public final T maxItem(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
if (source == null) { return null; }
T result = null;
int max = Integer.MIN_VALUE;
for (final T c : source) {
if (!this.apply(c)) { continue; }
int value = valueAccessor.apply(c);
if ( value > max ) {
result = c;
max = value;
}
}
return result;
}
// Random - algorithm adapted from Braid's GeneratorFunctions
/**
* Random.
*
* @param source
* the source
* @return the t
*/
public final T random(final Iterable<T> source) {
int n = 0;
T candidate = null;
for (final T item : source) {
if (!this.apply(item)) {
continue;
}
if ((Math.random() * ++n) < 1) {
candidate = item;
}
}
return candidate;
}
/**
* Random.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @return the u
*/
public final <U> U random(final Iterable<U> source, final Lambda1<T, U> accessor) {
int n = 0;
U candidate = null;
for (final U item : source) {
if (!this.apply(accessor.apply(item))) {
continue;
}
if ((Math.random() * ++n) < 1) {
candidate = item;
}
}
return candidate;
}
// Get several random values
// should improve to make 1 pass over source and track N candidates at once
/**
* Random.
*
* @param source
* the source
* @param count
* the count
* @return the list
*/
public final List<T> random(final Iterable<T> source, final int count) {
final List<T> result = new ArrayList<T>();
for (int i = 0; i < count; ++i) {
final T toAdd = this.random(source);
if (toAdd == null) {
break;
}
result.add(toAdd);
}
return result;
}
/**
* Random.
*
* @param <U>
* the generic type
* @param source
* the source
* @param accessor
* the accessor
* @param count
* the count
* @return the list
*/
public final <U> List<U> random(final Iterable<U> source, final Lambda1<T, U> accessor, final int count) {
final List<U> result = new ArrayList<U>();
for (int i = 0; i < count; ++i) {
final U toAdd = this.random(source, accessor);
if (toAdd == null) {
break;
}
result.add(toAdd);
}
return result;
}
/**
* Random.
*
* @param <V>
* the value type
* @param source
* the source
* @param count
* the count
* @param transformer
* the transformer
* @return the list
*/
public final <V> List<V> random(final Iterable<T> source, final int count, final Lambda1<V, T> transformer) {
final List<V> result = new ArrayList<V>();
for (int i = 0; i < count; ++i) {
final T toAdd = this.random(source);
if (toAdd == null) {
break;
}
result.add(transformer.apply(toAdd));
}
return result;
}
// Static builder methods - they choose concrete implementation by // Static builder methods - they choose concrete implementation by
// themselves // themselves
@@ -653,27 +127,16 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
* the fn bridge * the fn bridge
* @return the predicate * @return the predicate
*/ */
public static <U, T> Predicate<U> brigde(final Predicate<T> predicate, final Lambda1<T, U> fnBridge) { public static final <U, T> Predicate<U> brigde(final com.google.common.base.Predicate<T> predicate, final Function<U, T> fnBridge) {
return new Bridge<T, U>(predicate, fnBridge); return new Bridge<T, U>(predicate, fnBridge);
} }
/** public final <U> Predicate<U> brigde(final Function<U, T> fnBridge) {
* Instance of. return new Bridge<T, U>(this, fnBridge);
*
* @param <U>
* the generic type
* @param <T>
* the generic type
* @param predicate
* the predicate
* @param clsTarget
* the cls target
* @return the predicate
*/
public static <U, T> Predicate<U> instanceOf(final Predicate<T> predicate, final Class<T> clsTarget) {
return new BridgeToInstance<T, U>(predicate, clsTarget);
} }
/** /**
* Compose. * Compose.
* *
@@ -743,8 +206,8 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
* @return the predicate * @return the predicate
*/ */
public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2, public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2,
final Lambda1<U, T> bridge) { final Lambda1<U, T> fnBridge) {
return new NodeAndBridged<T, U>(operand1, operand2, bridge); return new NodeAnd<T>(operand1, operand2.brigde(fnBridge));
} }
/** /**
@@ -808,19 +271,6 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
return new Not<T>(operand1); return new Not<T>(operand1);
} }
/**
* Not.
*
* @param <T>
* the generic type
* @param operand
* the operand
* @return the predicate
*/
public static <T> Predicate<T> not(final Iterable<Predicate<T>> operand) {
return new MultiNodeNot<T>(operand);
}
/** /**
* Gets the true. * Gets the true.
* *
@@ -889,11 +339,11 @@ final class Bridge<T, U> extends Predicate<U> {
/** /**
* *
*/ */
private final Predicate<T> filter; private final com.google.common.base.Predicate<T> filter;
/** /**
* *
*/ */
private final Lambda1<T, U> fnBridge; private final Function<U, T> fnBridge;
/** /**
* *
@@ -902,7 +352,7 @@ final class Bridge<T, U> extends Predicate<U> {
* @param operand Predicate<T> * @param operand Predicate<T>
* @param fnTfromU Lambda1<T, U> * @param fnTfromU Lambda1<T, U>
*/ */
public Bridge(final Predicate<T> operand, final Lambda1<T, U> fnTfromU) { public Bridge(final com.google.common.base.Predicate<T> operand, final Function<U, T> fnTfromU) {
this.filter = operand; this.filter = operand;
this.fnBridge = fnTfromU; this.fnBridge = fnTfromU;
} }
@@ -911,54 +361,8 @@ final class Bridge<T, U> extends Predicate<U> {
public boolean apply(final U card) { public boolean apply(final U card) {
return this.filter.apply(this.fnBridge.apply(card)); return this.filter.apply(this.fnBridge.apply(card));
} }
@Override
public boolean is1() {
return this.filter.is1();
}
} }
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
* @param <U>
*/
final class BridgeToInstance<T, U> extends Predicate<U> {
/**
*
*/
private final Predicate<T> filter;
/**
*
*/
private final Class<T> clsBridge;
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand Predicate
* @param clsT Class
*/
public BridgeToInstance(final Predicate<T> operand, final Class<T> clsT) {
this.filter = operand;
this.clsBridge = clsT;
}
@SuppressWarnings("unchecked")
@Override
public boolean apply(final U card) {
return this.clsBridge.isInstance(card) && this.filter.apply((T) card);
}
@Override
public boolean is1() {
return this.filter.is1();
}
}
// binary operators // binary operators
/** /**
@@ -1217,33 +621,6 @@ final class MultiNodeOr<T> extends MultiNode<T> {
} }
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
*/
final class MultiNodeNot<T> extends MultiNode<T> {
/**
*
* TODO: Write javadoc for Constructor.
* @param filters Iterable<Predicate<T>>
*/
public MultiNodeNot(final Iterable<Predicate<T>> filters) {
super(filters);
}
@Override
public boolean apply(final T subject) {
for (final Predicate<T> p : this.getOperands()) {
if (!p.apply(subject)) {
return true;
}
}
return false;
}
}
/** /**
* *