From 7c34dad8cb4e9203fd3483c4d7776b5229e97528 Mon Sep 17 00:00:00 2001 From: igoudt Date: Sat, 30 Sep 2017 00:07:25 +0200 Subject: [PATCH] update cardtextpredicate --- .../predicate/other/CardTextPredicate.java | 49 +++++-------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/Mage/src/main/java/mage/filter/predicate/other/CardTextPredicate.java b/Mage/src/main/java/mage/filter/predicate/other/CardTextPredicate.java index 36cf356ce4..2f6559a6d7 100644 --- a/Mage/src/main/java/mage/filter/predicate/other/CardTextPredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/other/CardTextPredicate.java @@ -29,13 +29,10 @@ package mage.filter.predicate.other; import mage.cards.Card; import mage.cards.SplitCard; -import mage.constants.SubType; -import mage.constants.SuperType; import mage.filter.predicate.Predicate; import mage.game.Game; /** - * * @author North */ public class CardTextPredicate implements Predicate { @@ -64,53 +61,31 @@ public class CardTextPredicate implements Predicate { //separate by spaces String[] tokens = text.toLowerCase().split(" "); + boolean found = false; for (String token : tokens) { - boolean found = false; if (!token.isEmpty()) { // then try to find in rules if (inRules) { if (input.isSplitCard()) { - for (String rule : ((SplitCard) input).getLeftHalfCard().getRules(game)) { - if (rule.toLowerCase().contains(token)) { - found = true; - break; - } - } - for (String rule : ((SplitCard) input).getRightHalfCard().getRules(game)) { - if (rule.toLowerCase().contains(token)) { - found = true; - break; - } - } - } - for (String rule : input.getRules(game)) { - if (rule.toLowerCase().contains(token)) { - found = true; - break; - } + found = ((SplitCard) input).getLeftHalfCard().getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase())); + found |= ((SplitCard) input).getRightHalfCard().getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase())); + + } else { + found = input.getRules(game).stream().anyMatch(rule -> rule.toLowerCase().contains(token.toLowerCase())); } } if (inTypes) { - for (SubType subType : input.getSubtype(game)) { - if (subType.toString().equalsIgnoreCase(token)) { - found = true; - break; - } - } - for (SuperType superType : input.getSuperType()) { - if (superType.toString().equalsIgnoreCase(token)) { - found = true; - break; - } - } + found |= input.getSubtype(game).stream().anyMatch(s -> s.toString().equalsIgnoreCase(token)); + found |= input.getSuperType().stream().anyMatch(s -> s.toString().equalsIgnoreCase(token)); } } - if (!found) { - return false; + if (found) { + break; } + } - return true; + return found; } @Override