From c34eabdb6e0fe29d0f389735e67454fe7dcea18b Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Fri, 28 Sep 2012 06:53:56 +0000 Subject: [PATCH] Removal of forge.util.closures.Predicate in favour of guava implementation --- .gitattributes | 6 +- src/main/java/forge/AllZoneUtil.java | 4 +- src/main/java/forge/CardList.java | 10 +- src/main/java/forge/CardListUtil.java | 4 +- src/main/java/forge/CardPredicates.java | 8 +- src/main/java/forge/CardUtil.java | 3 +- src/main/java/forge/GameAction.java | 4 +- src/main/java/forge/GameActionUtil.java | 4 +- src/main/java/forge/card/BoosterData.java | 4 +- .../java/forge/card/BoosterGenerator.java | 2 +- src/main/java/forge/card/CardBlock.java | 4 +- src/main/java/forge/card/CardEdition.java | 12 +- src/main/java/forge/card/CardRules.java | 41 +- src/main/java/forge/card/DeckHints.java | 16 +- .../abilityfactory/AbilityFactoryAttach.java | 7 +- .../AbilityFactoryChangeZone.java | 8 +- .../abilityfactory/AbilityFactoryChoose.java | 5 +- .../abilityfactory/AbilityFactoryCombat.java | 4 +- .../AbilityFactoryCounters.java | 4 +- .../AbilityFactoryDealDamage.java | 4 +- .../abilityfactory/AbilityFactoryDebuff.java | 4 +- .../abilityfactory/AbilityFactoryDestroy.java | 4 +- .../abilityfactory/AbilityFactoryEffect.java | 4 +- .../AbilityFactoryGainControl.java | 4 +- .../AbilityFactoryPermanentState.java | 4 +- .../abilityfactory/AbilityFactoryPlay.java | 4 +- .../AbilityFactoryProtection.java | 4 +- .../abilityfactory/AbilityFactoryPump.java | 4 +- .../cardfactory/CardFactoryArtifacts.java | 4 +- .../card/cardfactory/CardFactoryAuras.java | 3 +- .../cardfactory/CardFactoryCreatures.java | 6 +- .../card/cardfactory/CardFactoryInstants.java | 4 +- .../card/cardfactory/CardFactoryLands.java | 4 +- .../cardfactory/CardFactorySorceries.java | 3 +- .../card/cardfactory/CardFactoryUtil.java | 3 +- .../card/spellability/TargetSelection.java | 4 +- .../generate/GenerateColoredDeckBase.java | 16 +- .../forge/deck/generate/GenerateDeckUtil.java | 8 +- src/main/java/forge/game/GameFormat.java | 18 +- .../forge/game/limited/BoosterDraftAI.java | 10 +- .../java/forge/game/limited/LimitedDeck.java | 22 +- .../java/forge/game/phase/CombatUtil.java | 3 +- src/main/java/forge/game/phase/EndOfTurn.java | 4 +- .../java/forge/game/phase/PhaseHandler.java | 11 +- src/main/java/forge/game/phase/PhaseUtil.java | 4 +- src/main/java/forge/game/phase/Untap.java | 4 +- src/main/java/forge/game/phase/Upkeep.java | 3 +- .../java/forge/game/player/ComputerUtil.java | 4 +- .../forge/game/player/ComputerUtilAttack.java | 4 +- .../forge/game/player/ComputerUtilBlock.java | 17 +- .../java/forge/game/player/PlayerUtil.java | 4 +- .../forge/gui/deckeditor/SEditorUtil.java | 6 +- .../forge/gui/deckeditor/SFilterUtil.java | 102 ++- .../gui/deckeditor/controllers/CDeckgen.java | 6 +- .../deckeditor/controllers/CStatistics.java | 6 +- .../gui/deckeditor/tables/TableView.java | 5 +- src/main/java/forge/item/CardDb.java | 3 +- src/main/java/forge/item/CardPrinted.java | 24 +- src/main/java/forge/item/ItemPredicate.java | 20 +- src/main/java/forge/item/OpenablePack.java | 7 +- src/main/java/forge/quest/BoosterUtils.java | 19 +- .../java/forge/quest/QuestController.java | 6 +- src/main/java/forge/quest/QuestUtilCards.java | 21 +- .../Lambda.java => ComparableOp.java} | 70 +- .../util/{closures => }/PredicateString.java | 6 +- .../java/forge/util/closures/Lambda0.java | 24 +- .../java/forge/util/closures/Lambda1.java | 23 +- .../java/forge/util/closures/Predicate.java | 632 ------------------ .../forge/util/closures/PredicateInteger.java | 97 --- 69 files changed, 370 insertions(+), 1056 deletions(-) rename src/main/java/forge/util/{closures/Lambda.java => ComparableOp.java} (70%) rename src/main/java/forge/util/{closures => }/PredicateString.java (93%) delete mode 100644 src/main/java/forge/util/closures/Predicate.java delete mode 100644 src/main/java/forge/util/closures/PredicateInteger.java diff --git a/.gitattributes b/.gitattributes index 246f2339056..7dac5b3bdf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12723,6 +12723,7 @@ 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/BinaryUtil.java -text +src/main/java/forge/util/ComparableOp.java -text src/main/java/forge/util/CopyFiles.java svneol=native#text/plain src/main/java/forge/util/FileFinder.java svneol=native#text/plain src/main/java/forge/util/FileSection.java -text @@ -12738,6 +12739,7 @@ src/main/java/forge/util/LineReader.java -text src/main/java/forge/util/MultiplexOutputStream.java svneol=native#text/plain src/main/java/forge/util/MyObservable.java svneol=native#text/plain src/main/java/forge/util/MyRandom.java svneol=native#text/plain +src/main/java/forge/util/PredicateString.java -text src/main/java/forge/util/StorageImmediatelySerialized.java svneol=native#text/plain src/main/java/forge/util/StorageReaderFile.java -text src/main/java/forge/util/StorageReaderFolder.java -text @@ -12745,12 +12747,8 @@ src/main/java/forge/util/StorageView.java -text src/main/java/forge/util/TextUtil.java -text src/main/java/forge/util/ThreadUtil.java svneol=native#text/plain src/main/java/forge/util/XmlUtil.java -text -src/main/java/forge/util/closures/Lambda.java svneol=native#text/plain src/main/java/forge/util/closures/Lambda0.java -text src/main/java/forge/util/closures/Lambda1.java svneol=native#text/plain -src/main/java/forge/util/closures/Predicate.java -text -src/main/java/forge/util/closures/PredicateInteger.java -text -src/main/java/forge/util/closures/PredicateString.java -text src/main/java/forge/util/closures/package-info.java svneol=native#text/plain src/main/java/forge/util/package-info.java -text src/main/java/forge/view/ButtonUtil.java svneol=native#text/plain diff --git a/src/main/java/forge/AllZoneUtil.java b/src/main/java/forge/AllZoneUtil.java index f83d409ae59..edb20f7956d 100644 --- a/src/main/java/forge/AllZoneUtil.java +++ b/src/main/java/forge/AllZoneUtil.java @@ -20,10 +20,12 @@ package forge; import java.util.ArrayList; import java.util.List; +import com.google.common.base.Predicate; + import forge.CardPredicates.Presets; import forge.game.player.Player; import forge.game.zone.ZoneType; -import forge.util.closures.Predicate; + /** * AllZoneUtil contains static functions used to get CardLists of various cards diff --git a/src/main/java/forge/CardList.java b/src/main/java/forge/CardList.java index 39ae491e15c..da0c056543a 100644 --- a/src/main/java/forge/CardList.java +++ b/src/main/java/forge/CardList.java @@ -20,12 +20,14 @@ package forge; import java.util.ArrayList; import java.util.Collections; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.card.spellability.SpellAbility; import forge.game.player.Player; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

@@ -97,7 +99,7 @@ public class CardList extends ArrayList { // cardType is like "Land" or "Goblin", returns a new CardList with cards // that do not have this type public final CardList getNotType(final String cardType) { - return this.filter(Predicate.not(CardPredicates.isType(cardType))); + return this.filter(Predicates.not(CardPredicates.isType(cardType))); } public final CardList getKeyword(final String keyword) { @@ -105,7 +107,7 @@ public class CardList extends ArrayList { } public final CardList getNotKeyword(final String keyword) { - return this.filter(Predicate.not(CardPredicates.hasKeyword(keyword))); + return this.filter(Predicates.not(CardPredicates.hasKeyword(keyword))); } public final CardList getTargetableCards(final SpellAbility source) { @@ -113,7 +115,7 @@ public class CardList extends ArrayList { } public final CardList getUnprotectedCards(final Card source) { - return this.filter(Predicate.not(CardPredicates.isProtectedFrom(source))); + return this.filter(Predicates.not(CardPredicates.isProtectedFrom(source))); } /** diff --git a/src/main/java/forge/CardListUtil.java b/src/main/java/forge/CardListUtil.java index 3b82347c517..b862a67fbd5 100644 --- a/src/main/java/forge/CardListUtil.java +++ b/src/main/java/forge/CardListUtil.java @@ -20,9 +20,11 @@ package forge; import java.util.Collections; import java.util.Comparator; +import com.google.common.base.Predicate; + import forge.card.cardfactory.CardFactoryUtil; import forge.util.Aggregates; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/CardPredicates.java b/src/main/java/forge/CardPredicates.java index 604055782d0..bce1173b8d6 100644 --- a/src/main/java/forge/CardPredicates.java +++ b/src/main/java/forge/CardPredicates.java @@ -17,14 +17,15 @@ */ package forge; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import forge.card.spellability.SpellAbility; import forge.game.phase.CombatUtil; import forge.game.player.Player; +import forge.util.PredicateString; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; -import forge.util.closures.PredicateString; + /** *

@@ -322,9 +323,6 @@ public final class CardPredicates { return c.isCreature() && (!c.hasFirstStrike() || c.hasDoubleStrike()); } }; - public static final Predicate All = Predicate.getTrue(Card.class); - - } public static class Accessors { diff --git a/src/main/java/forge/CardUtil.java b/src/main/java/forge/CardUtil.java index 830894ace71..1874ef05e2f 100644 --- a/src/main/java/forge/CardUtil.java +++ b/src/main/java/forge/CardUtil.java @@ -30,6 +30,7 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import forge.card.CardCharacteristics; @@ -44,7 +45,7 @@ import forge.item.CardPrinted; import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index 4728cfea23f..472bc5b81fb 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -25,6 +25,8 @@ import java.util.Iterator; import javax.swing.JFrame; +import com.google.common.base.Predicate; + import forge.card.abilityfactory.AbilityFactory; import forge.card.abilityfactory.AbilityFactoryAttach; import forge.card.abilityfactory.AbilityFactoryCharm; @@ -58,7 +60,7 @@ import forge.game.zone.PlayerZoneComesIntoPlay; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.ViewWinLose; -import forge.util.closures.Predicate; + /** * Methods for common actions performed during a game. diff --git a/src/main/java/forge/GameActionUtil.java b/src/main/java/forge/GameActionUtil.java index be66e8d9f78..ad0b3e8193c 100644 --- a/src/main/java/forge/GameActionUtil.java +++ b/src/main/java/forge/GameActionUtil.java @@ -22,6 +22,8 @@ import java.util.HashMap; import javax.swing.JOptionPane; +import com.google.common.base.Predicate; + import forge.CardPredicates.Presets; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; @@ -52,7 +54,7 @@ import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/BoosterData.java b/src/main/java/forge/card/BoosterData.java index 1e098e67f27..c36bae9f237 100644 --- a/src/main/java/forge/card/BoosterData.java +++ b/src/main/java/forge/card/BoosterData.java @@ -1,10 +1,12 @@ package forge.card; +import com.google.common.base.Predicate; + import forge.item.CardPrinted; import forge.util.FileSection; import forge.util.StorageReaderFile; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; + /** * The Class BoosterData. diff --git a/src/main/java/forge/card/BoosterGenerator.java b/src/main/java/forge/card/BoosterGenerator.java index f5513ba0e30..ebf0dfe5de2 100644 --- a/src/main/java/forge/card/BoosterGenerator.java +++ b/src/main/java/forge/card/BoosterGenerator.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import forge.item.CardDb; @@ -31,7 +32,6 @@ import forge.item.CardPrinted; import forge.item.ItemPoolView; import forge.util.MyRandom; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; /** *

diff --git a/src/main/java/forge/card/CardBlock.java b/src/main/java/forge/card/CardBlock.java index 9bb08e49fd0..7994246fcfa 100644 --- a/src/main/java/forge/card/CardBlock.java +++ b/src/main/java/forge/card/CardBlock.java @@ -20,10 +20,12 @@ package forge.card; import java.util.ArrayList; import java.util.List; +import com.google.common.base.Predicate; + import forge.item.CardPrinted; import forge.util.StorageReaderFile; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; + // import forge.deck.Deck; /** diff --git a/src/main/java/forge/card/CardEdition.java b/src/main/java/forge/card/CardEdition.java index 692459b8578..323f4e18f41 100644 --- a/src/main/java/forge/card/CardEdition.java +++ b/src/main/java/forge/card/CardEdition.java @@ -17,12 +17,14 @@ */ package forge.card; +import com.google.common.base.Predicate; + import forge.Singletons; import forge.game.GameFormat; import forge.util.FileSection; import forge.util.StorageReaderFile; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; + /** *

@@ -176,7 +178,7 @@ public final class CardEdition implements Comparable { // immutable /** The Constant canMakeBooster. */ public static final Predicate CAN_MAKE_BOOSTER = new CanMakeBooster(); - private static class CanMakeBooster extends Predicate { + private static class CanMakeBooster implements Predicate { @Override public boolean apply(final CardEdition subject) { return Singletons.getModel().getBoosters().contains(subject.getCode()); @@ -184,7 +186,7 @@ public final class CardEdition implements Comparable { // immutable } public static final Predicate HAS_TOURNAMENT_PACK = new CanMakeStarter(); - private static class CanMakeStarter extends Predicate { + private static class CanMakeStarter implements Predicate { @Override public boolean apply(final CardEdition subject) { return Singletons.getModel().getTournamentPacks().contains(subject.getCode()); @@ -192,7 +194,7 @@ public final class CardEdition implements Comparable { // immutable } public static final Predicate HAS_FAT_PACK = new CanMakeFatPack(); - private static class CanMakeFatPack extends Predicate { + private static class CanMakeFatPack implements Predicate { @Override public boolean apply(final CardEdition subject) { return Singletons.getModel().getFatPacks().contains(subject.getCode()); @@ -209,7 +211,7 @@ public final class CardEdition implements Comparable { // immutable return new LegalInFormat(format); } - private static class LegalInFormat extends Predicate { + private static class LegalInFormat implements Predicate { private final GameFormat format; public LegalInFormat(final GameFormat fmt) { diff --git a/src/main/java/forge/card/CardRules.java b/src/main/java/forge/card/CardRules.java index 73ce4e636d0..f0b16af702b 100644 --- a/src/main/java/forge/card/CardRules.java +++ b/src/main/java/forge/card/CardRules.java @@ -18,7 +18,6 @@ package forge.card; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -26,10 +25,11 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; -import forge.util.closures.Predicate; -import forge.util.closures.PredicateInteger.ComparableOp; -import forge.util.closures.Predicate.PredicatesOp; -import forge.util.closures.PredicateString; +import com.google.common.base.Predicate; + + +import forge.util.ComparableOp; +import forge.util.PredicateString; /** @@ -555,7 +555,7 @@ public final class CardRules { try { return Predicates.coreType(isEqual, Enum.valueOf(CardCoreType.class, what)); } catch (final Exception e) { - return Predicate.getFalse(CardRules.class); + return com.google.common.base.Predicates.alwaysFalse(); } } @@ -585,7 +585,7 @@ public final class CardRules { try { return Predicates.superType(isEqual, Enum.valueOf(CardSuperType.class, what)); } catch (final Exception e) { - return Predicate.getFalse(CardRules.class); + return com.google.common.base.Predicates.alwaysFalse(); } } @@ -699,7 +699,7 @@ public final class CardRules { } } - private static class LeafColor extends Predicate { + private static class LeafColor implements Predicate { public enum ColorOperator { CountColors, CountColorsGreaterOrEqual, HasAnyOf, HasAllOf, Equals } @@ -731,7 +731,7 @@ public final class CardRules { } } - private static class LeafNumber extends Predicate { + private static class LeafNumber implements Predicate { protected enum CardField { CMC, POWER, TOUGHNESS, } @@ -783,7 +783,7 @@ public final class CardRules { } } - private static class PredicateCoreType extends Predicate { + private static class PredicateCoreType implements Predicate { private final CardCoreType operand; private final boolean shouldBeEqual; @@ -798,7 +798,7 @@ public final class CardRules { } } - private static class PredicateSuperType extends Predicate { + private static class PredicateSuperType implements Predicate { private final CardSuperType operand; private final boolean shouldBeEqual; @@ -813,7 +813,7 @@ public final class CardRules { } } - private static class PredicateLastesSetRarity extends Predicate { + private static class PredicateLastesSetRarity implements Predicate { private final CardRarity operand; private final boolean shouldBeEqual; @@ -828,7 +828,7 @@ public final class CardRules { } } - private static class PredicateExistsInSets extends Predicate { + private static class PredicateExistsInSets implements Predicate { private final List sets; public PredicateExistsInSets(final List wantSets) { @@ -886,16 +886,14 @@ public final class CardRules { public static final Predicate IS_NON_LAND = Predicates.coreType(false, CardCoreType.Land); /** The Constant isNonCreatureSpell. */ - public static final Predicate IS_NON_CREATURE_SPELL = Predicate.compose(Presets.IS_CREATURE, - PredicatesOp.NOR, Presets.IS_LAND); + public static final Predicate IS_NON_CREATURE_SPELL = + com.google.common.base.Predicates.not(com.google.common.base.Predicates.or(Presets.IS_CREATURE,Presets.IS_LAND)); - /** - * - */ @SuppressWarnings("unchecked") - public static final Predicate IS_NONCREATURE_SPELL_FOR_GENERATOR = Predicate.or(Arrays.asList( + public static final Predicate IS_NONCREATURE_SPELL_FOR_GENERATOR = + com.google.common.base.Predicates.or( Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT, - Predicate.compose(Presets.IS_ARTIFACT, PredicatesOp.GT, Presets.IS_CREATURE)) + com.google.common.base.Predicates.and(Presets.IS_ARTIFACT, com.google.common.base.Predicates.not(Presets.IS_CREATURE)) ); /** The Constant isWhite. */ @@ -930,9 +928,6 @@ public final class CardRules { Presets.COLORS.add(Presets.IS_COLORLESS); } - /** The Constant constantTrue. */ - public static final Predicate CONSTANT_TRUE = Predicate.getTrue(CardRules.class); - // Think twice before using these, since rarity is a prop of printed // card. /** The Constant isInLatestSetCommon. */ diff --git a/src/main/java/forge/card/DeckHints.java b/src/main/java/forge/card/DeckHints.java index 28f2553245e..25b07d6144e 100644 --- a/src/main/java/forge/card/DeckHints.java +++ b/src/main/java/forge/card/DeckHints.java @@ -4,12 +4,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import forge.item.CardPrinted; -import forge.util.closures.PredicateString.StringOp; +import forge.util.PredicateString.StringOp; /** * DeckHints provides the ability for a Card to "want" another Card or type of @@ -75,7 +77,7 @@ public class DeckHints { ret = new ArrayList(); String[] types = filterParam.split("\\|"); for (String type : types) { - addMatchingItems(ret, CardRules.Predicates.subType(type).bridge(CardPrinted.FN_GET_RULES), cardList); + addMatchingItems(ret, cardList, CardRules.Predicates.subType(type), CardPrinted.FN_GET_RULES); } break; case COLOR: @@ -83,21 +85,21 @@ public class DeckHints { String[] colors = filterParam.split("\\|"); for (String color : colors) { CardColor cc = CardColor.fromNames(color); - addMatchingItems(ret, CardRules.Predicates.isColor(cc.getColor()).bridge(CardPrinted.FN_GET_RULES), cardList); + addMatchingItems(ret, cardList, CardRules.Predicates.isColor(cc.getColor()), CardPrinted.FN_GET_RULES); } break; case KEYWORD: ret = new ArrayList(); String[] keywords = filterParam.split("\\|"); for (String keyword : keywords) { - addMatchingItems(ret, CardRules.Predicates.hasKeyword(keyword).bridge(CardPrinted.FN_GET_RULES), cardList); + addMatchingItems(ret, cardList, CardRules.Predicates.hasKeyword(keyword), CardPrinted.FN_GET_RULES); } break; case NAME: ret = new ArrayList(); String[] names = filterParam.split("\\|"); for (String name : names) { - addMatchingItems(ret, CardRules.Predicates.name(StringOp.EQUALS, name).bridge(CardPrinted.FN_GET_RULES), cardList); + addMatchingItems(ret, cardList, CardRules.Predicates.name(StringOp.EQUALS, name), CardPrinted.FN_GET_RULES); } break; default: @@ -107,8 +109,8 @@ public class DeckHints { return ret; } - private static void addMatchingItems(Collection dest, Predicate predicate, Iterable source) { - for(T item : Iterables.filter(source, predicate)) + private static void addMatchingItems(Collection dest, Iterable source, Predicate predicate, Function fn) { + for(T item : Iterables.filter(source, Predicates.compose(predicate, fn))) dest.add(item); } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java index 99dde129f8e..fe8a80a03dc 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java @@ -23,6 +23,9 @@ import java.util.Iterator; import java.util.Map; import java.util.Random; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -50,7 +53,7 @@ import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** * The Class AbilityFactory_Attach. @@ -797,7 +800,7 @@ public class AbilityFactoryAttach { if (attachSource.isAura()) { // TODO For Auras like Rancor, that aren't as likely to lead to // card disadvantage, this check should be skipped - prefList = prefList.filter(Predicate.not(Presets.ENCHANTED)); + prefList = prefList.filter(Predicates.not(Presets.ENCHANTED)); } if (!grantingAbilities) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java index 0e52feee6b4..9736120396d 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.List; import java.util.Random; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.AllZone; @@ -58,7 +60,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

@@ -1208,7 +1210,7 @@ public final class AbilityFactoryChangeZone { c = CardFactoryUtil.getBestAI(fetchList); } else { // Don't fetch another tutor with the same name - CardList sameNamed = fetchList.filter(Predicate.not(CardPredicates.nameEquals(card.getName()))); + CardList sameNamed = fetchList.filter(Predicates.not(CardPredicates.nameEquals(card.getName()))); if (origin.contains(ZoneType.Library) && !sameNamed.isEmpty()) { fetchList = sameNamed; } @@ -1650,7 +1652,7 @@ public final class AbilityFactoryChangeZone { CardList list = AllZoneUtil.getCardsIn(origin); list = list.getValidCards(tgt.getValidTgts(), AllZone.getComputerPlayer(), source); if (source.isInZone(ZoneType.Hand)) { - list = list.filter(Predicate.not(CardPredicates.nameEquals(source.getName()))); // Don't get the same card back. + list = list.filter(Predicates.not(CardPredicates.nameEquals(source.getName()))); // Don't get the same card back. } if (list.size() < tgt.getMinTargets(sa.getSourceCard(), sa)) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java index f5369581252..ab7e751ce3e 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java @@ -26,6 +26,7 @@ import java.util.Random; import javax.swing.JOptionPane; +import com.google.common.base.Predicates; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -51,7 +52,7 @@ import forge.gui.ListChooser; import forge.item.CardDb; import forge.item.CardPrinted; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

@@ -1643,7 +1644,7 @@ public final class AbilityFactoryChoose { } } else { CardList list = AllZoneUtil.getCardsInGame().getController(AllZone.getHumanPlayer()); - list = list.filter(Predicate.not(Presets.LANDS)); + list = list.filter(Predicates.not(Presets.LANDS)); if (!list.isEmpty()) { chosen = list.get(0).getName(); } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryCombat.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryCombat.java index 3bedebe35f2..b35ee97d5c7 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryCombat.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryCombat.java @@ -20,6 +20,8 @@ package forge.card.abilityfactory; import java.util.ArrayList; import java.util.HashMap; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.Card; import forge.CardList; @@ -36,7 +38,7 @@ import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java index 9a63ecc734f..3f15dda9444 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -48,7 +50,7 @@ import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; import forge.util.MyRandom; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java index dafb14bf016..6797fad31d3 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -42,7 +44,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java index ddbd678b6c7..60b6a24324d 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java @@ -23,6 +23,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -43,7 +45,7 @@ import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java index 338e11327ee..6071946b661 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -41,7 +43,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java index 335e5d516d1..816d5edb258 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -46,7 +48,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java index 37b2c0d1f19..95dea1873af 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java @@ -22,6 +22,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -42,7 +44,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + //AB:GainControl|ValidTgts$Creature|TgtPrompt$Select target legendary creature|LoseControl$Untap,LoseControl|SpellDescription$Gain control of target xxxxxxx diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java index 16af98867b1..93a9229a3ed 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -44,7 +46,7 @@ import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java index 722a9e096fd..0ebf6e972aa 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -45,7 +47,7 @@ import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

* AbilityFactory_Copy class. diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java index df1ad83cec7..29b4e664cc2 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java @@ -24,6 +24,8 @@ import java.util.Iterator; import javax.swing.JOptionPane; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -46,7 +48,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java index 1e7ad47c226..359a3a8cb4a 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java @@ -22,6 +22,8 @@ import java.util.HashMap; import java.util.List; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -51,7 +53,7 @@ import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java b/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java index 781692124e1..f28f814a3a5 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java @@ -2,6 +2,8 @@ package forge.card.cardfactory; import javax.swing.JOptionPane; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -22,7 +24,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/card/cardfactory/CardFactoryAuras.java b/src/main/java/forge/card/cardfactory/CardFactoryAuras.java index cc1787ad472..21b4fc59a7e 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryAuras.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryAuras.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; import com.esotericsoftware.minlog.Log; +import com.google.common.base.Predicate; import forge.AllZone; import forge.AllZoneUtil; @@ -41,7 +42,7 @@ import forge.control.input.Input; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java index b5277c46585..0cf248db428 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java @@ -23,6 +23,8 @@ import java.util.List; import javax.swing.JOptionPane; import com.esotericsoftware.minlog.Log; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.AllZone; @@ -55,7 +57,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** @@ -75,7 +77,7 @@ public class CardFactoryCreatures { @Override public boolean canPlayAI() { final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); - return Iterables.any(list, Predicate.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem"))); + return Iterables.any(list, Predicates.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem"))); } }; // Do not remove SpellAbilities created by AbilityFactory or diff --git a/src/main/java/forge/card/cardfactory/CardFactoryInstants.java b/src/main/java/forge/card/cardfactory/CardFactoryInstants.java index 1d7b1810c07..3ae115f3f5b 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryInstants.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryInstants.java @@ -17,6 +17,8 @@ */ package forge.card.cardfactory; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -37,7 +39,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/card/cardfactory/CardFactoryLands.java b/src/main/java/forge/card/cardfactory/CardFactoryLands.java index 7c711e8d802..95f373d1419 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryLands.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryLands.java @@ -19,6 +19,8 @@ package forge.card.cardfactory; import javax.swing.JOptionPane; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -37,7 +39,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java index 386606bb740..60d6d5f4476 100644 --- a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java +++ b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java @@ -25,6 +25,7 @@ import java.util.Vector; import javax.swing.JOptionPane; import com.esotericsoftware.minlog.Log; +import com.google.common.base.Predicate; import forge.AllZone; import forge.AllZoneUtil; @@ -51,7 +52,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index 72520fdf7ea..4a03deae3cd 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -26,6 +26,7 @@ import java.util.Random; import java.util.TreeMap; import com.esotericsoftware.minlog.Log; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import forge.AllZone; @@ -75,7 +76,7 @@ import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; import forge.util.Aggregates; import forge.util.MyRandom; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/card/spellability/TargetSelection.java b/src/main/java/forge/card/spellability/TargetSelection.java index 97d328b5559..c94174d4335 100644 --- a/src/main/java/forge/card/spellability/TargetSelection.java +++ b/src/main/java/forge/card/spellability/TargetSelection.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -32,7 +34,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java b/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java index 6774c5285f7..d83f5cf13ce 100644 --- a/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java +++ b/src/main/java/forge/deck/generate/GenerateColoredDeckBase.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Random; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.Constant; @@ -38,7 +40,6 @@ import forge.item.ItemPool; import forge.properties.ForgePreferences.FPref; import forge.util.Aggregates; import forge.util.MyRandom; -import forge.util.closures.Predicate; /** *

@@ -85,12 +86,13 @@ public abstract class GenerateColoredDeckBase { final Iterable cards = selectCardsOfMatchingColorForPlayer(pt); // build subsets based on type - final Iterable creatures = Iterables.filter(cards, CardRules.Predicates.Presets.IS_CREATURE.bridge(CardPrinted.FN_GET_RULES)); + final Iterable creatures = Iterables.filter(cards, Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES)); final int creatCnt = (int) (getCreatPercentage() * size); tmpDeck.append("Creature Count:").append(creatCnt).append("\n"); addCmcAdjusted(creatures, creatCnt, cmcLevels, cmcAmounts); - final Iterable spells = Iterables.filter(cards, CardRules.Predicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR.bridge(CardPrinted.FN_GET_RULES)); + Predicate preSpells = Predicates.compose(CardRules.Predicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, CardPrinted.FN_GET_RULES); + final Iterable spells = Iterables.filter(cards, preSpells); final int spellCnt = (int) (getSpellPercentage() * size); tmpDeck.append("Spell Count:").append(spellCnt).append("\n"); addCmcAdjusted(spells, spellCnt, cmcLevels, cmcAmounts); @@ -177,7 +179,7 @@ public abstract class GenerateColoredDeckBase { addSome(diff, tDeck.toFlatList()); } else if (actualSize > targetSize) { - Predicate exceptBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).bridge(CardPrinted.FN_GET_RULES); + Predicate exceptBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES)); for (int i = 0; i < 3 && actualSize > targetSize; i++) { Iterable matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand); @@ -196,7 +198,7 @@ public abstract class GenerateColoredDeckBase { final List curved = new ArrayList(); for (int i = 0; i < cmcAmounts.length; i++) { - Iterable matchingCards = Iterables.filter(source, cmcLevels.get(i).bridge(CardPrinted.FN_GET_RULES)); + Iterable matchingCards = Iterables.filter(source, Predicates.compose(cmcLevels.get(i), CardPrinted.FN_GET_RULES)); curved.addAll( Aggregates.random(matchingCards, cmcAmounts[i])); } @@ -215,9 +217,9 @@ public abstract class GenerateColoredDeckBase { Predicate hasColor = new GenerateDeckUtil.ContainsAllColorsFrom(colors); if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) { - hasColor = Predicate.or(hasColor, GenerateDeckUtil.COLORLESS_CARDS); + hasColor = Predicates.or(hasColor, GenerateDeckUtil.COLORLESS_CARDS); } - return Iterables.filter(CardDb.instance().getAllCards(), Predicate.and(canPlay, hasColor).bridge(CardPrinted.FN_GET_RULES)); + return Iterables.filter(CardDb.instance().getAllCards(), Predicates.compose(Predicates.and(canPlay, hasColor), CardPrinted.FN_GET_RULES)); } protected static CCnt[] countLands(ItemPool outList) { diff --git a/src/main/java/forge/deck/generate/GenerateDeckUtil.java b/src/main/java/forge/deck/generate/GenerateDeckUtil.java index 9010fc933d6..2ae3f6e1476 100644 --- a/src/main/java/forge/deck/generate/GenerateDeckUtil.java +++ b/src/main/java/forge/deck/generate/GenerateDeckUtil.java @@ -23,10 +23,12 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import com.google.common.base.Predicate; + import forge.card.CardColor; import forge.card.CardManaCost; import forge.card.CardRules; -import forge.util.closures.Predicate; + /** *

@@ -60,7 +62,7 @@ public class GenerateDeckUtil { } }; - public static class ContainsAllColorsFrom extends Predicate { + public static class ContainsAllColorsFrom implements Predicate { private final CardColor allowedColor; public ContainsAllColorsFrom(CardColor color) { allowedColor = color; @@ -72,7 +74,7 @@ public class GenerateDeckUtil { } } - public static class FilterCMC extends Predicate { + public static class FilterCMC implements Predicate { private final int min; private final int max; diff --git a/src/main/java/forge/game/GameFormat.java b/src/main/java/forge/game/GameFormat.java index 67c6e27ebb2..df0dcb075f6 100644 --- a/src/main/java/forge/game/GameFormat.java +++ b/src/main/java/forge/game/GameFormat.java @@ -20,10 +20,13 @@ package forge.game; import java.util.Collections; import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + import forge.card.CardRules; import forge.item.CardPrinted; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; + /** * TODO: Write javadoc for this type. @@ -59,17 +62,16 @@ public final class GameFormat { private Predicate buildFilterPritned() { final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames); - final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.IS_TRUE - : CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true); - return Predicate.and(banNames, allowSets); + if (this.allowedSetCodes == null || this.allowedSetCodes.isEmpty() ) + return banNames; + return Predicates.and(banNames, CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true)); } private Predicate buildFilterRules() { final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames); - final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.IS_TRUE - : Predicate.bridge(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), - CardPrinted.FN_GET_RULES); - return Predicate.and(banNames, allowSets); + if ( this.allowedSetCodes == null || this.allowedSetCodes.isEmpty() ) + return banNames; + return Predicates.and(banNames, Predicates.compose(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.FN_GET_RULES)); } /** diff --git a/src/main/java/forge/game/limited/BoosterDraftAI.java b/src/main/java/forge/game/limited/BoosterDraftAI.java index 3fefcfe999e..ae48e2991b3 100644 --- a/src/main/java/forge/game/limited/BoosterDraftAI.java +++ b/src/main/java/forge/game/limited/BoosterDraftAI.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.Random; import java.util.TreeMap; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -32,7 +34,6 @@ import forge.card.CardRules; import forge.deck.Deck; import forge.deck.generate.GenerateDeckUtil; import forge.item.CardPrinted; -import forge.util.closures.Predicate; /** *

@@ -78,7 +79,8 @@ public class BoosterDraftAI { CardPrinted pickedCard = null; - Iterable aiPlayablesView = Iterables.filter(chooseFrom, CardRules.Predicates.IS_KEPT_IN_AI_DECKS.bridge(CardPrinted.FN_GET_RULES)); + Predicate pred = Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES); + Iterable aiPlayablesView = Iterables.filter(chooseFrom, pred ); List aiPlayables = Lists.newArrayList(aiPlayablesView); @@ -197,10 +199,10 @@ public class BoosterDraftAI { // Has already picked both colors. DeckColors dckColors = this.playerColors.get(player); CardColor colors = CardColor.fromNames(dckColors.getColor1(), dckColors.getColor2()); - Predicate hasColor = Predicate.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors), + Predicate hasColor = Predicates.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors), GenerateDeckUtil.COLORLESS_CARDS); - Iterable colorList = Iterables.filter(aiPlayables, hasColor.bridge(CardPrinted.FN_GET_RULES)); + Iterable colorList = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES)); // Sort playable, on-color cards by rank TreeMap rankedPlayableCards = rankCards(colorList); diff --git a/src/main/java/forge/game/limited/LimitedDeck.java b/src/main/java/forge/game/limited/LimitedDeck.java index 46bc6e31746..6afaa6a93c3 100644 --- a/src/main/java/forge/game/limited/LimitedDeck.java +++ b/src/main/java/forge/game/limited/LimitedDeck.java @@ -12,6 +12,8 @@ import java.util.Set; import org.apache.commons.lang3.tuple.Pair; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -26,7 +28,7 @@ import forge.deck.generate.GenerateDeckUtil; import forge.item.CardDb; import forge.item.CardPrinted; import forge.util.MyRandom; -import forge.util.closures.Predicate; + /** * Limited format deck. @@ -66,7 +68,7 @@ public class LimitedDeck { this.colors = pClrs.getCardColors(); // removeUnplayables(); - Iterable playables = Iterables.filter(availableList, CardRules.Predicates.IS_KEPT_IN_AI_DECKS.bridge(CardPrinted.FN_GET_RULES)); + Iterable playables = Iterables.filter(availableList, Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES)); this.aiPlayables = Lists.newArrayList(playables); this.availableList.removeAll(getAiPlayables()); @@ -95,16 +97,16 @@ public class LimitedDeck { public Deck buildDeck() { // -1. Prepare - hasColor = Predicate.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors), GenerateDeckUtil.COLORLESS_CARDS); - colorList = Iterables.filter(aiPlayables, hasColor.bridge(CardPrinted.FN_GET_RULES)); - onColorCreatures = Iterables.filter(colorList, CardRules.Predicates.Presets.IS_CREATURE.bridge(CardPrinted.FN_GET_RULES)); - onColorNonCreatures = Iterables.filter(colorList, CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.bridge(CardPrinted.FN_GET_RULES)); + hasColor = Predicates.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors), GenerateDeckUtil.COLORLESS_CARDS); + colorList = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES)); + onColorCreatures = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES)); + onColorNonCreatures = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL, CardPrinted.FN_GET_RULES)); // Guava iterables do not copy the collection contents, instead they act as filters and // iterate over _source_ collection each time. So even if aiPlayable has changed, // there is no need to create a new iterable. // 0. Add any planeswalkers - Iterable onColorWalkers = Iterables.filter(colorList, CardRules.Predicates.Presets.IS_PLANESWALKER.bridge(CardPrinted.FN_GET_RULES)); + Iterable onColorWalkers = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_PLANESWALKER, CardPrinted.FN_GET_RULES)); List walkers = Lists.newArrayList(onColorWalkers); deckList.addAll(walkers); aiPlayables.removeAll(walkers); @@ -400,7 +402,7 @@ public class LimitedDeck { * @param nCards */ private void addRandomCards(int nCards) { - Iterable others = Iterables.filter(aiPlayables, CardRules.Predicates.Presets.IS_NON_LAND.bridge(CardPrinted.FN_GET_RULES)); + Iterable others = Iterables.filter(aiPlayables, Predicates.compose(CardRules.Predicates.Presets.IS_NON_LAND, CardPrinted.FN_GET_RULES)); List> ranked = rankCards(others); for (Pair bean : ranked) { if (nCards > 0) { @@ -456,7 +458,7 @@ public class LimitedDeck { if (cardToAdd.getCard().getDeckHints() != null && cardToAdd.getCard().getDeckHints().getType() != DeckHints.Type.NONE) { DeckHints hints = cardToAdd.getCard().getDeckHints(); - Iterable onColor = Iterables.filter(aiPlayables, hasColor.bridge(CardPrinted.FN_GET_RULES)); + Iterable onColor = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES)); List comboCards = hints.filter(onColor); if (Constant.Runtime.DEV_MODE[0]) { System.out.println("Found " + comboCards.size() + " cards for " + cardToAdd.getName()); @@ -575,7 +577,7 @@ public class LimitedDeck { for (int i = 1; i < 7; i++) { creatureCosts.put(i, 0); } - Predicate filter = CardRules.Predicates.Presets.IS_CREATURE.bridge(CardPrinted.FN_GET_RULES); + Predicate filter = Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES); for (CardPrinted creature : Iterables.filter(deckList, filter)) { int cmc = creature.getCard().getManaCost().getCMC(); if (cmc < 1) { diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index b9c553ac1f8..f578afb69f2 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import com.esotericsoftware.minlog.Log; +import com.google.common.base.Predicate; import forge.AllZone; import forge.AllZoneUtil; @@ -62,7 +63,7 @@ import forge.gui.GuiUtils; import forge.gui.framework.EDocID; import forge.gui.framework.SDisplayUtil; import forge.gui.match.views.VCombat; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/game/phase/EndOfTurn.java b/src/main/java/forge/game/phase/EndOfTurn.java index 50a5f497a1b..25af5cf2e1a 100644 --- a/src/main/java/forge/game/phase/EndOfTurn.java +++ b/src/main/java/forge/game/phase/EndOfTurn.java @@ -17,6 +17,8 @@ */ package forge.game.phase; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -28,7 +30,7 @@ import forge.card.spellability.SpellAbility; import forge.game.GameLossReason; import forge.game.player.Player; import forge.game.zone.ZoneType; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/game/phase/PhaseHandler.java b/src/main/java/forge/game/phase/PhaseHandler.java index ea6cde61aed..f4575ec8527 100644 --- a/src/main/java/forge/game/phase/PhaseHandler.java +++ b/src/main/java/forge/game/phase/PhaseHandler.java @@ -22,11 +22,11 @@ import java.util.Observer; import java.util.Stack; import com.esotericsoftware.minlog.Log; - import forge.AllZone; import forge.AllZoneUtil; import forge.Card; import forge.CardList; +import forge.CardPredicates; import forge.GameActionUtil; import forge.Singletons; import forge.card.spellability.SpellAbility; @@ -35,7 +35,7 @@ import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.properties.ForgePreferences.FPref; import forge.util.MyObservable; -import forge.util.closures.Predicate; + /** *

@@ -660,12 +660,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { private boolean skipTurnTimeVault(Player turn) { // time vault: CardList vaults = turn.getCardsIn(ZoneType.Battlefield, "Time Vault"); - vaults = vaults.filter(new Predicate() { - @Override - public boolean apply(final Card c) { - return c.isTapped(); - } - }); + vaults = vaults.filter(CardPredicates.Presets.TAPPED); if (vaults.size() > 0) { final Card crd = vaults.get(0); diff --git a/src/main/java/forge/game/phase/PhaseUtil.java b/src/main/java/forge/game/phase/PhaseUtil.java index 666da04eaa0..2345a828f9f 100644 --- a/src/main/java/forge/game/phase/PhaseUtil.java +++ b/src/main/java/forge/game/phase/PhaseUtil.java @@ -19,6 +19,8 @@ package forge.game.phase; import java.util.HashMap; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -31,7 +33,7 @@ import forge.game.zone.ZoneType; import forge.gui.match.CMatchUI; import forge.gui.match.controllers.CMessage; import forge.gui.match.nonsingleton.VField.PhaseLabel; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/game/phase/Untap.java b/src/main/java/forge/game/phase/Untap.java index 7299239c115..e8601e1827c 100644 --- a/src/main/java/forge/game/phase/Untap.java +++ b/src/main/java/forge/game/phase/Untap.java @@ -19,6 +19,8 @@ package forge.game.phase; import java.util.ArrayList; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -34,7 +36,7 @@ import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/game/phase/Upkeep.java b/src/main/java/forge/game/phase/Upkeep.java index f934553fdf3..acaa9e46b95 100644 --- a/src/main/java/forge/game/phase/Upkeep.java +++ b/src/main/java/forge/game/phase/Upkeep.java @@ -19,6 +19,7 @@ package forge.game.phase; import java.util.ArrayList; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import forge.AllZone; @@ -47,7 +48,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/game/player/ComputerUtil.java b/src/main/java/forge/game/player/ComputerUtil.java index 287bd03cc6e..1982de68c3c 100644 --- a/src/main/java/forge/game/player/ComputerUtil.java +++ b/src/main/java/forge/game/player/ComputerUtil.java @@ -22,6 +22,8 @@ import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -54,7 +56,7 @@ import forge.game.phase.PhaseType; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; import forge.util.Aggregates; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/game/player/ComputerUtilAttack.java b/src/main/java/forge/game/player/ComputerUtilAttack.java index 827ca140334..9f0d96c1aa8 100644 --- a/src/main/java/forge/game/player/ComputerUtilAttack.java +++ b/src/main/java/forge/game/player/ComputerUtilAttack.java @@ -20,6 +20,8 @@ package forge.game.player; import java.util.List; import java.util.Random; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.AllZoneUtil; import forge.Card; @@ -35,7 +37,7 @@ import forge.game.phase.Combat; import forge.game.phase.CombatUtil; import forge.game.zone.ZoneType; import forge.util.MyRandom; -import forge.util.closures.Predicate; + //doesHumanAttackAndWin() uses the global variable AllZone.getComputerPlayer() /** diff --git a/src/main/java/forge/game/player/ComputerUtilBlock.java b/src/main/java/forge/game/player/ComputerUtilBlock.java index 6fefdd092c1..f193a19d611 100644 --- a/src/main/java/forge/game/player/ComputerUtilBlock.java +++ b/src/main/java/forge/game/player/ComputerUtilBlock.java @@ -19,6 +19,9 @@ package forge.game.player; import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + import forge.AllZone; import forge.Card; import forge.CardList; @@ -29,7 +32,7 @@ import forge.GameEntity; import forge.card.cardfactory.CardFactoryUtil; import forge.game.phase.Combat; import forge.game.phase.CombatUtil; -import forge.util.closures.Predicate; + /** *

@@ -399,8 +402,8 @@ public class ComputerUtilBlock { CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft()); currentAttackers = currentAttackers - .filter(Predicate.not(CardPredicates.containsKeyword("Rampage"))) - .filter(Predicate.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature."))); + .filter(Predicates.not(CardPredicates.containsKeyword("Rampage"))) + .filter(Predicates.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature."))); CardList blockers; // Try to block an attacker without first strike with a gang of first strikers @@ -598,8 +601,8 @@ public class ComputerUtilBlock { CardList tramplingAttackers = ComputerUtilBlock.getAttackers().getKeyword("Trample"); tramplingAttackers = tramplingAttackers - .filter(Predicate.not(CardPredicates.containsKeyword("Rampage"))) - .filter(Predicate.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature."))); + .filter(Predicates.not(CardPredicates.containsKeyword("Rampage"))) + .filter(Predicates.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature."))); // TODO - should check here for a "rampage-like" trigger that replaced // the keyword: @@ -647,8 +650,8 @@ public class ComputerUtilBlock { CardList blockers; CardList targetAttackers = ComputerUtilBlock.getBlockedButUnkilled() - .filter(Predicate.not(CardPredicates.containsKeyword("Rampage"))) - .filter(Predicate.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature."))); + .filter(Predicates.not(CardPredicates.containsKeyword("Rampage"))) + .filter(Predicates.not(CardPredicates.containsKeyword("CARDNAME can't be blocked by more than one creature."))); // TODO - should check here for a "rampage-like" trigger that replaced // the keyword: diff --git a/src/main/java/forge/game/player/PlayerUtil.java b/src/main/java/forge/game/player/PlayerUtil.java index 60758c8dabf..f3fc996eae3 100644 --- a/src/main/java/forge/game/player/PlayerUtil.java +++ b/src/main/java/forge/game/player/PlayerUtil.java @@ -17,6 +17,8 @@ */ package forge.game.player; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.Card; import forge.CardList; @@ -26,7 +28,7 @@ import forge.control.input.Input; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; import forge.gui.match.CMatchUI; -import forge.util.closures.Predicate; + import forge.view.ButtonUtil; /** diff --git a/src/main/java/forge/gui/deckeditor/SEditorUtil.java b/src/main/java/forge/gui/deckeditor/SEditorUtil.java index e977db2c93b..c442353ebb4 100644 --- a/src/main/java/forge/gui/deckeditor/SEditorUtil.java +++ b/src/main/java/forge/gui/deckeditor/SEditorUtil.java @@ -3,6 +3,8 @@ package forge.gui.deckeditor; import javax.swing.ImageIcon; import javax.swing.JLabel; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; @@ -14,7 +16,7 @@ import forge.gui.toolbox.FSkin; import forge.item.InventoryItem; import forge.item.ItemPoolView; import forge.util.Aggregates; -import forge.util.closures.Predicate; + /** * Static methods for working with top-level editor methods, @@ -85,7 +87,7 @@ public final class SEditorUtil { } public static void setLabelTextSum(JLabel label, final ItemPoolView deck, Predicate predicate) { - int sum = Aggregates.sum(Iterables.filter(deck, predicate.bridge(deck.getFnToCard())), deck.getFnToCount()); + int sum = Aggregates.sum(Iterables.filter(deck, Predicates.compose(predicate, deck.getFnToCard())), deck.getFnToCount()); label.setText(String.valueOf(sum)); } diff --git a/src/main/java/forge/gui/deckeditor/SFilterUtil.java b/src/main/java/forge/gui/deckeditor/SFilterUtil.java index 5829a1d4457..8c03a56345c 100644 --- a/src/main/java/forge/gui/deckeditor/SFilterUtil.java +++ b/src/main/java/forge/gui/deckeditor/SFilterUtil.java @@ -16,6 +16,9 @@ import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + import forge.card.CardEdition; import forge.card.CardRules; import forge.game.GameFormat; @@ -23,9 +26,8 @@ import forge.gui.WrapLayout; import forge.gui.deckeditor.controllers.CFilters; import forge.gui.deckeditor.views.VFilters; import forge.item.CardPrinted; -import forge.util.closures.Predicate; -import forge.util.closures.PredicateInteger.ComparableOp; -import forge.util.closures.PredicateString.StringOp; +import forge.util.ComparableOp; +import forge.util.PredicateString.StringOp; /** * Static factory; holds blocks of form elements and predicates @@ -178,7 +180,7 @@ public class SFilterUtil { * @return Predicate */ public static Predicate buildColorFilter() { - if (MAP_COLOR_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); } + if (MAP_COLOR_CHECKBOXES.isEmpty()) { return Predicates.alwaysTrue(); } final List> ors = new ArrayList>(); JCheckBox chbTemp; @@ -207,15 +209,13 @@ public class SFilterUtil { chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.MULTICOLOR)).getCheckBox(); final Predicate preMulti; if (chbTemp.isSelected()) { - preMulti = Predicate.getTrue(CardPrinted.class); + preMulti = Predicates.alwaysTrue(); } else { - preMulti = Predicate.not(Predicate.bridge( - CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES)); + preMulti = Predicates.compose(CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES); } - final Predicate preColors = - Predicate.bridge(Predicate.or(ors), CardPrinted.FN_GET_RULES); + final Predicate preColors = Predicates.compose(Predicates.or(ors), CardPrinted.FN_GET_RULES); // Corner case: if multi is checked, and the rest are empty, AND won't work. // This still doesn't work perfectly :/ @@ -229,11 +229,10 @@ public class SFilterUtil { } if (allEmptyExceptMulti) { - return Predicate.bridge( - CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES); + return Predicates.compose(CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES); } else { - return Predicate.and(preColors, preMulti); + return Predicates.and(preColors, preMulti); } } @@ -245,7 +244,7 @@ public class SFilterUtil { public static Predicate buildSetAndFormatFilter() { // Set/Format filter if (VFilters.SINGLETON_INSTANCE.getCbxSets().getSelectedIndex() == 0) { - return Predicate.getTrue(CardPrinted.class); + return Predicates.alwaysTrue(); } final Object selected = VFilters.SINGLETON_INSTANCE.getCbxSets().getSelectedItem(); @@ -266,7 +265,7 @@ public class SFilterUtil { * @return Predicate */ public static Predicate buildTypeFilter() { - if (MAP_TYPE_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); } + if (MAP_TYPE_CHECKBOXES.isEmpty()) { return Predicates.alwaysTrue(); } final List> ors = new ArrayList>(); JCheckBox chbTemp; @@ -292,7 +291,7 @@ public class SFilterUtil { chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.SORCERY)).getCheckBox(); if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_SORCERY); } - return Predicate.bridge(Predicate.or(ors), CardPrinted.FN_GET_RULES); + return Predicates.compose(Predicates.or(ors), CardPrinted.FN_GET_RULES); } /** @@ -303,8 +302,8 @@ public class SFilterUtil { * @return Predicate */ public static Predicate buildTextFilter() { - Predicate filterAnd = Predicate.getTrue(CardPrinted.class); - Predicate filterNot = Predicate.getTrue(CardPrinted.class); + Predicate filterAnd = Predicates.alwaysTrue(); + Predicate filterNot = Predicates.alwaysTrue(); final String strContains = VFilters.SINGLETON_INSTANCE.getTxfContains().getText(); final String strWithout = VFilters.SINGLETON_INSTANCE.getTxfWithout().getText(); @@ -324,17 +323,17 @@ public class SFilterUtil { for (final String s : splitContains) { final List> subands = new ArrayList>(); - if (useName) { subands.add(Predicate.bridge(CardRules.Predicates.name( + if (useName) { subands.add(Predicates.compose(CardRules.Predicates.name( StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); } - if (useType) { subands.add(Predicate.bridge(CardRules.Predicates.joinedType( + if (useType) { subands.add(Predicates.compose(CardRules.Predicates.joinedType( StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); } - if (useText) { subands.add(Predicate.bridge(CardRules.Predicates.rules( + if (useText) { subands.add(Predicates.compose(CardRules.Predicates.rules( StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); } - ands.add(Predicate.or(subands)); + ands.add(Predicates.or(subands)); } - filterAnd = Predicate.and(ands); + filterAnd = Predicates.and(ands); } if (!strWithout.isEmpty()) { @@ -348,20 +347,17 @@ public class SFilterUtil { for (final String s : splitWithout) { final List> subnots = new ArrayList>(); - if (useName) { subnots.add(Predicate.bridge(CardRules.Predicates.name( - StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); } - if (useType) { subnots.add(Predicate.bridge(CardRules.Predicates.joinedType( - StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); } - if (useText) { subnots.add(Predicate.bridge(CardRules.Predicates.rules( - StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); } + if (useName) { subnots.add(Predicates.compose(CardRules.Predicates.name(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); } + if (useType) { subnots.add(Predicates.compose(CardRules.Predicates.joinedType(StringOp.CONTAINS_IC, s), CardPrinted.FN_GET_RULES)); } + if (useText) { subnots.add(Predicates.compose(CardRules.Predicates.rules(StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); } - nots.add(Predicate.or(subnots)); + nots.add(Predicates.or(subnots)); } - filterNot = Predicate.not(Predicate.or(nots)); + filterNot = Predicates.not(Predicates.or(nots)); } - return Predicate.and(filterAnd, filterNot); + return Predicates.and(filterAnd, filterNot); } /** @@ -372,7 +368,7 @@ public class SFilterUtil { */ public static Predicate buildIntervalFilter() { final VFilters view = VFilters.SINGLETON_INSTANCE; - Predicate filter = Predicate.getTrue(CardPrinted.class); + Predicate filter = Predicates.alwaysTrue(); // Must include -1 so non-creatures are included by default. final int plow = view.getCbxPLow().getSelectedItem().toString().equals("*") @@ -398,73 +394,73 @@ public class SFilterUtil { // Power: CardRules returns null if no power, which means extra // filtering must be applied to allow all cards to be shown if * is chosen. // (Without this, lands and such would be filtered out by default.) - if (plow > phigh) { prePower = Predicate.getFalse(CardPrinted.class); } + if (plow > phigh) { prePower = Predicates.alwaysFalse(); } else { // If * is selected in the combo box, cards without power // will be included in the filter. final Predicate preNotCreature; if (plow == -1) { - preNotCreature = Predicate.not( - Predicate.bridge(CardRules.Predicates.Presets.IS_CREATURE, + preNotCreature = Predicates.not( + Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES)); } // Otherwise, if 0 or higher is selected, cards without power // are excluded. else { - preNotCreature = Predicate.getFalse(CardPrinted.class); + preNotCreature = Predicates.alwaysFalse(); } - final Predicate prePowerTemp = Predicate.and( - Predicate.bridge(CardRules.Predicates.power( + final Predicate prePowerTemp = Predicates.and( + Predicates.compose(CardRules.Predicates.power( ComparableOp.GT_OR_EQUAL, plow), CardPrinted.FN_GET_RULES), - Predicate.bridge(CardRules.Predicates.power( + Predicates.compose(CardRules.Predicates.power( ComparableOp.LT_OR_EQUAL, phigh), CardPrinted.FN_GET_RULES)); - prePower = Predicate.or(preNotCreature, prePowerTemp); + prePower = Predicates.or(preNotCreature, prePowerTemp); } // Toughness: CardRules returns null if no toughness, which means extra // filtering must be applied to allow all cards to be shown if * is chosen. // (Without this, lands and such would be filtered out by default.) - if (tlow > thigh) { preToughness = Predicate.getFalse(CardPrinted.class); } + if (tlow > thigh) { preToughness = Predicates.alwaysFalse(); } else { // If * is selected in the combo box, cards without toughness // will be included in the filter. final Predicate preNotCreature; if (tlow == -1) { - preNotCreature = Predicate.not( - Predicate.bridge(CardRules.Predicates.Presets.IS_CREATURE, + preNotCreature = Predicates.not( + Predicates.compose(CardRules.Predicates.Presets.IS_CREATURE, CardPrinted.FN_GET_RULES)); } // Otherwise, if 0 or higher is selected, cards without toughness // are excluded. else { - preNotCreature = Predicate.getFalse(CardPrinted.class); + preNotCreature = Predicates.alwaysFalse(); } - final Predicate preToughnessTemp = Predicate.and( - Predicate.bridge(CardRules.Predicates.toughness( + final Predicate preToughnessTemp = Predicates.and( + Predicates.compose(CardRules.Predicates.toughness( ComparableOp.GT_OR_EQUAL, tlow), CardPrinted.FN_GET_RULES), - Predicate.bridge(CardRules.Predicates.toughness( + Predicates.compose(CardRules.Predicates.toughness( ComparableOp.LT_OR_EQUAL, thigh), CardPrinted.FN_GET_RULES)); - preToughness = Predicate.or(preNotCreature, preToughnessTemp); + preToughness = Predicates.or(preNotCreature, preToughnessTemp); } // CMC, thankfully, will return -1 if the card doesn't have a CMC, // so it can be compared directly against the low value, and non-CMC // cards will still be included if * is chosen. - if (clow > chigh) { preCMC = Predicate.getFalse(CardPrinted.class); } + if (clow > chigh) { preCMC = Predicates.alwaysFalse(); } else { - preCMC = Predicate.and( - Predicate.bridge(CardRules.Predicates.cmc( + preCMC = Predicates.and( + Predicates.compose(CardRules.Predicates.cmc( ComparableOp.GT_OR_EQUAL, clow), CardPrinted.FN_GET_RULES), - Predicate.bridge(CardRules.Predicates.cmc( + Predicates.compose(CardRules.Predicates.cmc( ComparableOp.LT_OR_EQUAL, chigh), CardPrinted.FN_GET_RULES)); } // Stack them all together and return. - filter = Predicate.and(preCMC, Predicate.and(prePower, preToughness)); + filter = Predicates.and(preCMC, Predicates.and(prePower, preToughness)); return filter; } diff --git a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java index e6efe18d0b4..a0e904cc4c3 100644 --- a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java +++ b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java @@ -1,5 +1,7 @@ package forge.gui.deckeditor.controllers; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.Command; @@ -19,7 +21,7 @@ import forge.item.CardDb; import forge.item.CardPrinted; import forge.item.InventoryItem; import forge.util.Aggregates; -import forge.util.closures.Predicate; + /** * Controls the "analysis" panel in the deck editor UI. @@ -78,7 +80,7 @@ public enum CDeckgen implements ICDoc { final Deck randomDeck = new Deck(); - Predicate notBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).bridge(CardPrinted.FN_GET_RULES); + Predicate notBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND,CardPrinted.FN_GET_RULES)); Iterable source = Iterables.filter(CardDb.instance().getAllUniqueCards(), notBasicLand); randomDeck.getMain().addAllFlat(Aggregates.random(source, 15*5)); diff --git a/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java b/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java index 62e66299e82..9c480da6317 100644 --- a/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java +++ b/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java @@ -4,6 +4,8 @@ import java.util.Map.Entry; import javax.swing.JLabel; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.Command; @@ -19,7 +21,7 @@ import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.ItemPoolView; import forge.util.Aggregates; -import forge.util.closures.Predicate; + /** * Controls the "analysis" panel in the deck editor UI. @@ -57,7 +59,7 @@ public enum CStatistics implements ICDoc { } private void setLabelValue(JLabel label, ItemPoolView deck, Predicate predicate, int total) { - int tmp = Aggregates.sum(Iterables.filter(deck, predicate.bridge(deck.getFnToCard())), deck.getFnToCount()); + int tmp = Aggregates.sum(Iterables.filter(deck, Predicates.compose(predicate, deck.getFnToCard())), deck.getFnToCount()); label.setText( tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); } diff --git a/src/main/java/forge/gui/deckeditor/tables/TableView.java b/src/main/java/forge/gui/deckeditor/tables/TableView.java index b9688bfe0b0..4c0459ba4e6 100644 --- a/src/main/java/forge/gui/deckeditor/tables/TableView.java +++ b/src/main/java/forge/gui/deckeditor/tables/TableView.java @@ -27,6 +27,7 @@ import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableColumnModel; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.gui.deckeditor.SEditorUtil; @@ -274,11 +275,11 @@ public final class TableView { } if (useFilter && this.wantUnique) { - Predicate> filterForPool = forge.util.closures.Predicate.bridge(this.filter, this.pool.getFnToPrinted()); + Predicate> filterForPool = Predicates.compose(this.filter, this.pool.getFnToPrinted()); Iterable> cards = Aggregates.uniqueByLast(Iterables.filter(this.pool, filterForPool), this.pool.getFnToCardName()); this.model.addCards(cards); } else if (useFilter) { - Predicate> pred = forge.util.closures.Predicate.bridge(this.filter, this.pool.getFnToPrinted()); + Predicate> pred = Predicates.compose(this.filter, this.pool.getFnToPrinted()); this.model.addCards(Iterables.filter(this.pool, pred)); } else if (this.wantUnique) { Iterable> cards = Aggregates.uniqueByLast(this.pool, this.pool.getFnToCardName()); diff --git a/src/main/java/forge/item/CardDb.java b/src/main/java/forge/item/CardDb.java index e6a7f5e6580..b85cdb0a653 100644 --- a/src/main/java/forge/item/CardDb.java +++ b/src/main/java/forge/item/CardDb.java @@ -29,6 +29,7 @@ import java.util.NoSuchElementException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -38,7 +39,7 @@ import forge.card.CardInSet; import forge.card.CardRules; import forge.card.MtgDataParser; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; + /** *

diff --git a/src/main/java/forge/item/CardPrinted.java b/src/main/java/forge/item/CardPrinted.java index 1de8955ca19..99ce4a2ff6a 100644 --- a/src/main/java/forge/item/CardPrinted.java +++ b/src/main/java/forge/item/CardPrinted.java @@ -23,15 +23,17 @@ import java.util.List; import org.apache.commons.lang3.ArrayUtils; +import com.google.common.base.Function; +import com.google.common.base.Predicate; + import forge.AllZone; import forge.Card; import forge.CardUtil; import forge.card.CardRarity; import forge.card.CardRules; import forge.game.player.Player; -import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; -import forge.util.closures.PredicateString; +import forge.util.PredicateString; + /** * A viciously lightweight version of a card, for instances @@ -167,7 +169,7 @@ public final class CardPrinted implements Comparable, InventoryItem * Lambda to get rules for selects from list of printed cards. * */ - public static final Lambda1 FN_GET_RULES = new Lambda1() { + public static final Function FN_GET_RULES = new Function() { @Override public CardRules apply(final CardPrinted from) { return from.card; @@ -337,7 +339,7 @@ public final class CardPrinted implements Comparable, InventoryItem */ public static Predicate printedInSets(final List value, final boolean shouldContain) { if ((value == null) || value.isEmpty()) { - return Predicate.getTrue(CardPrinted.class); + return com.google.common.base.Predicates.alwaysTrue(); } return new PredicateSets(value, shouldContain); } @@ -351,7 +353,7 @@ public final class CardPrinted implements Comparable, InventoryItem */ public static Predicate printedInSets(final String value) { if ((value == null) || value.isEmpty()) { - return Predicate.getTrue(CardPrinted.class); + return com.google.common.base.Predicates.alwaysTrue(); } return new PredicateSets(Arrays.asList(new String[] { value }), true); } @@ -391,7 +393,7 @@ public final class CardPrinted implements Comparable, InventoryItem return new PredicateNamesExcept(what); } - private static class PredicateRarity extends Predicate { + private static class PredicateRarity implements Predicate { private final CardRarity operand; private final boolean shouldBeEqual; @@ -406,7 +408,7 @@ public final class CardPrinted implements Comparable, InventoryItem } } - private static class PredicateSets extends Predicate { + private static class PredicateSets implements Predicate { private final List sets; private final boolean mustContain; @@ -475,7 +477,7 @@ public final class CardPrinted implements Comparable, InventoryItem public static final Predicate IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare); /** The Constant isRareOrMythic. */ - public static final Predicate IS_RARE_OR_MYTHIC = Predicate.or(Presets.IS_RARE, + public static final Predicate IS_RARE_OR_MYTHIC = com.google.common.base.Predicates.or(Presets.IS_RARE, Presets.IS_MYTHIC_RARE); /** The Constant isSpecial. */ @@ -483,10 +485,6 @@ public final class CardPrinted implements Comparable, InventoryItem /** The Constant exceptLands. */ public static final Predicate EXCEPT_LANDS = Predicates.rarity(false, CardRarity.BasicLand); - - /** The Constant isTrue. */ - public static final Predicate IS_TRUE = Predicate.getTrue(CardPrinted.class); - } } } diff --git a/src/main/java/forge/item/ItemPredicate.java b/src/main/java/forge/item/ItemPredicate.java index e051998ff93..e53c78712d2 100644 --- a/src/main/java/forge/item/ItemPredicate.java +++ b/src/main/java/forge/item/ItemPredicate.java @@ -1,7 +1,10 @@ package forge.item; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + + -import forge.util.closures.Predicate; /** * Filtering conditions for miscellaneous InventoryItems. @@ -60,7 +63,7 @@ public abstract class ItemPredicate { * * @return the predicate */ - public static class PredicateBoosterPack extends Predicate { + public static class PredicateBoosterPack implements Predicate { @Override public boolean apply(final InventoryItem card) { @@ -73,7 +76,7 @@ public abstract class ItemPredicate { * * @return the predicate */ - public static class PredicateFatPack extends Predicate { + public static class PredicateFatPack implements Predicate { @Override public boolean apply(final InventoryItem card) { @@ -86,7 +89,7 @@ public abstract class ItemPredicate { * * @return the predicate */ - public static class PredicateTournamentPack extends Predicate { + public static class PredicateTournamentPack implements Predicate { @Override public boolean apply(final InventoryItem card) { @@ -99,7 +102,7 @@ public abstract class ItemPredicate { * * @return the predicate */ - public static class PredicateStarterDeck extends Predicate { + public static class PredicateStarterDeck implements Predicate { @Override public boolean apply(final InventoryItem card) { @@ -112,7 +115,7 @@ public abstract class ItemPredicate { * * @return the predicate */ - public static class PredicatePrebuiltDeck extends Predicate { + public static class PredicatePrebuiltDeck implements Predicate { @Override public boolean apply(final InventoryItem card) { @@ -135,7 +138,8 @@ public abstract class ItemPredicate { public static final Predicate IS_TOURNAMENT_PACK = tournamentPack(); /** The Item IsPack. */ - public static final Predicate IS_PACK = Predicate.or(Predicate.or(IS_BOOSTER_PACK, IS_FAT_PACK), IS_TOURNAMENT_PACK); + @SuppressWarnings("unchecked") + public static final Predicate IS_PACK = Predicates.or(IS_BOOSTER_PACK, IS_FAT_PACK, IS_TOURNAMENT_PACK); /** The Item IsStarterDeck. */ public static final Predicate IS_STARTER_DECK = starterDeck(); @@ -144,6 +148,6 @@ public abstract class ItemPredicate { public static final Predicate IS_PREBUILT_DECK = prebuiltDeck(); /** The Item IsDeck. */ - public static final Predicate IS_DECK = Predicate.or(IS_STARTER_DECK, IS_PREBUILT_DECK); + public static final Predicate IS_DECK = Predicates.or(IS_STARTER_DECK, IS_PREBUILT_DECK); } } diff --git a/src/main/java/forge/item/OpenablePack.java b/src/main/java/forge/item/OpenablePack.java index 405d93159a2..8dbcf274de5 100644 --- a/src/main/java/forge/item/OpenablePack.java +++ b/src/main/java/forge/item/OpenablePack.java @@ -19,13 +19,14 @@ package forge.item; import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.card.BoosterData; import forge.card.BoosterGenerator; import forge.card.CardRules; import forge.util.Aggregates; -import forge.util.closures.Predicate; /** * TODO: Write javadoc for this type. @@ -171,9 +172,9 @@ public abstract class OpenablePack implements InventoryItemFromSet { * @return the random basic lands */ protected List getRandomBasicLands(final String setCode, final int count) { - Predicate cardsRule = Predicate.and( + Predicate cardsRule = Predicates.and( CardPrinted.Predicates.printedInSets(setCode), - CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES); + Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES)); return Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), cardsRule), count); } diff --git a/src/main/java/forge/quest/BoosterUtils.java b/src/main/java/forge/quest/BoosterUtils.java index 5acf70d9f5c..c5fbbc1b736 100644 --- a/src/main/java/forge/quest/BoosterUtils.java +++ b/src/main/java/forge/quest/BoosterUtils.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; @@ -33,7 +35,6 @@ import forge.item.CardPrinted; import forge.util.Aggregates; import forge.util.MyRandom; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; // The BoosterPack generates cards for the Card Pool in Quest Mode /** @@ -85,12 +86,12 @@ public final class BoosterUtils { final Iterable cardpool = CardDb.instance().getAllUniqueCards(); cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, - Predicate.and(filter, CardPrinted.Predicates.Presets.IS_COMMON), numCommon, colorFilters)); + Predicates.and(filter, CardPrinted.Predicates.Presets.IS_COMMON), numCommon, colorFilters)); cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, - Predicate.and(filter, CardPrinted.Predicates.Presets.IS_UNCOMMON), numUncommon, colorFilters)); + Predicates.and(filter, CardPrinted.Predicates.Presets.IS_UNCOMMON), numUncommon, colorFilters)); int nRares = numRare, nMythics = 0; - final Predicate filterMythics = Predicate.and(filter, + final Predicate filterMythics = Predicates.and(filter, CardPrinted.Predicates.Presets.IS_MYTHIC_RARE); final boolean haveMythics = Iterables.any(cardpool, filterMythics); for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) { @@ -102,7 +103,7 @@ public final class BoosterUtils { } cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, - Predicate.and(filter, CardPrinted.Predicates.Presets.IS_RARE), nRares, colorFilters)); + Predicates.and(filter, CardPrinted.Predicates.Presets.IS_RARE), nRares, colorFilters)); if (nMythics > 0) { cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters)); } @@ -142,7 +143,8 @@ public final class BoosterUtils { if (size > 0) { final Predicate color2 = allowedColors.get(iAttempt % size); if (color2 != null) { - card = Aggregates.random(Iterables.filter(source, Predicate.and(filter, color2, CardPrinted.FN_GET_RULES))); + Predicate color2c = Predicates.compose(color2, CardPrinted.FN_GET_RULES); + card = Aggregates.random(Iterables.filter(source, Predicates.and(filter, color2c))); } } @@ -231,7 +233,7 @@ public final class BoosterUtils { } // Determine color ("random" defaults to null color) - Predicate col = Predicate.getTrue(CardRules.class); + Predicate col = Predicates.alwaysTrue(); if (temp[1].equalsIgnoreCase("black")) { col = CardRules.Predicates.Presets.IS_BLACK; } else if (temp[1].equalsIgnoreCase("blue")) { @@ -254,6 +256,7 @@ public final class BoosterUtils { return arg1.getSingletonBoosterPack(qty); } }; - return new UnOpenedProduct(openWay, new BoosterGenerator(Predicate.and(rar, col, CardPrinted.FN_GET_RULES))); // qty)) + Predicate colorPred = Predicates.compose(col, CardPrinted.FN_GET_RULES); + return new UnOpenedProduct(openWay, new BoosterGenerator(Predicates.and(rar, colorPred))); // qty)) } } diff --git a/src/main/java/forge/quest/QuestController.java b/src/main/java/forge/quest/QuestController.java index df18a15530f..37302341f8a 100644 --- a/src/main/java/forge/quest/QuestController.java +++ b/src/main/java/forge/quest/QuestController.java @@ -20,6 +20,9 @@ package forge.quest; import java.util.HashMap; import java.util.Map; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + import forge.Singletons; import forge.deck.Deck; import forge.item.CardPrinted; @@ -36,7 +39,6 @@ import forge.quest.io.PreconReader; import forge.util.IStorage; import forge.util.IStorageView; import forge.util.StorageView; -import forge.util.closures.Predicate; /** * TODO: Write javadoc for this type. @@ -210,7 +212,7 @@ public class QuestController { break; default: // Unrestricted - filter = CardPrinted.Predicates.Presets.IS_TRUE; + filter = Predicates.alwaysTrue(); break; } diff --git a/src/main/java/forge/quest/QuestUtilCards.java b/src/main/java/forge/quest/QuestUtilCards.java index c85997c09aa..2266bc48da8 100644 --- a/src/main/java/forge/quest/QuestUtilCards.java +++ b/src/main/java/forge/quest/QuestUtilCards.java @@ -30,12 +30,13 @@ import forge.quest.data.QuestPreferences.QPref; import forge.util.Aggregates; import forge.util.MyRandom; import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Iterables; /** @@ -101,9 +102,9 @@ public final class QuestUtilCards { final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES); final ArrayList newCards = new ArrayList(); - newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON), nCommon)); - newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON), nUncommon)); - newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC), nRare)); + newCards.addAll(BoosterUtils.generateDistinctCards(Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON), nCommon)); + newCards.addAll(BoosterUtils.generateDistinctCards(Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON), nUncommon)); + newCards.addAll(BoosterUtils.generateDistinctCards(Predicates.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC), nRare)); this.addAllCards(newCards); return newCards; @@ -322,18 +323,18 @@ public final class QuestUtilCards { private final Predicate filterExt = CardEdition.Predicates.isLegalInFormat(this.formats.getExtended()); /** The filter t2booster. */ - private final Predicate filterT2booster = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, + private final Predicate filterT2booster = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, CardEdition.Predicates.isLegalInFormat(this.formats.getStandard())); /** The filter ext but t2. */ - private final Predicate filterExtButT2 = Predicate.and( + private final Predicate filterExtButT2 = Predicates.and( CardEdition.Predicates.CAN_MAKE_BOOSTER, - Predicate.and(this.filterExt, - Predicate.not(CardEdition.Predicates.isLegalInFormat(this.formats.getStandard())))); + Predicates.and(this.filterExt, + Predicates.not(CardEdition.Predicates.isLegalInFormat(this.formats.getStandard())))); /** The filter not ext. */ - private final Predicate filterNotExt = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, - Predicate.not(this.filterExt)); + private final Predicate filterNotExt = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, + Predicates.not(this.filterExt)); /** * Generate boosters in shop. diff --git a/src/main/java/forge/util/closures/Lambda.java b/src/main/java/forge/util/ComparableOp.java similarity index 70% rename from src/main/java/forge/util/closures/Lambda.java rename to src/main/java/forge/util/ComparableOp.java index f74f795ed5a..a34b72fe413 100644 --- a/src/main/java/forge/util/closures/Lambda.java +++ b/src/main/java/forge/util/ComparableOp.java @@ -1,36 +1,34 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.util.closures; - -/** - * The Interface Lambda. - * - * @param - * the generic type - */ -public interface Lambda { - - /** - * Apply. - * - * @param args - * the args - * @return the r - */ - R apply(Object[] args); -} +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 MaxMtg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.util; + +/** + * Possible operators for comparables. + * + * @author Max + * + */ +public enum ComparableOp { + + EQUALS, + NOT_EQUALS, + GREATER_THAN, + LESS_THAN, + GT_OR_EQUAL, + LT_OR_EQUAL +} diff --git a/src/main/java/forge/util/closures/PredicateString.java b/src/main/java/forge/util/PredicateString.java similarity index 93% rename from src/main/java/forge/util/closures/PredicateString.java rename to src/main/java/forge/util/PredicateString.java index a7a66c92bfd..93ce1beff13 100644 --- a/src/main/java/forge/util/closures/PredicateString.java +++ b/src/main/java/forge/util/PredicateString.java @@ -15,17 +15,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.util.closures; +package forge.util; import org.apache.commons.lang3.StringUtils; +import com.google.common.base.Predicate; + /** * Special predicate class to perform string operations. * * @param * the generic type */ -public abstract class PredicateString extends Predicate { +public abstract class PredicateString implements Predicate { /** Possible operators for string operands. */ public enum StringOp { /** The CONTAINS. */ diff --git a/src/main/java/forge/util/closures/Lambda0.java b/src/main/java/forge/util/closures/Lambda0.java index 9fcfff6f90d..659fea2228a 100644 --- a/src/main/java/forge/util/closures/Lambda0.java +++ b/src/main/java/forge/util/closures/Lambda0.java @@ -17,13 +17,12 @@ */ package forge.util.closures; - /** * The Class Lambda1. * * @param the generic type */ -public abstract class Lambda0 implements Lambda { +public abstract class Lambda0 { /** * Apply. @@ -31,25 +30,4 @@ public abstract class Lambda0 implements Lambda { * @return the r */ public abstract R apply(); - - /* - * (non-Javadoc) - * - * @see - * net.slightlymagic.braids.util.lambda.Lambda#apply(java.lang.Object[]) - */ - - // TODO @Override - /** - * Apply. - * - * @param args - * Object[] - * @return R - */ - @Override - public final R apply(final Object[] args) { - return this.apply(); - } - } diff --git a/src/main/java/forge/util/closures/Lambda1.java b/src/main/java/forge/util/closures/Lambda1.java index e8c6bea4f85..cb5a5c0a0c7 100644 --- a/src/main/java/forge/util/closures/Lambda1.java +++ b/src/main/java/forge/util/closures/Lambda1.java @@ -28,7 +28,7 @@ import com.google.common.base.Function; * @param * the generic type */ -public abstract class Lambda1 implements Lambda, Function { +public abstract class Lambda1 implements Function { /** * Apply. @@ -38,25 +38,4 @@ public abstract class Lambda1 implements Lambda, Function { * @return the r */ public abstract R apply(A1 arg1); - - /* - * (non-Javadoc) - * - * @see - * net.slightlymagic.braids.util.lambda.Lambda#apply(java.lang.Object[]) - */ - - // TODO @Override - /** - * Apply. - * - * @param args Object[] - * @return R - */ - @Override - @SuppressWarnings("unchecked") - public final R apply(final Object[] args) { - return apply((A1) args[0]); - } - } diff --git a/src/main/java/forge/util/closures/Predicate.java b/src/main/java/forge/util/closures/Predicate.java deleted file mode 100644 index a76b039fea4..00000000000 --- a/src/main/java/forge/util/closures/Predicate.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 MaxMtg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.util.closures; - -import com.google.common.base.Function; - -/** - * Predicate class allows to select items or type , which are or contain an - * object of type , matching to some criteria set by predicate. No need to - * write that simple operation by hand. - * - * Implements com.google.common.base.Predicates, so you may use this in Guava collection management routines. - * - * @param - * - class to check condition against - * @author Max - */ - -public abstract class Predicate implements com.google.common.base.Predicate{ - - /** - * Possible operators on two predicates. - * - * @author Max - */ - public enum PredicatesOp { - - /** The AND. */ - AND, - /** The OR. */ - OR, - /** The XOR. */ - XOR, - /** The EQ. */ - EQ, - /** The NOR. */ - NOR, - /** The NAND. */ - NAND, - /** */ - GT, - /** */ - LT - } - - /** - * This is the main method, predicates were made for. - * - * @param subject - * the subject - * @return true, if is true - */ - public abstract boolean apply(T subject); - - // Overloaded only in LeafConstant - /** - * These are checks against constants, they will let simpler - * expressions be built. - * - * @return true, if is 1 - */ - public boolean is1() { - return false; - } - - /** - * Checks if is 0. - * - * @return true, if is 0 - */ - public boolean is0() { - return false; - } - - /** - * Brigde (transforms a predicate of type T into a predicate - * of type U, using a bridge function passed as an argument). - * - * @param - * the generic type - * @param - * the generic type - * @param predicate - * the predicate - * @param fnBridge - * the fn bridge - * @return the predicate - */ - public static final Predicate bridge(final com.google.common.base.Predicate predicate, final Function fnBridge) { - return new Bridge(predicate, fnBridge); - } - - public final Predicate bridge(final Function fnBridge) { - return new Bridge(this, fnBridge); - } - - - - /** - * Compose. - * - * @param - * the generic type - * @param operand1 - * the operand1 - * @param operator - * the operator - * @param operand2 - * the operand2 - * @return the predicate - */ - public static Predicate compose(final Predicate operand1, final PredicatesOp operator, - final Predicate operand2) { - return new Node(operand1, operator, operand2); - } - - // Predefined operators: and, or - /** - * And. - * - * @param - * the generic type - * @param operand1 - * the operand1 - * @param operand2 - * the operand2 - * @return the predicate - */ - public static Predicate and(final Predicate operand1, final Predicate operand2) { - if (operand1.is1()) { - return operand2; - } - if ((operand2 == null) || operand2.is1()) { - return operand1; - } - return new NodeAnd(operand1, operand2); - } - - /** - * And. - * - * @param - * the generic type - * @param operand - * the operand - * @return the predicate - */ - public static Predicate and(final Iterable> operand) { - return new MultiNodeAnd(operand); - } - - /** - * And. - * - * @param - * the generic type - * @param - * the generic type - * @param operand1 - * the operand1 - * @param operand2 - * the operand2 - * @param bridge - * the bridge - * @return the predicate - */ - public static Predicate and(final Predicate operand1, final Predicate operand2, - final Lambda1 fnBridge) { - return new NodeAnd(operand1, operand2.bridge(fnBridge)); - } - - /** - * Or. - * - * @param - * the generic type - * @param operand1 - * the operand1 - * @param operand2 - * the operand2 - * @return the predicate - */ - public static Predicate or(final Predicate operand1, final Predicate operand2) { - return new NodeOr(operand1, operand2); - } - - /** - * Or. - * - * @param - * the generic type - * @param operand - * the operand - * @return the predicate - */ - public static Predicate or(final Iterable> operand) { - return new MultiNodeOr(operand); - } - - /** - * Or. - * - * @param - * the generic type - * @param - * the generic type - * @param operand1 - * the operand1 - * @param operand2 - * the operand2 - * @param bridge - * the bridge - * @return the predicate - */ - public static Predicate or(final Predicate operand1, final Predicate operand2, - final Lambda1 bridge) { - return new NodeOrBridged(operand1, operand2, bridge); - } - - /** - * Not. - * - * @param - * the generic type - * @param operand1 - * the operand1 - * @return the predicate - */ - public static Predicate not(final Predicate operand1) { - return new Not(operand1); - } - - /** - * Gets the true. - * - * @param - * the generic type - * @param cls - * the cls - * @return the true - */ - public static Predicate getTrue(final Class cls) { - return new LeafConstant(true); - } - - /** - * Gets the false. - * - * @param - * the generic type - * @param cls - * the cls - * @return the false - */ - public static Predicate getFalse(final Class cls) { - return new LeafConstant(false); - } -} - -// Concrete implementations -// unary operators -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -final class Not extends Predicate { - /** - * - */ - private final Predicate filter; - - /** - * - * TODO: Write javadoc for Constructor. - * - * @param operand Predicate - */ - public Not(final Predicate operand) { - this.filter = operand; - } - - @Override - public boolean apply(final T card) { - return !this.filter.apply(card); - } -} - -/** - * - * TODO: Write javadoc for this type. - * - * @param - * @param - */ -final class Bridge extends Predicate { - /** - * - */ - private final com.google.common.base.Predicate filter; - /** - * - */ - private final Function fnBridge; - - /** - * - * TODO: Write javadoc for Constructor. - * - * @param operand Predicate - * @param fnTfromU Lambda1 - */ - public Bridge(final com.google.common.base.Predicate operand, final Function fnTfromU) { - this.filter = operand; - this.fnBridge = fnTfromU; - } - - @Override - public boolean apply(final U card) { - return this.filter.apply(this.fnBridge.apply(card)); - } -} - - -// binary operators -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -/* PERFORMANCE CRITICAL - DO NOT GENERATE GETTERS HERE*/ -class Node extends Predicate { - /* PERFORMANCE CRITICAL - DO NOT GENERATE GETTERS HERE*/ - private final PredicatesOp operator; - protected final Predicate filter1; - protected final Predicate filter2; - /* PERFORMANCE CRITICAL - DO NOT GENERATE GETTERS HERE*/ - - /** - * - * Node. - * - * @param operand1 Predicate - * @param op PredicatesOp - * @param operand2 Predicate - */ - public Node(final Predicate operand1, final PredicatesOp op, final Predicate operand2) { - this.operator = op; - this.filter1 = operand1; - this.filter2 = operand2; - } - - @Override - public boolean apply(final T card) { - switch (this.operator) { - case AND: - return this.filter1.apply(card) && this.filter2.apply(card); - case GT: - return this.filter1.apply(card) && !this.filter2.apply(card); - case LT: - return !this.filter1.apply(card) && this.filter2.apply(card); - case NAND: - return !(this.filter1.apply(card) && this.filter2.apply(card)); - case OR: - return this.filter1.apply(card) || this.filter2.apply(card); - case NOR: - return !(this.filter1.apply(card) || this.filter2.apply(card)); - case XOR: - return this.filter1.apply(card) ^ this.filter2.apply(card); - case EQ: - return this.filter1.apply(card) == this.filter2.apply(card); - default: - return false; - } - } - - -} - -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -final class NodeOr extends Node { - /** - * - * TODO: Write javadoc for Constructor. - * - * @param operand1 Predicate - * @param operand2 Predicate - */ - public NodeOr(final Predicate operand1, final Predicate operand2) { - super(operand1, PredicatesOp.OR, operand2); - } - - @Override - public boolean apply(final T card) { - return this.filter1.apply(card) || this.filter2.apply(card); - } -} - -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -final class NodeAnd extends Node { - /** - * - * TODO: Write javadoc for Constructor. - * - * @param operand1 Predicate - * @param operand2 Predicate - */ - public NodeAnd(final Predicate operand1, final Predicate operand2) { - super(operand1, PredicatesOp.AND, operand2); - } - - @Override - public boolean apply(final T card) { - return this.filter1.apply(card) && this.filter2.apply(card); - } -} - -// Bridged OR and AND -/** - * - * TODO: Write javadoc for this type. - * - * @param - * @param - */ -final class NodeOrBridged extends Predicate { - private final Predicate filter1; - private final Predicate filter2; - private final Lambda1 bridge; - - /** - * - * TODO: Write javadoc for Constructor. - * - * @param operand1 Predicate - * @param operand2 Predicate - * @param accessor Lambda - */ - public NodeOrBridged(final Predicate operand1, final Predicate operand2, final Lambda1 accessor) { - this.filter1 = operand1; - this.filter2 = operand2; - this.bridge = accessor; - } - - @Override - public boolean apply(final T card) { - return this.filter1.apply(card) || this.filter2.apply(this.bridge.apply(card)); - } -} - -/** - * - * TODO: Write javadoc for this type. - * - * @param - * @param - */ -final class NodeAndBridged extends Predicate { - private final Predicate filter1; - private final Predicate filter2; - private final Lambda1 bridge; - - /** - * - * TODO: Write javadoc for Constructor. - * - * @param operand1 Predicate - * @param operand2 Predicate - * @param accessor Lambda - */ - public NodeAndBridged(final Predicate operand1, final Predicate operand2, final Lambda1 accessor) { - this.filter1 = operand1; - this.filter2 = operand2; - this.bridge = accessor; - } - - @Override - public boolean apply(final T card) { - return this.filter1.apply(card) && this.filter2.apply(this.bridge.apply(card)); - } -} - -// multi-operand operators -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -abstract class MultiNode extends Predicate { - /** - * - */ - private final Iterable> operands; - - /** - * - * TODO: Write javadoc for Constructor. - * - * @param filters Iterable> - */ - public MultiNode(final Iterable> filters) { - this.operands = filters; - } - - /** - * @return the operands - */ - public Iterable> getOperands() { - return operands; - } -} - -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -final class MultiNodeAnd extends MultiNode { - /** - * - * TODO: Write javadoc for Constructor. - * - * @param filters Iterable> - */ - public MultiNodeAnd(final Iterable> filters) { - super(filters); - } - - @Override - public boolean apply(final T subject) { - for (final Predicate p : this.getOperands()) { - if (!p.apply(subject)) { - return false; - } - } - return true; - } -} - -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -final class MultiNodeOr extends MultiNode { - /** - * - * TODO: Write javadoc for Constructor. - * - * @param filters Iterable> - */ - public MultiNodeOr(final Iterable> filters) { - super(filters); - } - - @Override - public boolean apply(final T subject) { - for (final Predicate p : this.getOperands()) { - if (p.apply(subject)) { - return true; - } - } - return false; - } -} - - - -/** - * - * TODO: Write javadoc for this type. - * - * @param - */ -class LeafConstant extends Predicate { - private final boolean bValue; - - @Override - public boolean is1() { - return this.bValue; - } - - @Override - public boolean is0() { - return !this.bValue; - } - - @Override - public boolean apply(final T card) { - return this.bValue; - } - - /** - * - * TODO: Write javadoc for Constructor. - * - * @param value boolean - */ - public LeafConstant(final boolean value) { - this.bValue = value; - } -} diff --git a/src/main/java/forge/util/closures/PredicateInteger.java b/src/main/java/forge/util/closures/PredicateInteger.java deleted file mode 100644 index a1df40fedf3..00000000000 --- a/src/main/java/forge/util/closures/PredicateInteger.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 MaxMtg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.util.closures; - -/** - * Special predicate class to perform integer operations. - * - * @param - * the generic type - */ -public abstract class PredicateInteger extends Predicate { - - /** - * Possible operators for comparables. - * - * @author Max - * - */ - public enum ComparableOp { - - /** The EQUALS. */ - EQUALS, - /** The NO t_ equals. */ - NOT_EQUALS, - /** The GREATE r_ than. */ - GREATER_THAN, - /** The LES s_ than. */ - LESS_THAN, - /** The G t_ o r_ equal. */ - GT_OR_EQUAL, - /** The L t_ o r_ equal. */ - LT_OR_EQUAL - } - - /** The operator. */ - private final ComparableOp operator; - - /** - * Op. - * - * @param op1 - * the op1 - * @param op2 - * the op2 - * @return true, if successful - */ - protected final boolean op(final int op1, final int op2) { - switch (this.getOperator()) { - case GREATER_THAN: - return op1 > op2; - case LESS_THAN: - return op1 < op2; - case GT_OR_EQUAL: - return op1 >= op2; - case LT_OR_EQUAL: - return op1 <= op2; - case EQUALS: - return op1 == op2; - case NOT_EQUALS: - return op1 != op2; - default: - return false; - } - } - - /** - * Instantiates a new integer predicate. - * - * @param operator - * the operator - */ - public PredicateInteger(final ComparableOp operator) { - this.operator = operator; - } - - /** - * @return the operator - */ - public ComparableOp getOperator() { - return operator; - } -}