Removal of forge.util.closures.Predicate in favour of guava implementation

This commit is contained in:
Maxmtg
2012-09-28 06:53:56 +00:00
parent ffb8c78e60
commit c34eabdb6e
69 changed files with 370 additions and 1056 deletions

6
.gitattributes vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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;
/**
* <p>
@@ -97,7 +99,7 @@ public class CardList extends ArrayList<Card> {
// 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<Card> {
}
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<Card> {
}
public final CardList getUnprotectedCards(final Card source) {
return this.filter(Predicate.not(CardPredicates.isProtectedFrom(source)));
return this.filter(Predicates.not(CardPredicates.isProtectedFrom(source)));
}
/**

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>
@@ -322,9 +323,6 @@ public final class CardPredicates {
return c.isCreature() && (!c.hasFirstStrike() || c.hasDoubleStrike());
}
};
public static final Predicate<Card> All = Predicate.getTrue(Card.class);
}
public static class Accessors {

View File

@@ -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;
/**
* <p>

View File

@@ -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.

View File

@@ -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;
/**
* <p>

View File

@@ -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.

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**

View File

@@ -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;
/**
* <p>
@@ -176,7 +178,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
/** The Constant canMakeBooster. */
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = new CanMakeBooster();
private static class CanMakeBooster extends Predicate<CardEdition> {
private static class CanMakeBooster implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getModel().getBoosters().contains(subject.getCode());
@@ -184,7 +186,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
}
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
private static class CanMakeStarter extends Predicate<CardEdition> {
private static class CanMakeStarter implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getModel().getTournamentPacks().contains(subject.getCode());
@@ -192,7 +194,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
}
public static final Predicate<CardEdition> HAS_FAT_PACK = new CanMakeFatPack();
private static class CanMakeFatPack extends Predicate<CardEdition> {
private static class CanMakeFatPack implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getModel().getFatPacks().contains(subject.getCode());
@@ -209,7 +211,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
return new LegalInFormat(format);
}
private static class LegalInFormat extends Predicate<CardEdition> {
private static class LegalInFormat implements Predicate<CardEdition> {
private final GameFormat format;
public LegalInFormat(final GameFormat fmt) {

View File

@@ -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<CardRules> {
private static class LeafColor implements Predicate<CardRules> {
public enum ColorOperator {
CountColors, CountColorsGreaterOrEqual, HasAnyOf, HasAllOf, Equals
}
@@ -731,7 +731,7 @@ public final class CardRules {
}
}
private static class LeafNumber extends Predicate<CardRules> {
private static class LeafNumber implements Predicate<CardRules> {
protected enum CardField {
CMC, POWER, TOUGHNESS,
}
@@ -783,7 +783,7 @@ public final class CardRules {
}
}
private static class PredicateCoreType extends Predicate<CardRules> {
private static class PredicateCoreType implements Predicate<CardRules> {
private final CardCoreType operand;
private final boolean shouldBeEqual;
@@ -798,7 +798,7 @@ public final class CardRules {
}
}
private static class PredicateSuperType extends Predicate<CardRules> {
private static class PredicateSuperType implements Predicate<CardRules> {
private final CardSuperType operand;
private final boolean shouldBeEqual;
@@ -813,7 +813,7 @@ public final class CardRules {
}
}
private static class PredicateLastesSetRarity extends Predicate<CardRules> {
private static class PredicateLastesSetRarity implements Predicate<CardRules> {
private final CardRarity operand;
private final boolean shouldBeEqual;
@@ -828,7 +828,7 @@ public final class CardRules {
}
}
private static class PredicateExistsInSets extends Predicate<CardRules> {
private static class PredicateExistsInSets implements Predicate<CardRules> {
private final List<String> sets;
public PredicateExistsInSets(final List<String> wantSets) {
@@ -886,16 +886,14 @@ public final class CardRules {
public static final Predicate<CardRules> IS_NON_LAND = Predicates.coreType(false, CardCoreType.Land);
/** The Constant isNonCreatureSpell. */
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = Predicate.compose(Presets.IS_CREATURE,
PredicatesOp.NOR, Presets.IS_LAND);
public static final Predicate<CardRules> 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<CardRules> IS_NONCREATURE_SPELL_FOR_GENERATOR = Predicate.or(Arrays.asList(
public static final Predicate<CardRules> 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<CardRules> CONSTANT_TRUE = Predicate.getTrue(CardRules.class);
// Think twice before using these, since rarity is a prop of printed
// card.
/** The Constant isInLatestSetCommon. */

View File

@@ -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<CardPrinted>();
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<CardPrinted>();
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<CardPrinted>();
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 <T> void addMatchingItems(Collection<? super T> dest, Predicate<T> predicate, Iterable<T> source) {
for(T item : Iterables.filter(source, predicate))
private static <T, U> void addMatchingItems(Collection<? super T> dest, Iterable<? extends T> source, Predicate<U> predicate, Function<T, U> fn) {
for(T item : Iterables.filter(source, Predicates.compose(predicate, fn)))
dest.add(item);
}

View File

@@ -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) {

View File

@@ -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;
/**
* <p>
@@ -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)) {

View File

@@ -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;
/**
* <p>
@@ -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();
}

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>

View File

@@ -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

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>
* AbilityFactory_Copy class.

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**

View File

@@ -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;
/**
* <p>

View File

@@ -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

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**

View File

@@ -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;
/**

View File

@@ -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;
/**

View File

@@ -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;
/**

View File

@@ -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;
/**
* <p>
@@ -85,12 +86,13 @@ public abstract class GenerateColoredDeckBase {
final Iterable<CardPrinted> cards = selectCardsOfMatchingColorForPlayer(pt);
// build subsets based on type
final Iterable<CardPrinted> creatures = Iterables.filter(cards, CardRules.Predicates.Presets.IS_CREATURE.bridge(CardPrinted.FN_GET_RULES));
final Iterable<CardPrinted> 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<CardPrinted> spells = Iterables.filter(cards, CardRules.Predicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR.bridge(CardPrinted.FN_GET_RULES));
Predicate<CardPrinted> preSpells = Predicates.compose(CardRules.Predicates.Presets.IS_NONCREATURE_SPELL_FOR_GENERATOR, CardPrinted.FN_GET_RULES);
final Iterable<CardPrinted> 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<CardPrinted> exceptBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).bridge(CardPrinted.FN_GET_RULES);
Predicate<CardPrinted> 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<CardPrinted> matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand);
@@ -196,7 +198,7 @@ public abstract class GenerateColoredDeckBase {
final List<CardPrinted> curved = new ArrayList<CardPrinted>();
for (int i = 0; i < cmcAmounts.length; i++) {
Iterable<CardPrinted> matchingCards = Iterables.filter(source, cmcLevels.get(i).bridge(CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> 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<CardRules> 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<CardPrinted> outList) {

View File

@@ -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;
/**
* <p>
@@ -60,7 +62,7 @@ public class GenerateDeckUtil {
}
};
public static class ContainsAllColorsFrom extends Predicate<CardRules> {
public static class ContainsAllColorsFrom implements Predicate<CardRules> {
private final CardColor allowedColor;
public ContainsAllColorsFrom(CardColor color) {
allowedColor = color;
@@ -72,7 +74,7 @@ public class GenerateDeckUtil {
}
}
public static class FilterCMC extends Predicate<CardRules> {
public static class FilterCMC implements Predicate<CardRules> {
private final int min;
private final int max;

View File

@@ -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<CardPrinted> buildFilterPritned() {
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
final Predicate<CardPrinted> 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<CardPrinted> buildFilterRules() {
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
final Predicate<CardPrinted> 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));
}
/**

View File

@@ -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;
/**
* <p>
@@ -78,7 +79,8 @@ public class BoosterDraftAI {
CardPrinted pickedCard = null;
Iterable<CardPrinted> aiPlayablesView = Iterables.filter(chooseFrom, CardRules.Predicates.IS_KEPT_IN_AI_DECKS.bridge(CardPrinted.FN_GET_RULES));
Predicate<CardPrinted> pred = Predicates.compose(CardRules.Predicates.IS_KEPT_IN_AI_DECKS, CardPrinted.FN_GET_RULES);
Iterable<CardPrinted> aiPlayablesView = Iterables.filter(chooseFrom, pred );
List<CardPrinted> 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<CardRules> hasColor = Predicate.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors),
Predicate<CardRules> hasColor = Predicates.or(new GenerateDeckUtil.ContainsAllColorsFrom(colors),
GenerateDeckUtil.COLORLESS_CARDS);
Iterable<CardPrinted> colorList = Iterables.filter(aiPlayables, hasColor.bridge(CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> colorList = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES));
// Sort playable, on-color cards by rank
TreeMap<Double, CardPrinted> rankedPlayableCards = rankCards(colorList);

View File

@@ -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<CardPrinted> playables = Iterables.filter(availableList, CardRules.Predicates.IS_KEPT_IN_AI_DECKS.bridge(CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> 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<CardPrinted> onColorWalkers = Iterables.filter(colorList, CardRules.Predicates.Presets.IS_PLANESWALKER.bridge(CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> onColorWalkers = Iterables.filter(colorList, Predicates.compose(CardRules.Predicates.Presets.IS_PLANESWALKER, CardPrinted.FN_GET_RULES));
List<CardPrinted> 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<CardPrinted> others = Iterables.filter(aiPlayables, CardRules.Predicates.Presets.IS_NON_LAND.bridge(CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> others = Iterables.filter(aiPlayables, Predicates.compose(CardRules.Predicates.Presets.IS_NON_LAND, CardPrinted.FN_GET_RULES));
List<Pair<Double, CardPrinted>> ranked = rankCards(others);
for (Pair<Double, CardPrinted> 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<CardPrinted> onColor = Iterables.filter(aiPlayables, hasColor.bridge(CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> onColor = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES));
List<CardPrinted> 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<CardPrinted> filter = CardRules.Predicates.Presets.IS_CREATURE.bridge(CardPrinted.FN_GET_RULES);
Predicate<CardPrinted> 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) {

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**
* <p>
@@ -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<Card>() {
@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);

View File

@@ -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;
/**
* <p>

View File

@@ -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;
/**

View File

@@ -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;
/**

View File

@@ -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;
/**
* <p>

View File

@@ -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()
/**

View File

@@ -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;
/**
* <p>
@@ -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:

View File

@@ -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;
/**

View File

@@ -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 <T extends InventoryItem> void setLabelTextSum(JLabel label, final ItemPoolView<T> deck, Predicate<CardRules> 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));
}

View File

@@ -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<CardPrinted>
*/
public static Predicate<CardPrinted> buildColorFilter() {
if (MAP_COLOR_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); }
if (MAP_COLOR_CHECKBOXES.isEmpty()) { return Predicates.alwaysTrue(); }
final List<Predicate<CardRules>> ors = new ArrayList<Predicate<CardRules>>();
JCheckBox chbTemp;
@@ -207,15 +209,13 @@ public class SFilterUtil {
chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.MULTICOLOR)).getCheckBox();
final Predicate<CardPrinted> 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<CardPrinted> preColors =
Predicate.bridge(Predicate.or(ors), CardPrinted.FN_GET_RULES);
final Predicate<CardPrinted> 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<CardPrinted> 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<CardPrinted>
*/
public static Predicate<CardPrinted> buildTypeFilter() {
if (MAP_TYPE_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); }
if (MAP_TYPE_CHECKBOXES.isEmpty()) { return Predicates.alwaysTrue(); }
final List<Predicate<CardRules>> ors = new ArrayList<Predicate<CardRules>>();
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<CardPrinted>
*/
public static Predicate<CardPrinted> buildTextFilter() {
Predicate<CardPrinted> filterAnd = Predicate.getTrue(CardPrinted.class);
Predicate<CardPrinted> filterNot = Predicate.getTrue(CardPrinted.class);
Predicate<CardPrinted> filterAnd = Predicates.alwaysTrue();
Predicate<CardPrinted> 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<Predicate<CardPrinted>> subands = new ArrayList<Predicate<CardPrinted>>();
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<Predicate<CardPrinted>> subnots = new ArrayList<Predicate<CardPrinted>>();
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<CardPrinted> buildIntervalFilter() {
final VFilters view = VFilters.SINGLETON_INSTANCE;
Predicate<CardPrinted> filter = Predicate.getTrue(CardPrinted.class);
Predicate<CardPrinted> 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<CardPrinted> 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<CardPrinted> prePowerTemp = Predicate.and(
Predicate.bridge(CardRules.Predicates.power(
final Predicate<CardPrinted> 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<CardPrinted> 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<CardPrinted> preToughnessTemp = Predicate.and(
Predicate.bridge(CardRules.Predicates.toughness(
final Predicate<CardPrinted> 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;
}

View File

@@ -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<CardPrinted> notBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).bridge(CardPrinted.FN_GET_RULES);
Predicate<CardPrinted> notBasicLand = Predicates.not(Predicates.compose(CardRules.Predicates.Presets.IS_BASIC_LAND,CardPrinted.FN_GET_RULES));
Iterable<CardPrinted> source = Iterables.filter(CardDb.instance().getAllUniqueCards(), notBasicLand);
randomDeck.getMain().addAllFlat(Aggregates.random(source, 15*5));

View File

@@ -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<CardPrinted> deck, Predicate<CardRules> 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) + "%)");
}

View File

@@ -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<T extends InventoryItem> {
}
if (useFilter && this.wantUnique) {
Predicate<Entry<T, Integer>> filterForPool = forge.util.closures.Predicate.bridge(this.filter, this.pool.getFnToPrinted());
Predicate<Entry<T, Integer>> filterForPool = Predicates.compose(this.filter, this.pool.getFnToPrinted());
Iterable<Entry<T, Integer>> cards = Aggregates.uniqueByLast(Iterables.filter(this.pool, filterForPool), this.pool.getFnToCardName());
this.model.addCards(cards);
} else if (useFilter) {
Predicate<Entry<T, Integer>> pred = forge.util.closures.Predicate.bridge(this.filter, this.pool.getFnToPrinted());
Predicate<Entry<T, Integer>> pred = Predicates.compose(this.filter, this.pool.getFnToPrinted());
this.model.addCards(Iterables.filter(this.pool, pred));
} else if (this.wantUnique) {
Iterable<Entry<T, Integer>> cards = Aggregates.uniqueByLast(this.pool, this.pool.getFnToCardName());

View File

@@ -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;
/**
* <p>

View File

@@ -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<CardPrinted>, InventoryItem
* Lambda to get rules for selects from list of printed cards.
*
*/
public static final Lambda1<CardRules, CardPrinted> FN_GET_RULES = new Lambda1<CardRules, CardPrinted>() {
public static final Function<CardPrinted, CardRules> FN_GET_RULES = new Function<CardPrinted, CardRules>() {
@Override
public CardRules apply(final CardPrinted from) {
return from.card;
@@ -337,7 +339,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
*/
public static Predicate<CardPrinted> printedInSets(final List<String> 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<CardPrinted>, InventoryItem
*/
public static Predicate<CardPrinted> 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<CardPrinted>, InventoryItem
return new PredicateNamesExcept(what);
}
private static class PredicateRarity extends Predicate<CardPrinted> {
private static class PredicateRarity implements Predicate<CardPrinted> {
private final CardRarity operand;
private final boolean shouldBeEqual;
@@ -406,7 +408,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
}
}
private static class PredicateSets extends Predicate<CardPrinted> {
private static class PredicateSets implements Predicate<CardPrinted> {
private final List<String> sets;
private final boolean mustContain;
@@ -475,7 +477,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
public static final Predicate<CardPrinted> IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare);
/** The Constant isRareOrMythic. */
public static final Predicate<CardPrinted> IS_RARE_OR_MYTHIC = Predicate.or(Presets.IS_RARE,
public static final Predicate<CardPrinted> 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<CardPrinted>, InventoryItem
/** The Constant exceptLands. */
public static final Predicate<CardPrinted> EXCEPT_LANDS = Predicates.rarity(false, CardRarity.BasicLand);
/** The Constant isTrue. */
public static final Predicate<CardPrinted> IS_TRUE = Predicate.getTrue(CardPrinted.class);
}
}
}

View File

@@ -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<InventoryItem> {
public static class PredicateBoosterPack implements Predicate<InventoryItem> {
@Override
public boolean apply(final InventoryItem card) {
@@ -73,7 +76,7 @@ public abstract class ItemPredicate {
*
* @return the predicate
*/
public static class PredicateFatPack extends Predicate<InventoryItem> {
public static class PredicateFatPack implements Predicate<InventoryItem> {
@Override
public boolean apply(final InventoryItem card) {
@@ -86,7 +89,7 @@ public abstract class ItemPredicate {
*
* @return the predicate
*/
public static class PredicateTournamentPack extends Predicate<InventoryItem> {
public static class PredicateTournamentPack implements Predicate<InventoryItem> {
@Override
public boolean apply(final InventoryItem card) {
@@ -99,7 +102,7 @@ public abstract class ItemPredicate {
*
* @return the predicate
*/
public static class PredicateStarterDeck extends Predicate<InventoryItem> {
public static class PredicateStarterDeck implements Predicate<InventoryItem> {
@Override
public boolean apply(final InventoryItem card) {
@@ -112,7 +115,7 @@ public abstract class ItemPredicate {
*
* @return the predicate
*/
public static class PredicatePrebuiltDeck extends Predicate<InventoryItem> {
public static class PredicatePrebuiltDeck implements Predicate<InventoryItem> {
@Override
public boolean apply(final InventoryItem card) {
@@ -135,7 +138,8 @@ public abstract class ItemPredicate {
public static final Predicate<InventoryItem> IS_TOURNAMENT_PACK = tournamentPack();
/** The Item IsPack. */
public static final Predicate<InventoryItem> IS_PACK = Predicate.or(Predicate.or(IS_BOOSTER_PACK, IS_FAT_PACK), IS_TOURNAMENT_PACK);
@SuppressWarnings("unchecked")
public static final Predicate<InventoryItem> IS_PACK = Predicates.or(IS_BOOSTER_PACK, IS_FAT_PACK, IS_TOURNAMENT_PACK);
/** The Item IsStarterDeck. */
public static final Predicate<InventoryItem> IS_STARTER_DECK = starterDeck();
@@ -144,6 +148,6 @@ public abstract class ItemPredicate {
public static final Predicate<InventoryItem> IS_PREBUILT_DECK = prebuiltDeck();
/** The Item IsDeck. */
public static final Predicate<InventoryItem> IS_DECK = Predicate.or(IS_STARTER_DECK, IS_PREBUILT_DECK);
public static final Predicate<InventoryItem> IS_DECK = Predicates.or(IS_STARTER_DECK, IS_PREBUILT_DECK);
}
}

View File

@@ -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<CardPrinted> getRandomBasicLands(final String setCode, final int count) {
Predicate<CardPrinted> cardsRule = Predicate.and(
Predicate<CardPrinted> 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);
}

View File

@@ -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<CardPrinted> 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<CardPrinted> filterMythics = Predicate.and(filter,
final Predicate<CardPrinted> 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<CardRules> color2 = allowedColors.get(iAttempt % size);
if (color2 != null) {
card = Aggregates.random(Iterables.filter(source, Predicate.and(filter, color2, CardPrinted.FN_GET_RULES)));
Predicate<CardPrinted> 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<CardRules> col = Predicate.getTrue(CardRules.class);
Predicate<CardRules> 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<CardPrinted> colorPred = Predicates.compose(col, CardPrinted.FN_GET_RULES);
return new UnOpenedProduct(openWay, new BoosterGenerator(Predicates.and(rar, colorPred))); // qty))
}
}

View File

@@ -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;
}

View File

@@ -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<CardPrinted> newCards = new ArrayList<CardPrinted>();
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<CardEdition> filterExt = CardEdition.Predicates.isLegalInFormat(this.formats.getExtended());
/** The filter t2booster. */
private final Predicate<CardEdition> filterT2booster = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
private final Predicate<CardEdition> filterT2booster = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
CardEdition.Predicates.isLegalInFormat(this.formats.getStandard()));
/** The filter ext but t2. */
private final Predicate<CardEdition> filterExtButT2 = Predicate.and(
private final Predicate<CardEdition> 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<CardEdition> filterNotExt = Predicate.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
Predicate.not(this.filterExt));
private final Predicate<CardEdition> filterNotExt = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
Predicates.not(this.filterExt));
/**
* Generate boosters in shop.

View File

@@ -1,6 +1,6 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
* 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
@@ -15,22 +15,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.util.closures;
package forge.util;
/**
* The Interface Lambda.
* Possible operators for comparables.
*
* @author Max
*
* @param <R>
* the generic type
*/
public interface Lambda<R> {
public enum ComparableOp {
/**
* Apply.
*
* @param args
* the args
* @return the r
*/
R apply(Object[] args);
EQUALS,
NOT_EQUALS,
GREATER_THAN,
LESS_THAN,
GT_OR_EQUAL,
LT_OR_EQUAL
}

View File

@@ -15,17 +15,19 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 <T>
* the generic type
*/
public abstract class PredicateString<T> extends Predicate<T> {
public abstract class PredicateString<T> implements Predicate<T> {
/** Possible operators for string operands. */
public enum StringOp {
/** The CONTAINS. */

View File

@@ -17,13 +17,12 @@
*/
package forge.util.closures;
/**
* The Class Lambda1.
*
* @param <R> the generic type
*/
public abstract class Lambda0<R> implements Lambda<R> {
public abstract class Lambda0<R> {
/**
* Apply.
@@ -31,25 +30,4 @@ public abstract class Lambda0<R> implements Lambda<R> {
* @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();
}
}

View File

@@ -28,7 +28,7 @@ import com.google.common.base.Function;
* @param <A1>
* the generic type
*/
public abstract class Lambda1<R, A1> implements Lambda<R>, Function<A1, R> {
public abstract class Lambda1<R, A1> implements Function<A1, R> {
/**
* Apply.
@@ -38,25 +38,4 @@ public abstract class Lambda1<R, A1> implements Lambda<R>, Function<A1, R> {
* @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]);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.util.closures;
import com.google.common.base.Function;
/**
* Predicate class allows to select items or type <U>, which are or contain an
* object of type <T>, matching to some criteria set by predicate. No need to
* write that simple operation by hand.
*
* Implements com.google.common.base.Predicates, so you may use this in Guava collection management routines.
*
* @param <T>
* - class to check condition against
* @author Max
*/
public abstract class Predicate<T> implements com.google.common.base.Predicate<T>{
/**
* 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 <U>
* the generic type
* @param <T>
* the generic type
* @param predicate
* the predicate
* @param fnBridge
* the fn bridge
* @return the predicate
*/
public static final <U, T> Predicate<U> bridge(final com.google.common.base.Predicate<T> predicate, final Function<U, T> fnBridge) {
return new Bridge<T, U>(predicate, fnBridge);
}
public final <U> Predicate<U> bridge(final Function<U, T> fnBridge) {
return new Bridge<T, U>(this, fnBridge);
}
/**
* Compose.
*
* @param <T>
* the generic type
* @param operand1
* the operand1
* @param operator
* the operator
* @param operand2
* the operand2
* @return the predicate
*/
public static <T> Predicate<T> compose(final Predicate<T> operand1, final PredicatesOp operator,
final Predicate<T> operand2) {
return new Node<T>(operand1, operator, operand2);
}
// Predefined operators: and, or
/**
* And.
*
* @param <T>
* the generic type
* @param operand1
* the operand1
* @param operand2
* the operand2
* @return the predicate
*/
public static <T> Predicate<T> and(final Predicate<T> operand1, final Predicate<T> operand2) {
if (operand1.is1()) {
return operand2;
}
if ((operand2 == null) || operand2.is1()) {
return operand1;
}
return new NodeAnd<T>(operand1, operand2);
}
/**
* And.
*
* @param <T>
* the generic type
* @param operand
* the operand
* @return the predicate
*/
public static <T> Predicate<T> and(final Iterable<Predicate<T>> operand) {
return new MultiNodeAnd<T>(operand);
}
/**
* And.
*
* @param <T>
* the generic type
* @param <U>
* the generic type
* @param operand1
* the operand1
* @param operand2
* the operand2
* @param bridge
* the bridge
* @return the predicate
*/
public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2,
final Lambda1<U, T> fnBridge) {
return new NodeAnd<T>(operand1, operand2.bridge(fnBridge));
}
/**
* Or.
*
* @param <T>
* the generic type
* @param operand1
* the operand1
* @param operand2
* the operand2
* @return the predicate
*/
public static <T> Predicate<T> or(final Predicate<T> operand1, final Predicate<T> operand2) {
return new NodeOr<T>(operand1, operand2);
}
/**
* Or.
*
* @param <T>
* the generic type
* @param operand
* the operand
* @return the predicate
*/
public static <T> Predicate<T> or(final Iterable<Predicate<T>> operand) {
return new MultiNodeOr<T>(operand);
}
/**
* Or.
*
* @param <T>
* the generic type
* @param <U>
* the generic type
* @param operand1
* the operand1
* @param operand2
* the operand2
* @param bridge
* the bridge
* @return the predicate
*/
public static <T, U> Predicate<T> or(final Predicate<T> operand1, final Predicate<U> operand2,
final Lambda1<U, T> bridge) {
return new NodeOrBridged<T, U>(operand1, operand2, bridge);
}
/**
* Not.
*
* @param <T>
* the generic type
* @param operand1
* the operand1
* @return the predicate
*/
public static <T> Predicate<T> not(final Predicate<T> operand1) {
return new Not<T>(operand1);
}
/**
* Gets the true.
*
* @param <T>
* the generic type
* @param cls
* the cls
* @return the true
*/
public static <T> Predicate<T> getTrue(final Class<T> cls) {
return new LeafConstant<T>(true);
}
/**
* Gets the false.
*
* @param <T>
* the generic type
* @param cls
* the cls
* @return the false
*/
public static <T> Predicate<T> getFalse(final Class<T> cls) {
return new LeafConstant<T>(false);
}
}
// Concrete implementations
// unary operators
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
*/
final class Not<T> extends Predicate<T> {
/**
*
*/
private final Predicate<T> filter;
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand Predicate<T>
*/
public Not(final Predicate<T> operand) {
this.filter = operand;
}
@Override
public boolean apply(final T card) {
return !this.filter.apply(card);
}
}
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
* @param <U>
*/
final class Bridge<T, U> extends Predicate<U> {
/**
*
*/
private final com.google.common.base.Predicate<T> filter;
/**
*
*/
private final Function<U, T> fnBridge;
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand Predicate<T>
* @param fnTfromU Lambda1<T, U>
*/
public Bridge(final com.google.common.base.Predicate<T> operand, final Function<U, T> 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 <T>
*/
/* PERFORMANCE CRITICAL - DO NOT GENERATE GETTERS HERE*/
class Node<T> extends Predicate<T> {
/* PERFORMANCE CRITICAL - DO NOT GENERATE GETTERS HERE*/
private final PredicatesOp operator;
protected final Predicate<T> filter1;
protected final Predicate<T> filter2;
/* PERFORMANCE CRITICAL - DO NOT GENERATE GETTERS HERE*/
/**
*
* Node.
*
* @param operand1 Predicate<T>
* @param op PredicatesOp
* @param operand2 Predicate<T>
*/
public Node(final Predicate<T> operand1, final PredicatesOp op, final Predicate<T> 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 <T>
*/
final class NodeOr<T> extends Node<T> {
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand1 Predicate<T>
* @param operand2 Predicate<T>
*/
public NodeOr(final Predicate<T> operand1, final Predicate<T> 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 <T>
*/
final class NodeAnd<T> extends Node<T> {
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand1 Predicate<T>
* @param operand2 Predicate<T>
*/
public NodeAnd(final Predicate<T> operand1, final Predicate<T> 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 <T>
* @param <U>
*/
final class NodeOrBridged<T, U> extends Predicate<T> {
private final Predicate<T> filter1;
private final Predicate<U> filter2;
private final Lambda1<U, T> bridge;
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand1 Predicate
* @param operand2 Predicate
* @param accessor Lambda
*/
public NodeOrBridged(final Predicate<T> operand1, final Predicate<U> operand2, final Lambda1<U, T> 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 <T>
* @param <U>
*/
final class NodeAndBridged<T, U> extends Predicate<T> {
private final Predicate<T> filter1;
private final Predicate<U> filter2;
private final Lambda1<U, T> bridge;
/**
*
* TODO: Write javadoc for Constructor.
*
* @param operand1 Predicate
* @param operand2 Predicate
* @param accessor Lambda
*/
public NodeAndBridged(final Predicate<T> operand1, final Predicate<U> operand2, final Lambda1<U, T> 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 <T>
*/
abstract class MultiNode<T> extends Predicate<T> {
/**
*
*/
private final Iterable<Predicate<T>> operands;
/**
*
* TODO: Write javadoc for Constructor.
*
* @param filters Iterable<Predicate<T>>
*/
public MultiNode(final Iterable<Predicate<T>> filters) {
this.operands = filters;
}
/**
* @return the operands
*/
public Iterable<Predicate<T>> getOperands() {
return operands;
}
}
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
*/
final class MultiNodeAnd<T> extends MultiNode<T> {
/**
*
* TODO: Write javadoc for Constructor.
*
* @param filters Iterable<Predicate<T>>
*/
public MultiNodeAnd(final Iterable<Predicate<T>> filters) {
super(filters);
}
@Override
public boolean apply(final T subject) {
for (final Predicate<T> p : this.getOperands()) {
if (!p.apply(subject)) {
return false;
}
}
return true;
}
}
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
*/
final class MultiNodeOr<T> extends MultiNode<T> {
/**
*
* TODO: Write javadoc for Constructor.
*
* @param filters Iterable<Predicate<T>>
*/
public MultiNodeOr(final Iterable<Predicate<T>> filters) {
super(filters);
}
@Override
public boolean apply(final T subject) {
for (final Predicate<T> p : this.getOperands()) {
if (p.apply(subject)) {
return true;
}
}
return false;
}
}
/**
*
* TODO: Write javadoc for this type.
*
* @param <T>
*/
class LeafConstant<T> extends Predicate<T> {
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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.util.closures;
/**
* Special predicate class to perform integer operations.
*
* @param <T>
* the generic type
*/
public abstract class PredicateInteger<T> extends Predicate<T> {
/**
* 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;
}
}