added 2 overloads to splitWithParethesis assuming parentheses by default.

updated many callers, since they no longer need to specify round brackets explicitly
This commit is contained in:
Maxmtg
2013-05-07 10:11:38 +00:00
parent 1d7c8ea069
commit 57aa02edc4
9 changed files with 21 additions and 14 deletions

View File

@@ -76,7 +76,7 @@ public class BoosterGenerator {
String slotType = slot.getLeft(); // add expansion symbol here?
int numCards = slot.getRight().intValue();
String[] sType = TextUtil.splitWithParenthesis(slotType, ' ', '(', ')');
String[] sType = TextUtil.splitWithParenthesis(slotType, ' ');
String setCode = sType.length == 1 && booster.getEdition() != null ? booster.getEdition() : null;
String sheetKey = Singletons.getModel().getEditions().contains(setCode) ? slotType.trim() + " " + setCode: slotType.trim();
@@ -89,10 +89,10 @@ public class BoosterGenerator {
@SuppressWarnings("unchecked")
public static final PrintSheet makeSheet(String sheetKey, Iterable<CardPrinted> src) {
PrintSheet ps = new PrintSheet(sheetKey);
String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', '(', ')', 2);
String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', 2);
Predicate<CardPrinted> setPred = (Predicate<CardPrinted>) (sKey.length > 1 ? IPaperCard.Predicates.printedInSets(sKey[1].split(" ")) : Predicates.alwaysTrue());
List<String> operators = new LinkedList<String>(Arrays.asList(TextUtil.splitWithParenthesis(sKey[0], ':', '(', ')')));
List<String> operators = new LinkedList<String>(Arrays.asList(TextUtil.splitWithParenthesis(sKey[0], ':')));
Predicate<CardPrinted> extraPred = buildExtraPredicate(operators);
// source replacement operators - if one is applied setPredicate will be ignored

View File

@@ -67,12 +67,12 @@ public class BoosterTemplate extends SealedProductTemplate {
protected BoosterTemplate read(String line, int i) {
String[] headAndData = TextUtil.split(line, ':', 2);
final String edition = headAndData[0];
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',', '(', ')');
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',');
int nCovers = 1;
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();
for(String slotDesc : data) {
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', '(', ')', 2);
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', 2);
if (kv[1].startsWith("cover"))
nCovers = Integer.parseInt(kv[0]);
else

View File

@@ -238,7 +238,7 @@ public final class CardBlock implements Comparable<CardBlock> {
*/
@Override
protected CardBlock read(String line, int i) {
final String[] sParts = TextUtil.splitWithParenthesis(line.trim(), ',', '(', ')', 3);
final String[] sParts = TextUtil.splitWithParenthesis(line.trim(), ',', 3);
String name = sParts[0];
String[] numbers = sParts[1].trim().split("/");
@@ -249,7 +249,7 @@ public final class CardBlock implements Comparable<CardBlock> {
List<CardEdition> sets = new ArrayList<CardEdition>();
List<MetaSet> metas = new ArrayList<MetaSet>();
String[] setNames = TextUtil.splitWithParenthesis(sParts[2], ' ', '(', ')' );
String[] setNames = TextUtil.splitWithParenthesis(sParts[2], ' ' );
for(final String set : setNames ) {
if(set.startsWith("Meta-")) {
String metaSpec = set.substring(5);

View File

@@ -34,7 +34,7 @@ public class FatPackTemplate extends SealedProductTemplate {
protected FatPackTemplate read(String line, int i) {
String[] headAndData = TextUtil.split(line, ':', 2);
final String edition = headAndData[0];
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',', '(', ')');
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',');
int nBoosters = 6;
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();

View File

@@ -78,11 +78,11 @@ public class SealedProductTemplate {
protected SealedProductTemplate read(String line, int i) {
String[] headAndData = TextUtil.split(line, ':', 2);
final String edition = headAndData[0];
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',', '(', ')');
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',');
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();
for(String slotDesc : data) {
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', '(', ')', 2);
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', 2);
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
}

View File

@@ -55,7 +55,7 @@ public class UnOpenedMeta implements IUnOpenedProduct {
metaSets = new ArrayList<MetaSet>();
operation = op;
for(String m : TextUtil.splitWithParenthesis(creationString, ';', '(', ')')) {
for(String m : TextUtil.splitWithParenthesis(creationString, ';')) {
metaSets.add(new MetaSet(m, true));
}
}

View File

@@ -95,9 +95,9 @@ public class CustomLimited extends DeckBase {
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();
String boosterData = data.get("Booster");
if(StringUtils.isNotEmpty(boosterData)){
final String[] booster = TextUtil.splitWithParenthesis(boosterData, ',', '(', ')');
final String[] booster = TextUtil.splitWithParenthesis(boosterData, ',');
for(String slotDesc : booster) {
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', '(', ')', 2);
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', 2);
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
}
} else

View File

@@ -108,7 +108,7 @@ public class SealedCardPoolGenerator {
return;
for (String pz : TextUtil.split(p, ',')) {
String[] pps = TextUtil.splitWithParenthesis(pz.trim(), ' ' , '(', ')');
String[] pps = TextUtil.splitWithParenthesis(pz.trim(), ' ');
String setCode = pps[pps.length - 1];
int nBoosters = pps.length > 1 ? Integer.parseInt(pps[0]) : 1;
while(nBoosters-- > 0)

View File

@@ -48,11 +48,18 @@ public class TextUtil {
public static String[] split(CharSequence input, char delimiter, int limit) {
return splitWithParenthesis(input, delimiter, limit, '\0', '\0', true);
}
public static String[] splitWithParenthesis(CharSequence input, char delimiter) {
return splitWithParenthesis(input, delimiter, Integer.MAX_VALUE, '(', ')', true);
}
public static String[] splitWithParenthesis(CharSequence input, char delimiter, char openPar, char closePar) {
return splitWithParenthesis(input, delimiter, Integer.MAX_VALUE, openPar, closePar, true);
}
public static String[] splitWithParenthesis(CharSequence input, char delimiter, int limit) {
return splitWithParenthesis(input, delimiter, limit, '(', ')', true);
}
public static String[] splitWithParenthesis(CharSequence input, char delimiter, char openPar, char closePar, int limit) {
return splitWithParenthesis(input, delimiter, limit, openPar, closePar, true);
}