Skip to content

Commit

Permalink
Merge pull request #85 from ryanlimdx/fix-list
Browse files Browse the repository at this point in the history
Fix list
  • Loading branch information
iamtr authored Apr 4, 2024
2 parents 32990d5 + c6445ab commit f450a36
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ public ListCommand parse(String args) throws ParseException {

ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_TAG, PREFIX_WARD);

if (!argMultimap.getPreamble().isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
}
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_WARD);
List<String> tagList = ParserUtil
.parseTagsKeywords(argMultimap.getAllValues(PREFIX_TAG));
String ward = argMultimap.getValue(PREFIX_WARD).orElse("");
String ward = ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).orElse(null)).toString();

if (ward.isEmpty() && tagList.isEmpty()) {
throw new ParseException(
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
*/
public static List<String> parseTagsKeywords(Collection<String> tags) throws ParseException {
requireNonNull(tags);
final List<String> tagSet = new ArrayList<>(tags);
return tagSet;
Set <Tag> tagSet = parseTags(tags);
List<String> tagNames = new ArrayList<>();
for (Tag tag : tagSet) {
tagNames.add(tag.getTagName());
}
return tagNames;
}

/**
Expand All @@ -113,7 +117,6 @@ public static Dob parseDob(String dob) throws ParseException {
*/
public static Ic parseIc(String ic) throws ParseException {
requireNonNull(ic);
// Todo: Error handling
String trimmedIc = ic.trim();
if (!Ic.isValidIc(trimmedIc)) {
throw new ParseException(Ic.MESSAGE_CONSTRAINTS);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@ public String toString() {
return '[' + tagName + ']';
}

/**
* Returns the tag name.
*/
public String getTagName() {
return tagName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void parse_validArgs_returnsListCommand() {
// no leading and trailing whitespaces
ListCommand expectedListCommand =
new ListCommand(
new ListKeywordsPredicate(Arrays.asList(VALID_TAG_DIABETES, VALID_TAG_FALL_RISK),
new ListKeywordsPredicate(Arrays.asList(VALID_TAG_FALL_RISK, VALID_TAG_DIABETES),
VALID_WARD_BOB));
assertParseSuccess(parser, TAG_DESC_DIABETES
+ TAG_DESC_FALL_RISK + WARD_DESC_BOB, expectedListCommand);
Expand Down

0 comments on commit f450a36

Please sign in to comment.