removing unused code

This commit is contained in:
Maxmtg
2012-03-26 20:35:01 +00:00
parent d222aaa7c1
commit bc0033cd4d
10 changed files with 36 additions and 568 deletions

3
.gitattributes vendored
View File

@@ -11300,7 +11300,6 @@ src/main/java/forge/CardCharactersticName.java -text
src/main/java/forge/CardColor.java svneol=native#text/plain src/main/java/forge/CardColor.java svneol=native#text/plain
src/main/java/forge/CardContainer.java svneol=native#text/plain src/main/java/forge/CardContainer.java svneol=native#text/plain
src/main/java/forge/CardDamageHistory.java -text src/main/java/forge/CardDamageHistory.java -text
src/main/java/forge/CardFilter.java svneol=native#text/plain
src/main/java/forge/CardKeywords.java -text svneol=native#text/plain src/main/java/forge/CardKeywords.java -text svneol=native#text/plain
src/main/java/forge/CardList.java svneol=native#text/plain src/main/java/forge/CardList.java svneol=native#text/plain
src/main/java/forge/CardListFilter.java svneol=native#text/plain src/main/java/forge/CardListFilter.java svneol=native#text/plain
@@ -11847,7 +11846,6 @@ src/main/java/net/slightlymagic/braids/util/ClumsyRunnable.java svneol=native#te
src/main/java/net/slightlymagic/braids/util/ImmutableIterableFrom.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/ImmutableIterableFrom.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/UtilFunctions.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/UtilFunctions.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/generator/FindNonDirectoriesSkipDotDirectoriesGenerator.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/generator/FindNonDirectoriesSkipDotDirectoriesGenerator.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/generator/GeneratorFromArray.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/generator/GeneratorFunctions.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/generator/GeneratorFunctions.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/generator/package-info.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/generator/package-info.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/package-info.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/package-info.java svneol=native#text/plain
@@ -11876,7 +11874,6 @@ src/test/java/forge/PanelTest.java svneol=native#text/plain
src/test/java/forge/PhaseHandlerTest.java -text src/test/java/forge/PhaseHandlerTest.java -text
src/test/java/forge/RunTest.java svneol=native#text/plain src/test/java/forge/RunTest.java svneol=native#text/plain
src/test/java/forge/TinyTest.java svneol=native#text/plain src/test/java/forge/TinyTest.java svneol=native#text/plain
src/test/java/forge/card/cardFactory/CardFactoryUtilTest.java svneol=native#text/plain
src/test/java/forge/card/mana/ManaPartTest.java svneol=native#text/plain src/test/java/forge/card/mana/ManaPartTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/Generate2ColorDeckTest.java svneol=native#text/plain src/test/java/forge/deck/generate/Generate2ColorDeckTest.java svneol=native#text/plain
src/test/java/forge/deck/generate/Generate3ColorDeckTest.java svneol=native#text/plain src/test/java/forge/deck/generate/Generate3ColorDeckTest.java svneol=native#text/plain

View File

@@ -1,367 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge;
import java.util.List;
import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.generator.GeneratorFunctions;
import com.google.code.jyield.Generator;
import forge.card.EditionInfo;
import forge.util.Lambda1;
/**
* <p>
* CardFilter class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class CardFilter {
/**
* Filter a sequence (iterable) of cards to a list of equal or smaller size
* whose names contain the given substring.
*
* We perform the substring search without sensitivity to case.
*
* @param toBeFiltered
* an {@link java.lang.Iterable} of Card instances
* @param substring
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList cardListNameFilter(final Iterable<Card> toBeFiltered, final String substring) {
String s;
final CardList listFilter = new CardList();
for (final Card card : toBeFiltered) {
s = card.getName().toLowerCase();
if (s.indexOf(substring.toLowerCase()) >= 0) {
listFilter.add(card);
}
}
return listFilter;
}
/**
* <p>
* cardListTextFilter.
* </p>
*
* @param all
* a {@link forge.CardList} object.
* @param name
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList cardListTextFilter(final CardList all, final String name) {
Card cardName;
String s;
s = "";
final CardList listFilter = new CardList();
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
s = cardName.getText().toLowerCase();
if (s.indexOf(name.toLowerCase()) >= 0) {
listFilter.add(cardName);
}
}
return listFilter;
}
/**
* <p>
* cardListColorFilter.
* </p>
*
* @param all
* a {@link forge.CardList} object.
* @param name
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList cardListColorFilter(final CardList all, final String name) {
Card cardName = new Card();
final CardList listFilter = new CardList();
if (name == "black") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!CardUtil.getColors(cardName).contains(Constant.Color.BLACK)) {
listFilter.add(cardName);
}
}
}
if (name == "blue") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!CardUtil.getColors(cardName).contains(Constant.Color.BLUE)) {
listFilter.add(cardName);
}
}
}
if (name == "green") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!CardUtil.getColors(cardName).contains(Constant.Color.GREEN)) {
listFilter.add(cardName);
}
}
}
if (name == "red") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!CardUtil.getColors(cardName).contains(Constant.Color.RED)) {
listFilter.add(cardName);
}
}
}
if (name == "white") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!CardUtil.getColors(cardName).contains(Constant.Color.WHITE)) {
listFilter.add(cardName);
}
}
}
if (name.equals("colorless")) {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!CardUtil.getColors(cardName).contains(Constant.Color.COLORLESS)) {
listFilter.add(cardName);
}
}
}
return listFilter;
}
/**
* <p>
* cardListTypeFilter.
* </p>
*
* @param all
* a {@link forge.CardList} object.
* @param name
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final CardList cardListTypeFilter(final CardList all, final String name) {
Card cardName = new Card();
final CardList listFilter = new CardList();
if (name == "artifact") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isArtifact()) {
listFilter.add(cardName);
}
}
}
if (name == "creature") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isCreature()) {
listFilter.add(cardName);
}
}
}
if (name == "enchantment") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isEnchantment()) {
listFilter.add(cardName);
}
}
}
if (name == "instant") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isInstant()) {
listFilter.add(cardName);
}
}
}
if (name == "land") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isLand()) {
listFilter.add(cardName);
}
}
}
if (name == "planeswalker") {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isPlaneswalker()) {
listFilter.add(cardName);
}
}
}
if (name.equals("sorcery")) {
for (int i = 0; i < all.size(); i++) {
cardName = all.getCard(i);
if (!cardName.isSorcery()) {
listFilter.add(cardName);
}
}
}
return listFilter;
}
/**
* Filter an iterable sequence of Cards; note this is a static method that
* is very similar to the non-static one.
*
* @param iterable
* the sequence of cards to examine
*
* @param filt
* determines which cards are present in the resulting list
*
* @return a list of Cards that meet the filtering criteria; may be empty,
* but never null
*/
public static CardList filter(final Iterable<Card> iterable, final CardListFilter filt) {
final CardList result = new CardList();
for (final Card card : iterable) {
if (filt.addCard(card)) {
result.add(card);
}
}
return result;
}
/**
* Filter a Generator of Cards based on their colors; this does not cause
* the generator to be evaluated, but rather defers the filtering to when
* the result's generate method is called (e.g., by YieldUtils.toIterable).
*
* @param inputGenerator
* the sequence to filter; must not be null
*
* @param cardColor
* a {@link java.lang.String} object; "Multicolor" is also
* accepted. Must not be null.
*
* @return a new Generator containing cards only of the desired color or
* multicolored cards.
*/
public static Generator<Card> getColor(final Generator<Card> inputGenerator, final String cardColor) {
UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
UtilFunctions.checkNotNull("cardColor", cardColor);
final boolean weWantMulticolor = cardColor.equals("Multicolor");
final Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
@Override
public Boolean apply(final Card c) {
if (c == null) {
return false;
}
if (weWantMulticolor && (c.getColor() != null) && (c.getColor().size() > 1)) {
return true;
} else if (c.isColor(cardColor) && (c.getColor() != null) && (c.getColor().size() == 1)) {
return true;
}
return false;
}
};
return GeneratorFunctions.filterGenerator(predicate, inputGenerator);
} // getColor()
/**
* Filter a Generator of cards so that it contains only the ones that exist
* in certain sets.
*
* @param inputGenerator
* a sequence Generator of Card instances; must not be null.
*
* @param sets
* an ArrayList of Strings identifying the valid sets; must not
* be null.
*
* @return a {@link forge.CardList} object.
*/
public static Generator<Card> getSets(final Generator<Card> inputGenerator, final List<String> sets) {
UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
UtilFunctions.checkNotNull("sets", sets);
final Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
@Override
public Boolean apply(final Card c) {
if (c == null) {
return false;
}
for (final EditionInfo set : c.getSets()) {
if ((set != null) && sets.contains(set.toString())) {
return true;
}
}
return false;
}
};
return GeneratorFunctions.filterGenerator(predicate, inputGenerator);
} // getSets(Generator,ArrayList)
}

View File

@@ -635,7 +635,13 @@ public class CardList implements Iterable<Card> {
* criteria; may be empty, but never null. * criteria; may be empty, but never null.
*/ */
public final CardList filter(final CardListFilter filt) { public final CardList filter(final CardListFilter filt) {
return CardFilter.filter(this, filt); final CardList result = new CardList();
for (final Card card : this) {
if (filt.addCard(card)) {
result.add(card);
}
}
return result;
} }
/** /**

View File

@@ -24,7 +24,6 @@ import java.util.Random;
import forge.AllZone; import forge.AllZone;
import forge.Card; import forge.Card;
import forge.CardFilter;
import forge.CardList; import forge.CardList;
import forge.CardListFilter; import forge.CardListFilter;
import forge.Constant; import forge.Constant;
@@ -34,6 +33,7 @@ import forge.error.ErrorViewer;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.Predicate;
/** /**
* <p> * <p>
@@ -134,16 +134,10 @@ public class Generate2ColorDeck {
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() {
@Override Predicate<Card> toUse = pt == PlayerType.HUMAN ? GenerateDeckUtil.humanCanPlay : GenerateDeckUtil.aiCanPlay;
public boolean addCard(final Card c) { CardList allCards = new CardList(toUse.select(AllZone.getCardFactory()));
if (c.getSVar("RemRandomDeck").equals("True")) {
return false;
}
return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN)));
}
});
// reduce to cards that match the colors // reduce to cards that match the colors
CardList cl1 = allCards.getColor(this.color1); CardList cl1 = allCards.getColor(this.color1);
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) { if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) {

View File

@@ -24,7 +24,6 @@ import java.util.Random;
import forge.AllZone; import forge.AllZone;
import forge.Card; import forge.Card;
import forge.CardFilter;
import forge.CardList; import forge.CardList;
import forge.CardListFilter; import forge.CardListFilter;
import forge.Constant; import forge.Constant;
@@ -34,6 +33,7 @@ import forge.error.ErrorViewer;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.Predicate;
/** /**
* <p> * <p>
@@ -146,16 +146,9 @@ public class Generate3ColorDeck {
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { Predicate<Card> toUse = pt == PlayerType.HUMAN ? GenerateDeckUtil.humanCanPlay : GenerateDeckUtil.aiCanPlay;
@Override CardList allCards = new CardList(toUse.select(AllZone.getCardFactory()));
public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) {
return false;
}
return (!c.getSVar("RemAIDeck").equals("True") || ((pt != null) && pt.equals(PlayerType.HUMAN)));
}
});
// reduce to cards that match the colors // reduce to cards that match the colors
CardList cl1 = allCards.getColor(this.color1); CardList cl1 = allCards.getColor(this.color1);
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) { if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) {

View File

@@ -24,7 +24,6 @@ import java.util.Random;
import forge.AllZone; import forge.AllZone;
import forge.Card; import forge.Card;
import forge.CardFilter;
import forge.CardList; import forge.CardList;
import forge.CardListFilter; import forge.CardListFilter;
import forge.Constant; import forge.Constant;
@@ -34,6 +33,7 @@ import forge.error.ErrorViewer;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.Predicate;
/** /**
* <p> * <p>
@@ -144,16 +144,9 @@ public class Generate5ColorDeck {
// start with all cards // start with all cards
// remove cards that generated decks don't like // remove cards that generated decks don't like
final CardList allCards = CardFilter.filter(AllZone.getCardFactory(), new CardListFilter() { Predicate<Card> toUse = playerType == PlayerType.HUMAN ? GenerateDeckUtil.humanCanPlay : GenerateDeckUtil.aiCanPlay;
@Override CardList allCards = new CardList(toUse.select(AllZone.getCardFactory()));
public boolean addCard(final Card c) {
if (c.getSVar("RemRandomDeck").equals("True")) {
return false;
}
return (!c.getSVar("RemAIDeck").equals("True") || ((playerType != null) && playerType.equals(PlayerType.HUMAN)));
}
});
// reduce to cards that match the colors // reduce to cards that match the colors
CardList cardList1 = allCards.getColor(this.color1); CardList cardList1 = allCards.getColor(this.color1);
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) { if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) {

View File

@@ -19,6 +19,9 @@ package forge.deck.generate;
import java.util.ArrayList; import java.util.ArrayList;
import forge.Card;
import forge.util.Predicate;
/** /**
* <p> * <p>
* GenerateDeckUtil class. * GenerateDeckUtil class.
@@ -29,6 +32,19 @@ import java.util.ArrayList;
*/ */
public class GenerateDeckUtil { public class GenerateDeckUtil {
public static final Predicate<Card> aiCanPlay = new Predicate<Card>(){
@Override
public boolean isTrue(Card c) {
return !c.getSVar("RemRandomDeck").equals("True") && !c.getSVar("RemAIDeck").equals("True");
}
};
public static final Predicate<Card> humanCanPlay = new Predicate<Card>(){
@Override
public boolean isTrue(Card c) {
return !c.getSVar("RemRandomDeck").equals("True");
}
};
/** /**
* *
* Arrays of dual and tri-land cards. * Arrays of dual and tri-land cards.

View File

@@ -1,66 +0,0 @@
/*
* The files in the directory "net/slightlymagic/braids" and in all subdirectories of it (the "Files") are
* Copyright 2011 Braids Cabal-Conjurer. They are available under either Forge's
* main license (the GNU Public License; see LICENSE.txt in Forge's top directory)
* or under the Apache License, as explained below.
*
* The Files are additionally licensed under the Apache License, Version 2.0 (the
* "Apache License"); you may not use the files in this directory except in
* compliance with one of its two licenses. You may obtain a copy of the Apache
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Apache License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License for the specific language governing permissions and
* limitations under the Apache License.
*
*/
package net.slightlymagic.braids.util.generator;
import com.google.code.jyield.Generator;
import com.google.code.jyield.Yieldable;
/**
* Creates a Generator from an array; generators are a handy substitute for
* passing around and creating temporary lists, collections, and arrays.
*
* @param <T>
* the generic type {@link com.google.code.jyield.Generator}
*/
public class GeneratorFromArray<T> implements Generator<T> {
private T[] array;
/**
* Create a Generator from an array.
*
* @param array
* from which to generate items
*/
public GeneratorFromArray(final T[] array) {
this.array = array;
}
/*
* (non-Javadoc)
*
* @see
* com.google.code.jyield.Generator#generate(com.google.code.jyield.Yieldable
* )
*/
/**
* Submits all of the array's elements to the yieldable.
*
* @param yy
* the yieldable which receives the elements
*/
@Override
public final void generate(final Yieldable<T> yy) {
for (T item : array) {
yy.yield(item);
}
}
}

View File

@@ -70,50 +70,6 @@ public final class GeneratorFunctions {
return result; return result;
} }
/**
* Highly efficient means of filtering a long or infinite sequence.
*
* @param <T>
* any type
*
* @param predicate
* a Lambda (function) whose apply method takes an object of type
* <T> and returns a Boolean. If it returns false or null, the
* item from the inputGenerator is not yielded by this Generator;
* if predicate.apply returns true, then this Generator
* <i>does</i> yield the value.
*
* @param inputGenerator
* the sequence upon which we operate
*
* @return a generator which produces a subset <= the inputGenerator
*/
public static <T> Generator<T> filterGenerator(final Lambda1<Boolean, T> predicate,
final Generator<T> inputGenerator) {
Generator<T> result = new Generator<T>() {
@Override
public void generate(final Yieldable<T> outputYield) {
Yieldable<T> inputYield = new Yieldable<T>() {
private Boolean pResult;
@Override
public void yield(final T input) {
pResult = predicate.apply(input);
if (pResult != null && pResult) {
outputYield.yield(input);
}
}
};
inputGenerator.generate(inputYield);
}
};
return result;
}
/** /**
* Highly efficient means of applying a transform to a long or infinite * Highly efficient means of applying a transform to a long or infinite

View File

@@ -1,54 +0,0 @@
package forge.card.cardFactory;
import org.testng.annotations.Test;
import com.google.code.jyield.Generator;
import com.google.code.jyield.YieldUtils;
import forge.AllZone;
import forge.Card;
import forge.CardFilter;
import forge.CardList;
import forge.Counters;
import forge.card.cardfactory.CardFactoryUtil;
/**
* <p>
* Mana_PartTest class.
* </p>
*
* @author Forge
* @version $Id$
*/
@Test(groups = { "UnitTest" }, timeOut = 1000, enabled = false)
public class CardFactoryUtilTest {
/**
* Card factory test1.
*/
@Test(timeOut = 1000, enabled = false)
public void cardFactoryTest1() {
Generator<Card> in = YieldUtils.toGenerator(AllZone.getCardFactory());
in = CardFilter.getColor(in, "black");
CardList list = new CardList(in);
list = list.getType("Creature");
System.out.println("Most prominent creature type: " + CardFactoryUtil.getMostProminentCreatureType(list));
final String manacost = "3 GW W W R B S";
final String multipliedTwice = CardFactoryUtil.multiplyManaCost(manacost, 2);
final String multipliedThrice = CardFactoryUtil.multiplyManaCost(manacost, 3);
System.out.println(manacost + " times 2 = " + multipliedTwice);
System.out.println(manacost + " times 3 = " + multipliedThrice);
if (CardFactoryUtil.isNegativeCounter(Counters.M1M1)) {
System.out.println("M1M1 is a bad counter!");
} else {
System.out.println("M1M1 is a good counter!");
}
}
}