aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/cli
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2016-08-14 18:09:22 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2016-08-14 18:09:22 +0200
commit8cb35b358563e5a81ad9e4aceb123b85222cf4cc (patch)
tree0d73eebfe29e7d90d4e0d6c5d40a36db75de3fdc /src/eu/equalparts/cardbase/cli
parent78e369043f95e78b27c265f7eab4d766e54054f4 (diff)
Implemented some more filtering tests, sorted out validation and exceptions
Diffstat (limited to 'src/eu/equalparts/cardbase/cli')
-rw-r--r--src/eu/equalparts/cardbase/cli/CardbaseCLI.java14
1 files changed, 6 insertions, 8 deletions
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 {