mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
won't throw when not expected
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user