Skip to content

Commit

Permalink
Merge pull request #175 from ondretann/branch-FixId
Browse files Browse the repository at this point in the history
Fix id bug
  • Loading branch information
ondretann authored Apr 10, 2024
2 parents 887f976 + d45a58c commit 5c54d20
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void checkArgument(Boolean condition) {
*
* @throws IllegalArgumentException with {@code errorMessage} if {@code condition} is false.
*/
public static void checkArgument(Boolean condition, String errorMessage) {
public static void checkArgument(Boolean condition, String errorMessage) throws IllegalArgumentException {
if (!condition) {
throw new IllegalArgumentException(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
public class DeleteConfirmationCommandParser implements Parser<DeleteConfirmationCommand> {

@Override
public DeleteConfirmationCommand parse(String args) throws ParseException {
public DeleteConfirmationCommand parse(String args) throws ParseException, IllegalArgumentException {
try {
Id id = ParserUtil.parseId(args);
return new DeleteConfirmationCommand(id);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe);
} catch (IllegalArgumentException e) {
throw new ParseException(Id.MESSAGE_CONSTRAINTS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public EditCommand parse(String args) throws ParseException {
id = ParserUtil.parseId(argMultimap.getPreamble());
} catch (ParseException pe) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
} catch (IllegalArgumentException e) {
throw new ParseException(Id.MESSAGE_CONSTRAINTS);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public TagCommand parse(String args) throws ParseException {
id = ParserUtil.parseId(argMultimap.getPreamble());
} catch (ParseException pe) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagCommand.MESSAGE_USAGE));
} catch (IllegalArgumentException e) {
throw new ParseException(Id.MESSAGE_CONSTRAINTS);
}

Set<String> tagNames = new HashSet<>(argMultimap.getAllValues(PREFIX_TAG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public TransactionCommand parse(String args) throws ParseException {
} else {
dateTime = new DateTime(LocalDateTime.now());
}
Id employeeId = ParserUtil.parseId(argMultimap.getValue(PREFIX_ID).get());
Id employeeId = null;
try {
employeeId = ParserUtil.parseId(argMultimap.getValue(PREFIX_ID).get());
} catch (IllegalArgumentException e) {
throw new ParseException(Id.MESSAGE_CONSTRAINTS);
}
if (!model.hasPersonId(employeeId)) {
throw new ParseException(MESSAGE_INVALID_PERSON_DISPLAYED_ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public ViewCommand parse(String userInput) throws ParseException {
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE), pe);
} catch (IllegalArgumentException e) {
throw new ParseException(Id.MESSAGE_CONSTRAINTS);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Id(Model model, YearJoined yearJoined) {
*
* @param id A valid ID.
*/
public Id(int id) {
public Id(int id) throws IllegalArgumentException {
checkArgument(isValidId(id), MESSAGE_CONSTRAINTS);
value = id;
}
Expand Down

0 comments on commit 5c54d20

Please sign in to comment.