Normalize card names, use specific cards when numbers when possible.
@@ -19,4 +19,37 @@ public class CardLookup {
return CardRepository.instance.findCards(criteria);
}
+ public Optional<CardInfo> lookupCardInfo(String name, String set) {
+ Optional<CardInfo> result = lookupCardInfo(new CardCriteria().name(name).setCodes(set))
+ .stream()
+ .findAny();
+ if (result.isPresent()) {
+ return result;
+ }
+
+ return lookupCardInfo(name);
+ }
+
+ public Optional<CardInfo> lookupCardInfo(String name, String set, String cardNumber) {
+ Optional<CardInfo> result;
+ try {
+ int intCardNumber = Integer.parseInt(cardNumber);
+ result = lookupCardInfo(
+ new CardCriteria()
+ .name(name)
+ .setCodes(set)
+ .minCardNumber(intCardNumber)
+ .maxCardNumber(intCardNumber))
+ .stream()
+ .findAny();
+ if (result.isPresent()) {
+ return result;
+ }
+ } catch (NumberFormatException ignored) {
+ /* ignored */
+ }
+
+ return lookupCardInfo(name, set);
+ }
+
}
