From 8cb35b358563e5a81ad9e4aceb123b85222cf4cc Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 14 Aug 2016 18:09:22 +0200 Subject: Implemented some more filtering tests, sorted out validation and exceptions --- src/eu/equalparts/cardbase/cli/CardbaseCLI.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/eu/equalparts/cardbase/cli') diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java index f86365d..5738f5d 100644 --- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java +++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java @@ -389,14 +389,14 @@ public final class CardbaseCLI { if (cardToRemove != null) { String count = args.length > 1 ? args[1] : "1"; - if (count.matches("[-]?[0-9]+")) { - Integer intCount = Integer.valueOf(count); + try { + Integer intCount = Integer.parseInt(count); if (intCount > 0) { removeCard(cardToRemove, intCount); } else { System.out.println("Cannot remove " + count + " cards."); } - } else { + } catch (NumberFormatException e) { System.out.println(count + " is not a valid number of cards."); } } else { @@ -430,16 +430,14 @@ public final class CardbaseCLI { if (cardToAdd != null) { String count = args != null && args.length > 0 ? args[0] : "1"; - if (count.matches("[-]?[0-9]+")) { - - Integer intCount = Integer.valueOf(count); - + try { + Integer intCount = Integer.parseInt(count); if (intCount > 0) { addCard(cardToAdd, intCount); } else { System.out.println("Cannot add " + intCount + " cards."); } - } else { + } catch (NumberFormatException e) { System.out.println(count + " is not a valid number of cards."); } } else { -- cgit v1.2.3