mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Removal of functions from forge.util.closure.Predicate in favour of Guava routines
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -12570,6 +12570,7 @@ src/main/java/forge/quest/io/QuestDataIO.java svneol=native#text/plain
|
||||
src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain
|
||||
src/main/java/forge/quest/io/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/quest/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/util/Aggregates.java -text
|
||||
src/main/java/forge/util/Base64Coder.java svneol=native#text/plain
|
||||
src/main/java/forge/util/BinaryUtil.java -text
|
||||
src/main/java/forge/util/CopyFiles.java svneol=native#text/plain
|
||||
|
||||
@@ -19,7 +19,6 @@ package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@@ -77,11 +76,11 @@ public class CardList extends ArrayList<Card> {
|
||||
* criteria; may be empty, but never null.
|
||||
*/
|
||||
public final CardList filter(final Predicate<Card> filt) {
|
||||
return new CardList(filt.select(this));
|
||||
return new CardList(Iterables.filter(this, filt));
|
||||
}
|
||||
|
||||
public final boolean containsName(final String name) {
|
||||
return CardPredicates.nameEquals(name).any(this);
|
||||
return Iterables.any(this, CardPredicates.nameEquals(name));
|
||||
}
|
||||
|
||||
public final CardList getController(final Player player) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
/**
|
||||
@@ -237,7 +238,7 @@ public class CardListUtil {
|
||||
* @return a int.
|
||||
*/
|
||||
public static int sumCMC(final CardList c) {
|
||||
return CardPredicates.Presets.All.sum(c, CardPredicates.Accessors.fnGetCmc);
|
||||
return Aggregates.sum(c, CardPredicates.Accessors.fnGetCmc);
|
||||
} // sumCMC
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package forge;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.phase.CombatUtil;
|
||||
import forge.game.player.Player;
|
||||
@@ -73,7 +75,7 @@ public final class CardPredicates {
|
||||
return new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
return PredicateString.contains(keyword).any(c.getKeyword());
|
||||
return Iterables.any(c.getKeyword(), PredicateString.contains(keyword));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.card.CardCharacteristics;
|
||||
import forge.card.CardManaCost;
|
||||
import forge.card.EditionInfo;
|
||||
@@ -462,7 +464,7 @@ public final class CardUtil {
|
||||
return subject.getCode().equals(set);
|
||||
}
|
||||
};
|
||||
final EditionInfo neededSet = findSetInfo.first(card.getSets());
|
||||
final EditionInfo neededSet = Iterables.find(card.getSets(), findSetInfo);
|
||||
final int cntPictures = neededSet == null ? 1 : neededSet.getPicCount();
|
||||
return CardUtil
|
||||
.buildFilename(card.getName(), card.getCurSetCode(), card.getRandomPicture(), cntPictures, token);
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.Map.Entry;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
@@ -154,7 +156,7 @@ public class NameChanger {
|
||||
*/
|
||||
public final CardList changeCardsIfNeeded(CardList list) {
|
||||
if (this.shouldChangeCardName()) {
|
||||
list = new CardList(fnTransformCard.applyToIterable(list));
|
||||
list = new CardList( Lists.transform(list, fnTransformCard) );
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
@@ -120,7 +122,7 @@ public class BoosterGenerator {
|
||||
public BoosterGenerator(Predicate<CardPrinted> filter) {
|
||||
this();
|
||||
|
||||
for (final CardPrinted c : filter.select(CardDb.instance().getAllCards())) {
|
||||
for (final CardPrinted c : Iterables.filter(CardDb.instance().getAllCards(), filter)) {
|
||||
this.addToRarity(c);
|
||||
// System.out.println(c);
|
||||
}
|
||||
|
||||
@@ -110,14 +110,6 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fn1. */
|
||||
public static final Lambda1<CardEdition, CardEdition> FN1 = new Lambda1<CardEdition, CardEdition>() {
|
||||
@Override
|
||||
public CardEdition apply(final CardEdition arg1) {
|
||||
return arg1;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
@@ -637,6 +637,10 @@ public final class CardRules {
|
||||
return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
|
||||
}
|
||||
|
||||
public static Predicate<CardRules> isMonoColor(final byte thatColor) {
|
||||
return new LeafColor(LeafColor.ColorOperator.Equals, thatColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for cnt colors.
|
||||
*
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.AllZoneUtil;
|
||||
import forge.Card;
|
||||
@@ -495,7 +497,7 @@ public final class AbilityFactoryChangeZone {
|
||||
if (params.containsKey("Ninjutsu")) {
|
||||
if (source.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
|
||||
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
if (CardPredicates.nameEquals(source.getName()).any(list)) {
|
||||
if (Iterables.any(list, CardPredicates.nameEquals(source.getName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.List;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.AllZoneUtil;
|
||||
import forge.Card;
|
||||
@@ -73,8 +75,7 @@ public class CardFactoryCreatures {
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
return Predicate.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem")).any(list);
|
||||
|
||||
return Iterables.any(list, Predicate.or(CardPredicates.nameEquals("Glorious Anthem"), CardPredicates.nameEquals("Gaea's Anthem")));
|
||||
}
|
||||
};
|
||||
// Do not remove SpellAbilities created by AbilityFactory or
|
||||
|
||||
@@ -29,16 +29,13 @@ import forge.Counters;
|
||||
import forge.GameActionUtil;
|
||||
import forge.Singletons;
|
||||
import forge.card.cost.Cost;
|
||||
import forge.card.spellability.Ability;
|
||||
import forge.card.spellability.AbilityActivated;
|
||||
import forge.card.spellability.AbilityMana;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.control.input.Input;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
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;
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.AllZoneUtil;
|
||||
@@ -72,6 +73,7 @@ import forge.game.zone.PlayerZone;
|
||||
import forge.game.zone.ZoneType;
|
||||
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;
|
||||
@@ -2478,7 +2480,7 @@ public class CardFactoryUtil {
|
||||
list.add(AllZoneUtil.getCardState((Card) o));
|
||||
}
|
||||
}
|
||||
return CardPredicates.Presets.hasSecondStrike.sum(list, CardPredicates.Accessors.fnGetAttack);
|
||||
return Aggregates.sum(Iterables.filter(list, CardPredicates.Presets.hasSecondStrike), CardPredicates.Accessors.fnGetAttack);
|
||||
}
|
||||
|
||||
if (l[0].contains("RememberedSize")) {
|
||||
|
||||
@@ -19,6 +19,8 @@ package forge.card.spellability;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.AllZoneUtil;
|
||||
import forge.Card;
|
||||
@@ -347,7 +349,7 @@ public class SpellPermanent extends Spell {
|
||||
// check on legendary
|
||||
if (card.isType("Legendary") && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
|
||||
final CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
if (CardPredicates.nameEquals(card.getName()).any(list)) {
|
||||
if (Iterables.any(list, CardPredicates.nameEquals(card.getName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardColor;
|
||||
@@ -34,6 +36,7 @@ import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
@@ -155,10 +158,11 @@ public abstract class GenerateColoredDeckBase {
|
||||
addSome(diff, tDeck.toFlatList());
|
||||
} else if (actualSize > targetSize) {
|
||||
|
||||
Predicate<CardRules> exceptBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND);
|
||||
Predicate<CardPrinted> exceptBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).brigde(CardPrinted.FN_GET_RULES);
|
||||
|
||||
for (int i = 0; i < 3 && actualSize > targetSize; i++) {
|
||||
List<CardPrinted> toRemove = exceptBasicLand.random(tDeck.toFlatList(), CardPrinted.FN_GET_RULES, actualSize - targetSize);
|
||||
Iterable<CardPrinted> matchingCards = Iterables.filter(tDeck.toFlatList(), exceptBasicLand);
|
||||
List<CardPrinted> toRemove = Aggregates.random(matchingCards, actualSize - targetSize);
|
||||
tDeck.removeAllFlat(toRemove);
|
||||
|
||||
for (CardPrinted c : toRemove) {
|
||||
@@ -173,7 +177,8 @@ public abstract class GenerateColoredDeckBase {
|
||||
final List<CardPrinted> curved = new ArrayList<CardPrinted>();
|
||||
|
||||
for (int i = 0; i < cmcAmounts.length; i++) {
|
||||
curved.addAll(cmcLevels.get(i).random(source, CardPrinted.FN_GET_RULES, cmcAmounts[i]));
|
||||
Iterable<CardPrinted> matchingCards = Iterables.filter(source, cmcLevels.get(i).brigde(CardPrinted.FN_GET_RULES));
|
||||
curved.addAll( Aggregates.random(matchingCards, cmcAmounts[i]));
|
||||
}
|
||||
|
||||
for (CardPrinted c : curved) {
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Constant.Color;
|
||||
import forge.card.CardColor;
|
||||
@@ -46,11 +48,14 @@ public class SealedDeck extends LimitedDeck {
|
||||
System.out.println(cp.getName() + " " + cp.getCard().getManaCost().toString());
|
||||
}
|
||||
|
||||
int white = CardRules.Predicates.Presets.IS_WHITE.count(colorChooserList, CardPrinted.FN_GET_RULES);
|
||||
int blue = CardRules.Predicates.Presets.IS_BLUE.count(colorChooserList, CardPrinted.FN_GET_RULES);
|
||||
int black = CardRules.Predicates.Presets.IS_BLACK.count(colorChooserList, CardPrinted.FN_GET_RULES);
|
||||
int red = CardRules.Predicates.Presets.IS_RED.count(colorChooserList, CardPrinted.FN_GET_RULES);
|
||||
int green = CardRules.Predicates.Presets.IS_GREEN.count(colorChooserList, CardPrinted.FN_GET_RULES);
|
||||
Iterable<CardRules> rules = Iterables.transform(colorChooserList, CardPrinted.FN_GET_RULES);
|
||||
|
||||
int white = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_WHITE));
|
||||
int blue = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_BLUE));
|
||||
int black = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_BLACK));
|
||||
int red = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_RED));
|
||||
int green = Iterables.size(Iterables.filter(rules, CardRules.Predicates.Presets.IS_GREEN));
|
||||
|
||||
final int[] colorCounts = { white, blue, black, red, green };
|
||||
final String[] colors = Constant.Color.ONLY_COLORS;
|
||||
int[] countsCopy = Arrays.copyOf(colorCounts, 5);
|
||||
|
||||
@@ -19,6 +19,8 @@ package forge.game.phase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.AllZoneUtil;
|
||||
import forge.Card;
|
||||
@@ -2279,7 +2281,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
|
||||
public boolean apply(final Card c) {
|
||||
return c.isEnchantment() && c.hasKeyword("Enchant player")
|
||||
&& !source.getEnchantingPlayer().hasProtectionFrom(c)
|
||||
&& !CardPredicates.nameEquals(c.getName()).any(enchantmentsAttached);
|
||||
&& !Iterables.any(enchantmentsAttached, CardPredicates.nameEquals(c.getName()));
|
||||
}
|
||||
});
|
||||
final Player player = source.getController();
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang3.text.translate.AggregateTranslator;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.AllZoneUtil;
|
||||
import forge.Card;
|
||||
@@ -53,6 +55,7 @@ import forge.game.phase.CombatUtil;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
/**
|
||||
@@ -1332,7 +1335,7 @@ public class ComputerUtil {
|
||||
CardList lands = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
lands.addAll(hand);
|
||||
lands = lands.getType("Land");
|
||||
int maxCmcInHand = Predicate.getTrue(Card.class).max(hand, CardPredicates.Accessors.fnGetCmc);
|
||||
int maxCmcInHand = Aggregates.max(hand, CardPredicates.Accessors.fnGetCmc);
|
||||
for (final SpellAbility sa : spellAbilities) {
|
||||
if (sa.isCycling()) {
|
||||
if (lands.size() >= Math.max(maxCmcInHand, 6)) {
|
||||
@@ -2216,7 +2219,7 @@ public class ComputerUtil {
|
||||
final CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Land");
|
||||
final CardList landsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getType("Land");
|
||||
final CardList nonLandsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getNotType("Land");
|
||||
final int highestCMC = Math.max(6, Predicate.getTrue(Card.class).max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc));
|
||||
final int highestCMC = Math.max(6, Aggregates.max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc));
|
||||
final int discardCMC = discard.getCMC();
|
||||
if (discard.isLand()) {
|
||||
if (landsInPlay.size() >= highestCMC
|
||||
|
||||
@@ -31,7 +31,6 @@ import forge.card.spellability.Ability;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.staticability.StaticAbility;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
|
||||
import forge.card.CardRules;
|
||||
import forge.gui.deckeditor.views.ITableContainer;
|
||||
@@ -9,6 +13,8 @@ import forge.gui.deckeditor.views.VCurrentDeck;
|
||||
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,
|
||||
@@ -78,6 +84,11 @@ public final class SEditorUtil {
|
||||
return (int) Math.round((double) x0 / (double) y0 * 100);
|
||||
}
|
||||
|
||||
public static <T extends InventoryItem> void setLabelTextSum(JLabel label, final ItemPoolView<T> deck, Predicate<CardRules> predicate) {
|
||||
int sum = Aggregates.sum(Iterables.filter(deck, predicate.brigde(deck.getFnToCard())), deck.getFnToCount());
|
||||
label.setText(String.valueOf(sum));
|
||||
}
|
||||
|
||||
/**
|
||||
* setStats.
|
||||
*
|
||||
@@ -88,44 +99,19 @@ public final class SEditorUtil {
|
||||
public static <T extends InventoryItem> void setStats(final ItemPoolView<T> deck, final ITableContainer view) {
|
||||
view.getLblTotal().setText(String.valueOf(deck.countAll()));
|
||||
|
||||
view.getLblCreature().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_CREATURE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblLand().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_LAND.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblEnchantment().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_ENCHANTMENT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblArtifact().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_ARTIFACT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblInstant().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_INSTANT.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblSorcery().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_SORCERY.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblPlaneswalker().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_PLANESWALKER.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblColorless().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_COLORLESS.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblBlack().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_BLACK.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblBlue().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_BLUE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblGreen().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_GREEN.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblRed().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_RED.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
|
||||
view.getLblWhite().setText(String.valueOf(CardRules.Predicates.Presets
|
||||
.IS_WHITE.sum(deck, deck.getFnToCard(), deck.getFnToCount())));
|
||||
setLabelTextSum(view.getLblCreature(), deck, CardRules.Predicates.Presets.IS_CREATURE);
|
||||
setLabelTextSum(view.getLblLand(), deck, CardRules.Predicates.Presets.IS_LAND);
|
||||
setLabelTextSum(view.getLblEnchantment(), deck, CardRules.Predicates.Presets.IS_ENCHANTMENT);
|
||||
setLabelTextSum(view.getLblArtifact(), deck, CardRules.Predicates.Presets.IS_ARTIFACT);
|
||||
setLabelTextSum(view.getLblInstant(), deck, CardRules.Predicates.Presets.IS_INSTANT);
|
||||
setLabelTextSum(view.getLblSorcery(), deck, CardRules.Predicates.Presets.IS_SORCERY);
|
||||
setLabelTextSum(view.getLblPlaneswalker(), deck, CardRules.Predicates.Presets.IS_PLANESWALKER);
|
||||
setLabelTextSum(view.getLblColorless(), deck, CardRules.Predicates.Presets.IS_COLORLESS);
|
||||
setLabelTextSum(view.getLblBlack(), deck, CardRules.Predicates.Presets.IS_BLACK);
|
||||
setLabelTextSum(view.getLblBlue(), deck, CardRules.Predicates.Presets.IS_BLUE);
|
||||
setLabelTextSum(view.getLblGreen(), deck, CardRules.Predicates.Presets.IS_GREEN);
|
||||
setLabelTextSum(view.getLblRed(), deck, CardRules.Predicates.Presets.IS_RED);
|
||||
setLabelTextSum(view.getLblWhite(), deck, CardRules.Predicates.Presets.IS_WHITE);
|
||||
} // getStats()
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package forge.gui.deckeditor.controllers;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Command;
|
||||
import forge.card.CardRules;
|
||||
import forge.deck.Deck;
|
||||
@@ -16,6 +18,7 @@ import forge.gui.toolbox.FLabel;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
/**
|
||||
@@ -75,8 +78,10 @@ public enum CDeckgen implements ICDoc {
|
||||
|
||||
final Deck randomDeck = new Deck();
|
||||
|
||||
randomDeck.getMain().addAllFlat(Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND)
|
||||
.random(CardDb.instance().getAllUniqueCards(), CardPrinted.FN_GET_RULES, 15 * 5));
|
||||
Predicate<CardPrinted> notBasicLand = Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND).brigde(CardPrinted.FN_GET_RULES);
|
||||
Iterable<CardPrinted> source = Iterables.filter(CardDb.instance().getAllUniqueCards(), notBasicLand);
|
||||
randomDeck.getMain().addAllFlat(Aggregates.random(source, 15*5));
|
||||
|
||||
randomDeck.getMain().add("Plains");
|
||||
randomDeck.getMain().add("Island");
|
||||
randomDeck.getMain().add("Swamp");
|
||||
|
||||
@@ -7,6 +7,9 @@ import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
@@ -17,7 +20,6 @@ import forge.gui.toolbox.FLabel;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPredicate;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
/**
|
||||
* Controls the "filters" panel in the deck editor UI.
|
||||
@@ -160,11 +162,12 @@ public enum CFilters implements ICDoc {
|
||||
public <TItem extends InventoryItem, TModel extends DeckBase> void buildFilter() {
|
||||
// The main trick here is to apply a CardPrinted predicate
|
||||
// to the table. CardRules will lead to difficulties.
|
||||
final List<Predicate<CardPrinted>> lstFilters = new ArrayList<Predicate<CardPrinted>>();
|
||||
final List<Predicate<? super CardPrinted>> lstFilters = new ArrayList<Predicate<? super CardPrinted>>();
|
||||
|
||||
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
lstFilters.add(Predicates.instanceOf(CardPrinted.class));
|
||||
lstFilters.add(SFilterUtil.buildColorFilter());
|
||||
lstFilters.add(SFilterUtil.buildTypeFilter());
|
||||
lstFilters.add(SFilterUtil.buildSetAndFormatFilter());
|
||||
@@ -172,11 +175,10 @@ public enum CFilters implements ICDoc {
|
||||
lstFilters.add(SFilterUtil.buildIntervalFilter());
|
||||
|
||||
// Until this is filterable, always show packs and decks in the card shop.
|
||||
Predicate<InventoryItem> itemFilter = Predicate.instanceOf(
|
||||
Predicate.and(lstFilters), CardPrinted.class);
|
||||
com.google.common.base.Predicate<? super CardPrinted> itemFilter = Predicates.and(lstFilters);
|
||||
|
||||
itemFilter = Predicate.or(itemFilter, ItemPredicate.Presets.IS_PACK);
|
||||
itemFilter = Predicate.or(itemFilter, ItemPredicate.Presets.IS_DECK);
|
||||
itemFilter = Predicates.or(itemFilter, ItemPredicate.Presets.IS_PACK);
|
||||
itemFilter = Predicates.or(itemFilter, ItemPredicate.Presets.IS_DECK);
|
||||
|
||||
// Apply to table
|
||||
ed.getTableCatalog().setFilter((Predicate<TItem>) itemFilter);
|
||||
|
||||
@@ -2,10 +2,13 @@ package forge.gui.deckeditor.controllers;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Command;
|
||||
import forge.card.CardColor;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRules.Predicates;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
@@ -15,6 +18,7 @@ import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.closures.Predicate;
|
||||
|
||||
/**
|
||||
@@ -52,6 +56,12 @@ public enum CStatistics implements ICDoc {
|
||||
analyze();
|
||||
}
|
||||
|
||||
private void setLabelValue(JLabel label, ItemPoolView<CardPrinted> deck, Predicate<CardRules> predicate, int total) {
|
||||
int tmp = Aggregates.sum(Iterables.filter(deck, predicate.brigde(deck.getFnToCard())), deck.getFnToCount());
|
||||
label.setText( tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
}
|
||||
|
||||
//========== Other methods
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends InventoryItem, TModel extends DeckBase> void analyze() {
|
||||
@@ -69,84 +79,22 @@ public enum CStatistics implements ICDoc {
|
||||
// Hack-ish: avoid /0 cases, but still populate labels :)
|
||||
if (total == 0) { total = 1; }
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_MULTICOLOR
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblMulti().setText(String.valueOf(tmp));
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_CREATURE
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblCreature().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblCreature(), deck, CardRules.Predicates.Presets.IS_CREATURE, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblLand(), deck, CardRules.Predicates.Presets.IS_LAND, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblEnchantment(), deck, CardRules.Predicates.Presets.IS_ENCHANTMENT, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblArtifact(), deck, CardRules.Predicates.Presets.IS_ARTIFACT, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblInstant(), deck, CardRules.Predicates.Presets.IS_INSTANT, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblSorcery(), deck, CardRules.Predicates.Presets.IS_SORCERY, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker(), deck, CardRules.Predicates.Presets.IS_PLANESWALKER, total );
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_LAND
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblLand().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_ENCHANTMENT
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblEnchantment().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_ARTIFACT
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblArtifact().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_INSTANT
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblInstant().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_SORCERY
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblSorcery().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_PLANESWALKER
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = CardRules.Predicates.Presets.IS_COLORLESS
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblColorless().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = Predicate.and(
|
||||
Predicates.isColor(CardColor.BLACK),
|
||||
Predicates.hasCntColors((byte) 1))
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblBlack().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = Predicate.and(
|
||||
Predicates.isColor(CardColor.BLUE),
|
||||
Predicates.hasCntColors((byte) 1))
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblBlue().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = Predicate.and(
|
||||
Predicates.isColor(CardColor.GREEN),
|
||||
Predicates.hasCntColors((byte) 1))
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblGreen().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = Predicate.and(
|
||||
Predicates.isColor(CardColor.RED),
|
||||
Predicates.hasCntColors((byte) 1))
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblRed().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
|
||||
tmp = Predicate.and(
|
||||
Predicates.isColor(CardColor.WHITE),
|
||||
Predicates.hasCntColors((byte) 1))
|
||||
.sum(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||
VStatistics.SINGLETON_INSTANCE.getLblWhite().setText(
|
||||
tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)");
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblMulti(), deck, CardRules.Predicates.Presets.IS_MULTICOLOR, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblColorless(), deck, CardRules.Predicates.Presets.IS_COLORLESS, total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlack(), deck, CardRules.Predicates.isMonoColor(CardColor.BLACK), total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblBlue(), deck, CardRules.Predicates.isMonoColor(CardColor.BLUE), total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblGreen(), deck, CardRules.Predicates.isMonoColor(CardColor.GREEN), total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblRed(), deck, CardRules.Predicates.isMonoColor(CardColor.RED), total );
|
||||
setLabelValue( VStatistics.SINGLETON_INSTANCE.getLblWhite(), deck, CardRules.Predicates.isMonoColor(CardColor.WHITE), total );
|
||||
|
||||
int cmc0 = 0, cmc1 = 0, cmc2 = 0, cmc3 = 0, cmc4 = 0, cmc5 = 0, cmc6 = 0;
|
||||
int tmc = 0;
|
||||
|
||||
@@ -27,6 +27,8 @@ import javax.swing.JTable;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.card.CardColor;
|
||||
import forge.card.CardEdition;
|
||||
@@ -39,7 +41,6 @@ import forge.gui.deckeditor.controllers.ACEditorBase;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.InventoryItemFromSet;
|
||||
import forge.util.closures.Lambda1;
|
||||
|
||||
/**
|
||||
* A collection of methods pertaining to columns in card catalog and
|
||||
@@ -355,7 +356,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnQtyCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_QTY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_QTY_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getValue();
|
||||
@@ -363,7 +364,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnQtyGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_QTY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_QTY_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getValue();
|
||||
@@ -372,7 +373,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnNameCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_NAME_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_NAME_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getName();
|
||||
@@ -380,7 +381,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnNameGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_NAME_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_NAME_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
final String name = from.getKey().getName();
|
||||
@@ -390,7 +391,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnCostCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_COST_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_COST_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toManaCost(from.getKey());
|
||||
@@ -398,7 +399,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnCostGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COST_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_COST_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toManaCost(from.getKey());
|
||||
@@ -407,7 +408,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnColorCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_COLOR_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_COLOR_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toColor(from.getKey());
|
||||
@@ -415,7 +416,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnColorGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COLOR_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_COLOR_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toColor(from.getKey());
|
||||
@@ -424,7 +425,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnTypeCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TYPE_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_TYPE_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getType();
|
||||
@@ -432,7 +433,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnTypeGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TYPE_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_TYPE_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getType();
|
||||
@@ -441,7 +442,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnPowerCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_POWER_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_POWER_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toPower(from.getKey());
|
||||
@@ -449,7 +450,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnPowerGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_POWER_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_POWER_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toPower(from.getKey());
|
||||
@@ -458,7 +459,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnToughnessCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TOUGHNESS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_TOUGHNESS_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toToughness(from.getKey());
|
||||
@@ -466,7 +467,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnToughnessGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TOUGHNESS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_TOUGHNESS_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toToughness(from.getKey());
|
||||
@@ -475,7 +476,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnCMCCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_CMC_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_CMC_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toCMC(from.getKey());
|
||||
@@ -483,7 +484,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnCMCGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_CMC_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_CMC_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toCMC(from.getKey());
|
||||
@@ -492,7 +493,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnRarityCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_RARITY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_RARITY_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toRarity(from.getKey());
|
||||
@@ -500,7 +501,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnRarityGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_RARITY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_RARITY_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toRarity(from.getKey());
|
||||
@@ -509,7 +510,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnSetCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_SET_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_SET_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toSetCmp(from.getKey());
|
||||
@@ -517,7 +518,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnSetGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_SET_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_SET_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toSetStr(from.getKey());
|
||||
@@ -526,7 +527,7 @@ public final class SColumnUtil {
|
||||
|
||||
/** Lamda sort fnAiStatusCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_AI_STATUS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Comparable> FN_AI_STATUS_COMPARE = new Function<Entry<InventoryItem, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toAiCmp(from.getKey());
|
||||
@@ -534,7 +535,7 @@ public final class SColumnUtil {
|
||||
};
|
||||
|
||||
/** Lamda sort fnAiStatusGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_AI_STATUS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
private static final Function<Entry<InventoryItem, Integer>, Object> FN_AI_STATUS_GET = new Function<Entry<InventoryItem, Integer>, Object>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toAiStr(from.getKey());
|
||||
|
||||
@@ -21,8 +21,10 @@ import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.gui.deckeditor.tables.SColumnUtil.SortState;
|
||||
import forge.util.closures.Lambda1;
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
/**
|
||||
* A column object in a TableModel in the card editor.
|
||||
@@ -39,8 +41,8 @@ public class TableColumnInfo<T> extends TableColumn {
|
||||
private boolean show = true;
|
||||
private String enumval;
|
||||
|
||||
private Lambda1<Comparable, Entry<T, Integer>> fnSort;
|
||||
private Lambda1<Object, Entry<T, Integer>> fnDisplay;
|
||||
private Function<Entry<T, Integer>, Comparable> fnSort;
|
||||
private Function<Entry<T, Integer>, Object> fnDisplay;
|
||||
|
||||
/** */
|
||||
public TableColumnInfo() {
|
||||
@@ -108,7 +110,7 @@ public class TableColumnInfo<T> extends TableColumn {
|
||||
*
|
||||
* @return the fnSort
|
||||
*/
|
||||
public Lambda1<Comparable, Entry<T, Integer>> getFnSort() {
|
||||
public Function<Entry<T, Integer>, Comparable> getFnSort() {
|
||||
if (fnSort == null) {
|
||||
throw new NullPointerException("A sort function hasn't been set for "
|
||||
+ "Column " + TableColumnInfo.this.getIdentifier());
|
||||
@@ -121,7 +123,7 @@ public class TableColumnInfo<T> extends TableColumn {
|
||||
*
|
||||
* @return the fnDisplay
|
||||
*/
|
||||
public Lambda1<Object, Entry<T, Integer>> getFnDisplay() {
|
||||
public Function<Entry<T, Integer>, Object> getFnDisplay() {
|
||||
if (fnSort == null) {
|
||||
throw new NullPointerException("A display function hasn't been set for "
|
||||
+ "Column " + TableColumnInfo.this.getIdentifier());
|
||||
@@ -135,7 +137,7 @@ public class TableColumnInfo<T> extends TableColumn {
|
||||
* @param lambda0 the fnSort
|
||||
* @param lambda1 the fnDisplay
|
||||
*/
|
||||
public void setSortAndDisplayFunctions(final Lambda1<Comparable, Entry<T, Integer>> lambda0, final Lambda1<Object, Entry<T, Integer>> lambda1) {
|
||||
public void setSortAndDisplayFunctions(final Function<Entry<T, Integer>, Comparable> lambda0, final Function<Entry<T, Integer>, Object> lambda1) {
|
||||
this.fnSort = lambda0;
|
||||
this.fnDisplay = lambda1;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ package forge.gui.deckeditor.tables;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.item.CardPrinted;
|
||||
import forge.util.closures.Lambda1;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -38,7 +39,7 @@ import forge.util.closures.Lambda1;
|
||||
public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
|
||||
private final boolean ascending;
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Lambda1<Comparable, Entry<T, Integer>> field;
|
||||
private final Function<Entry<T, Integer>, Comparable> field;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -51,7 +52,7 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
|
||||
* a boolean.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public TableSorter(final Lambda1<Comparable, Entry<T, Integer>> field, final boolean inAscending) {
|
||||
public TableSorter(final Function<Entry<T, Integer>, Comparable> field, final boolean inAscending) {
|
||||
this.field = field;
|
||||
this.ascending = inAscending;
|
||||
}
|
||||
@@ -59,7 +60,7 @@ public class TableSorter<T> implements Comparator<Entry<T, Integer>> {
|
||||
/** The Constant byNameThenSet. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final TableSorter<CardPrinted> BY_NAME_THEN_SET = new TableSorter<CardPrinted>(
|
||||
new Lambda1<Comparable, Entry<CardPrinted, Integer>>() {
|
||||
new Function<Entry<CardPrinted, Integer>, Comparable>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<CardPrinted, Integer> from) {
|
||||
return from.getKey();
|
||||
|
||||
@@ -19,13 +19,16 @@ package forge.gui.deckeditor.tables;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.DefaultTableColumnModel;
|
||||
|
||||
import forge.card.CardRules;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.gui.deckeditor.SEditorUtil;
|
||||
import forge.gui.deckeditor.views.ITableContainer;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
@@ -33,7 +36,8 @@ import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.closures.Predicate;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
|
||||
/**
|
||||
* TableWithCards.
|
||||
@@ -207,7 +211,7 @@ public final class TableView<T extends InventoryItem> {
|
||||
}
|
||||
|
||||
private boolean isUnfiltered() {
|
||||
return (this.filter == null) || this.filter.is1();
|
||||
return this.filter == null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,13 +274,15 @@ public final class TableView<T extends InventoryItem> {
|
||||
}
|
||||
|
||||
if (useFilter && this.wantUnique) {
|
||||
this.model.addCards(this.filter.uniqueByLast(this.pool, this.pool.getFnToCardName(),
|
||||
this.pool.getFnToPrinted()));
|
||||
Predicate<Entry<T, Integer>> filterForPool = forge.util.closures.Predicate.brigde(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) {
|
||||
this.model.addCards(this.filter.select(this.pool, this.pool.getFnToPrinted()));
|
||||
Predicate<Entry<T, Integer>> pred = forge.util.closures.Predicate.brigde(this.filter, this.pool.getFnToPrinted());
|
||||
this.model.addCards(Iterables.filter(this.pool, pred));
|
||||
} else if (this.wantUnique) {
|
||||
this.model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(this.pool,
|
||||
this.pool.getFnToCardName(), this.pool.getFnToCard()));
|
||||
Iterable<Entry<T, Integer>> cards = Aggregates.uniqueByLast(this.pool, this.pool.getFnToCardName());
|
||||
this.model.addCards(cards);
|
||||
} else if (!useFilter && bForceFilter) {
|
||||
this.model.addCards(this.pool);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
@@ -280,7 +282,7 @@ public class CField implements ICDoc {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
final List<Card> src = this.getCardsAsIterable();
|
||||
final List<Card> choices = AllZone.getNameChanger().shouldChangeCardName() ? AllZone.getNameChanger().fnTransformCard.applyToIterable(src) : getCardsAsIterable();
|
||||
final List<Card> choices = AllZone.getNameChanger().shouldChangeCardName() ? Lists.transform(src, AllZone.getNameChanger().fnTransformCard) : getCardsAsIterable();
|
||||
|
||||
final ArrayList<Card> choices2 = new ArrayList<Card>();
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ import java.util.NoSuchElementException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardInSet;
|
||||
@@ -389,7 +392,7 @@ public final class CardDb {
|
||||
} else {
|
||||
// OK, plain name here
|
||||
final Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left);
|
||||
final List<CardPrinted> namedCards = predicate.select(this.allCardsFlat);
|
||||
final List<CardPrinted> namedCards = Lists.newArrayList(Iterables.filter(this.allCardsFlat, predicate));
|
||||
if (namedCards.isEmpty()) {
|
||||
throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name));
|
||||
}
|
||||
|
||||
@@ -19,9 +19,12 @@ package forge.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -168,9 +171,10 @@ public abstract class OpenablePack implements InventoryItemFromSet {
|
||||
* @return the random basic lands
|
||||
*/
|
||||
protected List<CardPrinted> getRandomBasicLands(final String setCode, final int count) {
|
||||
return Predicate.and(CardPrinted.Predicates.printedInSets(setCode),
|
||||
CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES).random(
|
||||
CardDb.instance().getAllCards(), count);
|
||||
Predicate<CardPrinted> cardsRule = Predicate.and(
|
||||
CardPrinted.Predicates.printedInSets(setCode),
|
||||
CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES);
|
||||
return Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), cardsRule), count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
|
||||
|
||||
import forge.card.BoosterGenerator;
|
||||
@@ -28,6 +30,7 @@ import forge.card.CardRules;
|
||||
import forge.card.UnOpenedProduct;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.closures.Lambda1;
|
||||
import forge.util.closures.Predicate;
|
||||
@@ -89,7 +92,7 @@ public final class BoosterUtils {
|
||||
int nRares = numRare, nMythics = 0;
|
||||
final Predicate<CardPrinted> filterMythics = Predicate.and(filter,
|
||||
CardPrinted.Predicates.Presets.IS_MYTHIC_RARE);
|
||||
final boolean haveMythics = filterMythics.any(cardpool);
|
||||
final boolean haveMythics = Iterables.any(cardpool, filterMythics);
|
||||
for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) {
|
||||
if (MyRandom.getRandom().nextInt(10) < 1) {
|
||||
// 10% chance of upgrading a Rare into a Mythic
|
||||
@@ -139,13 +142,13 @@ public final class BoosterUtils {
|
||||
if (size > 0) {
|
||||
final Predicate<CardRules> color2 = allowedColors.get(iAttempt % size);
|
||||
if (color2 != null) {
|
||||
card = Predicate.and(filter, color2, CardPrinted.FN_GET_RULES).random(source);
|
||||
card = Aggregates.random(Iterables.filter(source, Predicate.and(filter, color2, CardPrinted.FN_GET_RULES)));
|
||||
}
|
||||
}
|
||||
|
||||
if (card == null) {
|
||||
// We can't decide on a color, so just pick a card.
|
||||
card = filter.random(source);
|
||||
card = Aggregates.random(Iterables.filter(source, filter));
|
||||
}
|
||||
|
||||
if ((card != null) && !result.contains(card)) {
|
||||
@@ -194,7 +197,7 @@ public final class BoosterUtils {
|
||||
// constant!
|
||||
|
||||
while ((cntMade < cntNeeded) && (allowedMisses > 0)) {
|
||||
final CardPrinted card = filter.random(source);
|
||||
final CardPrinted card = Aggregates.random(Iterables.filter(source, filter));
|
||||
|
||||
if ((card != null) && !result.contains(card)) {
|
||||
result.add(card);
|
||||
|
||||
@@ -27,6 +27,7 @@ import forge.quest.bazaar.QuestItemType;
|
||||
import forge.quest.data.QuestAssets;
|
||||
import forge.quest.data.QuestPreferences;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.closures.Lambda1;
|
||||
import forge.util.closures.Predicate;
|
||||
@@ -35,6 +36,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* This is a helper class to execute operations on QuestData. It has been
|
||||
* created to decrease complexity of questData class
|
||||
@@ -139,7 +142,7 @@ public final class QuestUtilCards {
|
||||
* @return the card printed
|
||||
*/
|
||||
public CardPrinted addRandomRare() {
|
||||
final CardPrinted card = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards());
|
||||
final CardPrinted card = Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), QuestUtilCards.RARE_PREDICATE));
|
||||
this.addSingleCard(card);
|
||||
return card;
|
||||
}
|
||||
@@ -152,7 +155,7 @@ public final class QuestUtilCards {
|
||||
* @return the list
|
||||
*/
|
||||
public List<CardPrinted> addRandomRare(final int n) {
|
||||
final List<CardPrinted> newCards = QuestUtilCards.RARE_PREDICATE.random(CardDb.instance().getAllCards(), n);
|
||||
final List<CardPrinted> newCards = Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), QuestUtilCards.RARE_PREDICATE), n);
|
||||
this.addAllCards(newCards);
|
||||
return newCards;
|
||||
}
|
||||
@@ -343,8 +346,8 @@ public final class QuestUtilCards {
|
||||
final int rollD100 = MyRandom.getRandom().nextInt(100);
|
||||
final Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster
|
||||
: (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt);
|
||||
this.qa.getShopList().addAllFlat(
|
||||
filter.random(Singletons.getModel().getEditions(), 1, BoosterPack.FN_FROM_SET));
|
||||
Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getModel().getEditions(), filter);
|
||||
this.qa.getShopList().add(BoosterPack.FN_FROM_SET.apply(Aggregates.random(rightEditions)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,15 +358,13 @@ public final class QuestUtilCards {
|
||||
* the count
|
||||
*/
|
||||
public void generateTournamentsInShop(final int count) {
|
||||
Predicate<CardEdition> hasTournament = CardEdition.Predicates.HAS_TOURNAMENT_PACK;
|
||||
this.qa.getShopList().addAllFlat(hasTournament.random(Singletons.getModel().getEditions(),
|
||||
count,
|
||||
TournamentPack.FN_FROM_SET));
|
||||
Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getModel().getEditions(), CardEdition.Predicates.HAS_TOURNAMENT_PACK);
|
||||
this.qa.getShopList().addAllFlat(Aggregates.random(Iterables.transform(rightEditions, TournamentPack.FN_FROM_SET), count));
|
||||
}
|
||||
|
||||
public void generateFatPacksInShop(final int count) {
|
||||
Predicate<CardEdition> hasPack = CardEdition.Predicates.HAS_FAT_PACK;
|
||||
this.qa.getShopList().addAllFlat(hasPack.random(Singletons.getModel().getEditions(), count, FatPack.FN_FROM_SET));
|
||||
Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getModel().getEditions(), CardEdition.Predicates.HAS_FAT_PACK);
|
||||
this.qa.getShopList().addAllFlat(Aggregates.random(Iterables.transform(rightEditions, FatPack.FN_FROM_SET), count));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +380,7 @@ public final class QuestUtilCards {
|
||||
meetRequirements.add(deck);
|
||||
}
|
||||
}
|
||||
this.qa.getShopList().addAllFlat(Predicate.getTrue(PreconDeck.class).random(meetRequirements, count));
|
||||
this.qa.getShopList().addAllFlat(Aggregates.random(meetRequirements, count));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
107
src/main/java/forge/util/Aggregates.java
Normal file
107
src/main/java/forge/util/Aggregates.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package forge.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.util.closures.Lambda1;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class Aggregates {
|
||||
|
||||
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
|
||||
public final static <T> Integer max(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (final T c : source) {
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value > max ) {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public final static <T> int sum(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
int result = 0;
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
result += valueAccessor.apply(c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Random - algorithm adapted from Braid's GeneratorFunctions
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the t
|
||||
*/
|
||||
public final static <T> T random(final Iterable<T> source) {
|
||||
int n = 0;
|
||||
T candidate = null;
|
||||
for (final T item : source) {
|
||||
if ((Math.random() * ++n) < 1) {
|
||||
candidate = item;
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
// Get several random values
|
||||
// should improve to make 1 pass over source and track N candidates at once
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param count
|
||||
* the count
|
||||
* @return the list
|
||||
*/
|
||||
public final static <T> List<T> random(final Iterable<T> source, final int count) {
|
||||
final List<T> result = new ArrayList<T>();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
final T toAdd = Aggregates.random(source);
|
||||
if (toAdd == null) {
|
||||
break;
|
||||
}
|
||||
result.add(toAdd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique by last.
|
||||
*
|
||||
* @param <K>
|
||||
* the key type
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param fnUniqueKey
|
||||
* the fn unique key
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the iterable
|
||||
*/
|
||||
public static final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Lambda1<K, U> fnUniqueKey) { // this might be exotic
|
||||
final Map<K, U> uniques = new Hashtable<K, U>();
|
||||
for (final U c : source) {
|
||||
uniques.put(fnUniqueKey.apply(c), c);
|
||||
}
|
||||
return uniques.values();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,7 @@
|
||||
*/
|
||||
package forge.util.closures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
||||
/**
|
||||
@@ -29,7 +28,7 @@ import java.util.List;
|
||||
* @param <A1>
|
||||
* the generic type
|
||||
*/
|
||||
public abstract class Lambda1<R, A1> implements Lambda<R> {
|
||||
public abstract class Lambda1<R, A1> implements Lambda<R>, Function<A1, R> {
|
||||
|
||||
/**
|
||||
* Apply.
|
||||
@@ -40,14 +39,6 @@ public abstract class Lambda1<R, A1> implements Lambda<R> {
|
||||
*/
|
||||
public abstract R apply(A1 arg1);
|
||||
|
||||
public List<R> applyToIterable(Iterable<A1> arg1) {
|
||||
List<R> result = new ArrayList<R>();
|
||||
for(A1 a : arg1) {
|
||||
result.add(this.apply(a));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
package forge.util.closures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Predicate class allows to select items or type <U>, which are or contain an
|
||||
* object of type <T>, matching to some criteria set by predicate. No need to
|
||||
* write that simple operation by hand.
|
||||
*
|
||||
* PS: com.google.common.base.Predicates contains almost the same functionality,
|
||||
* except for they keep filtering, transformations aside from the predicate in
|
||||
* class Iterables
|
||||
* Implements com.google.common.base.Predicates, so you may use this in Guava collection management routines.
|
||||
*
|
||||
* @param <T>
|
||||
* - class to check condition against
|
||||
@@ -100,36 +96,6 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
|
||||
// list.add(transformer(U))
|
||||
|
||||
// selects are fun
|
||||
/**
|
||||
* Select.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the list
|
||||
*/
|
||||
public final List<T> select(final Iterable<T> source) {
|
||||
final ArrayList<T> result = new ArrayList<T>();
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
result.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the list
|
||||
*/
|
||||
public final <U> List<U> select(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
final ArrayList<U> result = new ArrayList<U>();
|
||||
if (source != null) {
|
||||
@@ -142,500 +108,8 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if any element meeting the criteria is present
|
||||
/**
|
||||
* Any.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return true, if successful
|
||||
*/
|
||||
public final boolean any(final Iterable<T> source) {
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Any.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return true, if successful
|
||||
*/
|
||||
public final <U> boolean any(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
if (source != null) {
|
||||
for (final U c : source) {
|
||||
if (this.apply(accessor.apply(c))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// select top 1
|
||||
/**
|
||||
* First.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the t
|
||||
*/
|
||||
public final T first(final Iterable<T> source) {
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* First.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the u
|
||||
*/
|
||||
public final <U> U first(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
if (source != null) {
|
||||
for (final U c : source) {
|
||||
if (this.apply(accessor.apply(c))) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* First.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param <V>
|
||||
* the value type
|
||||
* @param source
|
||||
* the source
|
||||
* @param cardAccessor
|
||||
* the card accessor
|
||||
* @param transformer
|
||||
* the transformer
|
||||
* @return the v
|
||||
*/
|
||||
public final <U, V> V first(final Iterable<U> source, final Lambda1<T, U> cardAccessor,
|
||||
final Lambda1<V, U> transformer) {
|
||||
if (source != null) {
|
||||
for (final U c : source) {
|
||||
if (this.apply(cardAccessor.apply(c))) {
|
||||
return transformer.apply(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// splits are even more fun
|
||||
/**
|
||||
* Split.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param trueList
|
||||
* the true list
|
||||
* @param falseList
|
||||
* the false list
|
||||
*/
|
||||
public final void split(final Iterable<T> source, final List<T> trueList, final List<T> falseList) {
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
trueList.add(c);
|
||||
} else {
|
||||
falseList.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Split.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @param trueList
|
||||
* the true list
|
||||
* @param falseList
|
||||
* the false list
|
||||
*/
|
||||
public final <U> void split(final Iterable<U> source, final Lambda1<T, U> accessor, final List<U> trueList,
|
||||
final List<U> falseList) {
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
for (final U c : source) {
|
||||
if (this.apply(accessor.apply(c))) {
|
||||
trueList.add(c);
|
||||
} else {
|
||||
falseList.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unique
|
||||
/**
|
||||
* Unique by last.
|
||||
*
|
||||
* @param <K>
|
||||
* the key type
|
||||
* @param source
|
||||
* the source
|
||||
* @param fnUniqueKey
|
||||
* the fn unique key
|
||||
* @return the iterable
|
||||
*/
|
||||
public final <K> Iterable<T> uniqueByLast(final Iterable<T> source, final Lambda1<K, T> fnUniqueKey) {
|
||||
final Map<K, T> uniques = new Hashtable<K, T>();
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
uniques.put(fnUniqueKey.apply(c), c);
|
||||
}
|
||||
}
|
||||
return uniques.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique by last.
|
||||
*
|
||||
* @param <K>
|
||||
* the key type
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param fnUniqueKey
|
||||
* the fn unique key
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the iterable
|
||||
*/
|
||||
public final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Lambda1<K, U> fnUniqueKey,
|
||||
final Lambda1<T, U> accessor) { // this might be exotic
|
||||
final Map<K, U> uniques = new Hashtable<K, U>();
|
||||
for (final U c : source) {
|
||||
if (this.apply(accessor.apply(c))) {
|
||||
uniques.put(fnUniqueKey.apply(c), c);
|
||||
}
|
||||
}
|
||||
return uniques.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique by first.
|
||||
*
|
||||
* @param <K>
|
||||
* the key type
|
||||
* @param source
|
||||
* the source
|
||||
* @param fnUniqueKey
|
||||
* the fn unique key
|
||||
* @return the iterable
|
||||
*/
|
||||
public final <K> Iterable<T> uniqueByFirst(final Iterable<T> source, final Lambda1<K, T> fnUniqueKey) {
|
||||
final Map<K, T> uniques = new Hashtable<K, T>();
|
||||
for (final T c : source) {
|
||||
final K key = fnUniqueKey.apply(c);
|
||||
if (this.apply(c) && !uniques.containsKey(key)) {
|
||||
uniques.put(fnUniqueKey.apply(c), c);
|
||||
}
|
||||
}
|
||||
return uniques.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique by first.
|
||||
*
|
||||
* @param <K>
|
||||
* the key type
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param fnUniqueKey
|
||||
* the fn unique key
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the iterable
|
||||
*/
|
||||
public final <K, U> Iterable<U> uniqueByFirst(final Iterable<U> source, final Lambda1<K, U> fnUniqueKey,
|
||||
final Lambda1<T, U> accessor) { // this might be exotic
|
||||
final Map<K, U> uniques = new Hashtable<K, U>();
|
||||
for (final U c : source) {
|
||||
final K key = fnUniqueKey.apply(c);
|
||||
if (this.apply(accessor.apply(c)) && !uniques.containsKey(key)) {
|
||||
uniques.put(fnUniqueKey.apply(c), c);
|
||||
}
|
||||
}
|
||||
return uniques.values();
|
||||
}
|
||||
|
||||
// Count
|
||||
/**
|
||||
* Count.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the int
|
||||
*/
|
||||
public final int count(final Iterable<T> source) {
|
||||
int result = 0;
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the int
|
||||
*/
|
||||
public final <U> int count(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
int result = 0;
|
||||
if (source != null) {
|
||||
for (final U c : source) {
|
||||
if (this.apply(accessor.apply(c))) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Aggregates?
|
||||
/**
|
||||
* Aggregate.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @param valueAccessor
|
||||
* the value accessor
|
||||
* @return the int
|
||||
*/
|
||||
public final <U> int sum(final Iterable<U> source, final Lambda1<T, U> accessor,
|
||||
final Lambda1<Integer, U> valueAccessor) {
|
||||
int result = 0;
|
||||
if (source != null) {
|
||||
for (final U c : source) {
|
||||
if (this.apply(accessor.apply(c))) {
|
||||
result += valueAccessor.apply(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public final int sum(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
int result = 0;
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
if (this.apply(c)) {
|
||||
result += valueAccessor.apply(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
|
||||
public final Integer max(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (final T c : source) {
|
||||
if (!this.apply(c)) { continue; }
|
||||
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value > max ) {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
// Returns the element matching predicate conditions with the maximum value of whatever valueAccessor returns.
|
||||
public final T maxItem(final Iterable<T> source, final Lambda1<Integer, T> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
|
||||
T result = null;
|
||||
int max = Integer.MIN_VALUE;
|
||||
|
||||
for (final T c : source) {
|
||||
if (!this.apply(c)) { continue; }
|
||||
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value > max ) {
|
||||
result = c;
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Random - algorithm adapted from Braid's GeneratorFunctions
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @return the t
|
||||
*/
|
||||
public final T random(final Iterable<T> source) {
|
||||
int n = 0;
|
||||
T candidate = null;
|
||||
for (final T item : source) {
|
||||
if (!this.apply(item)) {
|
||||
continue;
|
||||
}
|
||||
if ((Math.random() * ++n) < 1) {
|
||||
candidate = item;
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @return the u
|
||||
*/
|
||||
public final <U> U random(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
int n = 0;
|
||||
U candidate = null;
|
||||
for (final U item : source) {
|
||||
if (!this.apply(accessor.apply(item))) {
|
||||
continue;
|
||||
}
|
||||
if ((Math.random() * ++n) < 1) {
|
||||
candidate = item;
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
// Get several random values
|
||||
// should improve to make 1 pass over source and track N candidates at once
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param count
|
||||
* the count
|
||||
* @return the list
|
||||
*/
|
||||
public final List<T> random(final Iterable<T> source, final int count) {
|
||||
final List<T> result = new ArrayList<T>();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
final T toAdd = this.random(source);
|
||||
if (toAdd == null) {
|
||||
break;
|
||||
}
|
||||
result.add(toAdd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param source
|
||||
* the source
|
||||
* @param accessor
|
||||
* the accessor
|
||||
* @param count
|
||||
* the count
|
||||
* @return the list
|
||||
*/
|
||||
public final <U> List<U> random(final Iterable<U> source, final Lambda1<T, U> accessor, final int count) {
|
||||
final List<U> result = new ArrayList<U>();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
final U toAdd = this.random(source, accessor);
|
||||
if (toAdd == null) {
|
||||
break;
|
||||
}
|
||||
result.add(toAdd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random.
|
||||
*
|
||||
* @param <V>
|
||||
* the value type
|
||||
* @param source
|
||||
* the source
|
||||
* @param count
|
||||
* the count
|
||||
* @param transformer
|
||||
* the transformer
|
||||
* @return the list
|
||||
*/
|
||||
public final <V> List<V> random(final Iterable<T> source, final int count, final Lambda1<V, T> transformer) {
|
||||
final List<V> result = new ArrayList<V>();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
final T toAdd = this.random(source);
|
||||
if (toAdd == null) {
|
||||
break;
|
||||
}
|
||||
result.add(transformer.apply(toAdd));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Static builder methods - they choose concrete implementation by
|
||||
// themselves
|
||||
@@ -653,27 +127,16 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
|
||||
* the fn bridge
|
||||
* @return the predicate
|
||||
*/
|
||||
public static <U, T> Predicate<U> brigde(final Predicate<T> predicate, final Lambda1<T, U> fnBridge) {
|
||||
public static final <U, T> Predicate<U> brigde(final com.google.common.base.Predicate<T> predicate, final Function<U, T> fnBridge) {
|
||||
return new Bridge<T, U>(predicate, fnBridge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance of.
|
||||
*
|
||||
* @param <U>
|
||||
* the generic type
|
||||
* @param <T>
|
||||
* the generic type
|
||||
* @param predicate
|
||||
* the predicate
|
||||
* @param clsTarget
|
||||
* the cls target
|
||||
* @return the predicate
|
||||
*/
|
||||
public static <U, T> Predicate<U> instanceOf(final Predicate<T> predicate, final Class<T> clsTarget) {
|
||||
return new BridgeToInstance<T, U>(predicate, clsTarget);
|
||||
public final <U> Predicate<U> brigde(final Function<U, T> fnBridge) {
|
||||
return new Bridge<T, U>(this, fnBridge);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Compose.
|
||||
*
|
||||
@@ -743,8 +206,8 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
|
||||
* @return the predicate
|
||||
*/
|
||||
public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2,
|
||||
final Lambda1<U, T> bridge) {
|
||||
return new NodeAndBridged<T, U>(operand1, operand2, bridge);
|
||||
final Lambda1<U, T> fnBridge) {
|
||||
return new NodeAnd<T>(operand1, operand2.brigde(fnBridge));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,19 +271,6 @@ public abstract class Predicate<T> implements com.google.common.base.Predicate<T
|
||||
return new Not<T>(operand1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not.
|
||||
*
|
||||
* @param <T>
|
||||
* the generic type
|
||||
* @param operand
|
||||
* the operand
|
||||
* @return the predicate
|
||||
*/
|
||||
public static <T> Predicate<T> not(final Iterable<Predicate<T>> operand) {
|
||||
return new MultiNodeNot<T>(operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the true.
|
||||
*
|
||||
@@ -889,11 +339,11 @@ final class Bridge<T, U> extends Predicate<U> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final Predicate<T> filter;
|
||||
private final com.google.common.base.Predicate<T> filter;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final Lambda1<T, U> fnBridge;
|
||||
private final Function<U, T> fnBridge;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -902,7 +352,7 @@ final class Bridge<T, U> extends Predicate<U> {
|
||||
* @param operand Predicate<T>
|
||||
* @param fnTfromU Lambda1<T, U>
|
||||
*/
|
||||
public Bridge(final Predicate<T> operand, final Lambda1<T, U> fnTfromU) {
|
||||
public Bridge(final com.google.common.base.Predicate<T> operand, final Function<U, T> fnTfromU) {
|
||||
this.filter = operand;
|
||||
this.fnBridge = fnTfromU;
|
||||
}
|
||||
@@ -911,54 +361,8 @@ final class Bridge<T, U> extends Predicate<U> {
|
||||
public boolean apply(final U card) {
|
||||
return this.filter.apply(this.fnBridge.apply(card));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is1() {
|
||||
return this.filter.is1();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
* @param <T>
|
||||
* @param <U>
|
||||
*/
|
||||
final class BridgeToInstance<T, U> extends Predicate<U> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final Predicate<T> filter;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final Class<T> clsBridge;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for Constructor.
|
||||
*
|
||||
* @param operand Predicate
|
||||
* @param clsT Class
|
||||
*/
|
||||
public BridgeToInstance(final Predicate<T> operand, final Class<T> clsT) {
|
||||
this.filter = operand;
|
||||
this.clsBridge = clsT;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean apply(final U card) {
|
||||
return this.clsBridge.isInstance(card) && this.filter.apply((T) card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is1() {
|
||||
return this.filter.is1();
|
||||
}
|
||||
}
|
||||
|
||||
// binary operators
|
||||
/**
|
||||
@@ -1217,33 +621,6 @@ final class MultiNodeOr<T> extends MultiNode<T> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
final class MultiNodeNot<T> extends MultiNode<T> {
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param filters Iterable<Predicate<T>>
|
||||
*/
|
||||
public MultiNodeNot(final Iterable<Predicate<T>> filters) {
|
||||
super(filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(final T subject) {
|
||||
for (final Predicate<T> p : this.getOperands()) {
|
||||
if (!p.apply(subject)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user