won't throw when not expected

This commit is contained in:
Maxmtg
2014-01-29 17:02:32 +00:00
parent 0621f2e242
commit a5f4f78018

View File

@@ -26,7 +26,7 @@ import org.apache.commons.lang3.StringUtils;
/** /**
* <p> * <p>
* Immutable Card type. Can be build only from parsing a string. * Immutable Card type. Can be built only from parsing a string.
* </p> * </p>
* *
* @author Forge * @author Forge
@@ -56,21 +56,25 @@ public final class CardType implements Comparable<CardType> {
isPermanent = permanent; isPermanent = permanent;
} }
public static CoreType smartValueOf(final String value) { public static CoreType smartValueOf(final String value) { return smartValueOf(value, true); }
public static CoreType smartValueOf(final String value, boolean throwIfNotFound) {
if (value == null) { if (value == null) {
return null; return null;
} }
final String valToCompate = value.trim(); final String valToCompate = value.trim();
for (final CoreType v : CoreType.values()) { for (final CoreType v : CoreType.values()) {
if (v.name().compareToIgnoreCase(valToCompate) == 0) { if (v.name().equalsIgnoreCase(valToCompate)) {
return v; return v;
} }
} }
throw new IllegalArgumentException("No element named " + value + " in enum CoreType"); if (throwIfNotFound)
throw new IllegalArgumentException("No element named " + value + " in enum CoreType");
return null;
} }
public static boolean isAPermanentType(final String cardType) { public static boolean isAPermanentType(final String cardType) {
CoreType ct = smartValueOf(cardType); CoreType ct = smartValueOf(cardType, false);
return ct != null && ct.isPermanent; return ct != null && ct.isPermanent;
} }
} }