Remove not needed pattern

This commit is contained in:
Arne Keller 2020-02-19 08:57:18 +01:00
parent be6bc87b58
commit 0ff7d6e300

View File

@ -57,7 +57,6 @@ public final class CommandFactory {
private static final Pattern PUT_TRAIN_ARGUMENTS
= Pattern.compile(" (" + NUMBER + ") at \\((" + VECTOR + ")\\) in direction (" + VECTOR + ")");
private static final String STEP = "step";
private static final String POSITIVE_NUMBER = " \\+?\\d+";
/**
* Parse a single line of user input into one command.
@ -87,7 +86,7 @@ public final class CommandFactory {
return new AddSwitch(start, end1, end2);
} else if (command.startsWith(DELETE_TRACK)) {
String argument = command.substring(DELETE_TRACK.length());
if (!argument.matches(POSITIVE_NUMBER)) {
if (!argument.matches(" " + NUMBER)) {
throw new InvalidInputException("invalid/missing delete track argument");
}
int id = Integer.parseInt(argument.substring(1));
@ -182,7 +181,7 @@ public final class CommandFactory {
return new AddTrain(trainId, rollingStockId);
} else if (command.startsWith(DELETE_TRAIN)) {
String argument = command.substring(DELETE_TRAIN.length());
if (!argument.matches(POSITIVE_NUMBER)) {
if (!argument.matches(" " + NUMBER)) {
throw new InvalidInputException("invalid delete train argument");
}
int id = Integer.parseInt(argument.substring(1));
@ -194,7 +193,7 @@ public final class CommandFactory {
return new ListTrains();
} else if (command.startsWith(SHOW_TRAIN)) {
String argument = command.substring(SHOW_TRAIN.length());
if (!argument.matches(POSITIVE_NUMBER)) {
if (!argument.matches(" " + NUMBER)) {
throw new InvalidInputException("invalid show train argument");
}
int id = Integer.parseInt(argument.substring(1));