mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Guava migration - Preliminary
This commit is contained in:
@@ -196,7 +196,7 @@ public final class CardRulesPredicates {
|
||||
try {
|
||||
return CardRulesPredicates.coreType(isEqual, Enum.valueOf(CardType.CoreType.class, what));
|
||||
} catch (final Exception e) {
|
||||
return com.google.common.base.Predicates.alwaysFalse();
|
||||
return x -> false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public final class CardRulesPredicates {
|
||||
try {
|
||||
return CardRulesPredicates.superType(isEqual, Enum.valueOf(CardType.Supertype.class, what));
|
||||
} catch (final Exception e) {
|
||||
return com.google.common.base.Predicates.alwaysFalse();
|
||||
return x -> false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,14 +123,12 @@ public class DeckHints {
|
||||
for (Pair<Type, String> pair : filters) {
|
||||
Type type = pair.getLeft();
|
||||
String param = pair.getRight();
|
||||
Iterable<PaperCard> cards = getCardsForFilter(cardList, type, param);
|
||||
if (cards != null) {
|
||||
// if a type is used more than once intersect respective matches
|
||||
if (ret.containsKey(type)) {
|
||||
Iterables.retainAll(cards, new FCollection<>(ret.get(type)));
|
||||
}
|
||||
ret.put(type, cards);
|
||||
List<PaperCard> cards = getCardsForFilter(cardList, type, param);
|
||||
// if a type is used more than once intersect respective matches
|
||||
if (ret.containsKey(type)) {
|
||||
cards.retainAll(new FCollection<>(ret.get(type)));
|
||||
}
|
||||
ret.put(type, cards);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -166,7 +164,7 @@ public class DeckHints {
|
||||
return pair;
|
||||
}
|
||||
|
||||
private Iterable<PaperCard> getCardsForFilter(Iterable<PaperCard> cardList, Type type, String param) {
|
||||
private List<PaperCard> getCardsForFilter(Iterable<PaperCard> cardList, Type type, String param) {
|
||||
List<PaperCard> cards = new ArrayList<>();
|
||||
|
||||
// this is case ABILITY, but other types can also use this when the implicit parsing would miss
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.esotericsoftware.minlog.Log;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.Iterables;
|
||||
import forge.GameCommand;
|
||||
import forge.StaticData;
|
||||
import forge.card.*;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Json;
|
||||
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.StaticData;
|
||||
import forge.adventure.data.ConfigData;
|
||||
import forge.adventure.data.GeneratedDeckData;
|
||||
@@ -804,15 +805,15 @@ public class CardUtil {
|
||||
}
|
||||
|
||||
public static PaperCard getCardByName(String cardName) {
|
||||
List<PaperCard> validCards = Arrays.asList(Iterables.toArray(Iterables.filter(getFullCardPool(Config.instance().getSettingData().useAllCardVariants),
|
||||
input -> input.getCardName().equals(cardName)), PaperCard.class));
|
||||
List<PaperCard> validCards = Lists.newArrayList(Iterables.filter(getFullCardPool(Config.instance().getSettingData().useAllCardVariants),
|
||||
input -> input.getCardName().equals(cardName)));
|
||||
|
||||
return validCards.get(Current.world().getRandom().nextInt(validCards.size()));
|
||||
}
|
||||
|
||||
public static PaperCard getCardByNameAndEdition(String cardName, String edition) {
|
||||
List<PaperCard> validCards = Arrays.asList(Iterables.toArray(Iterables.filter(getFullCardPool(Config.instance().getSettingData().useAllCardVariants),
|
||||
input -> input.getCardName().equals(cardName) && input.getEdition().equals(edition)), PaperCard.class));
|
||||
List<PaperCard> validCards = Lists.newArrayList(Iterables.filter(getFullCardPool(Config.instance().getSettingData().useAllCardVariants),
|
||||
input -> input.getCardName().equals(cardName) && input.getEdition().equals(edition)));
|
||||
|
||||
if (validCards.isEmpty()) {
|
||||
System.err.println("Unexpected behavior: tried to call getCardByNameAndEdition for card " + cardName + " from the edition " + edition + ", but didn't find it in the DB. A random existing instance will be returned.");
|
||||
|
||||
@@ -449,7 +449,7 @@ public final class BoosterUtils {
|
||||
*/
|
||||
public static Predicate<CardRules> parseRulesLimitation(final String input) {
|
||||
if (null == input || "random".equalsIgnoreCase(input)) {
|
||||
return Predicates.alwaysTrue();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (input.equalsIgnoreCase("black")) return CardRulesPredicates.Presets.IS_BLACK;
|
||||
@@ -491,8 +491,7 @@ public final class BoosterUtils {
|
||||
|
||||
if (temp.length > 2) {
|
||||
Predicate<CardRules> cr = parseRulesLimitation(temp[1]);
|
||||
//noinspection RedundantCast
|
||||
if (Predicates.alwaysTrue() != (Object) cr) { // guava has a single instance for always-const predicates
|
||||
if (cr != null) {
|
||||
preds.add(Predicates.compose(cr, PaperCard::getRules));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user