Skip to content

Commit

Permalink
Merge pull request #215 from alex-setyawan/logic-issues
Browse files Browse the repository at this point in the history
Fix case sensitivity and find command
  • Loading branch information
jovantanyk authored Apr 12, 2024
2 parents 9d4c882 + 6b81701 commit 912e19c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public class ClusterCommand extends Command {
public static final String COMMAND_WORD = "cluster";

public static final String MESSAGE_USAGE = COMMAND_WORD + ":\nDetects if there is a cluster of the size given,"
+ " at the location given, of the disease given, and shows the details of all there with the disease."
+ "by the respective NRIC in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ " at the location given, of the disease given, and shows the details of all there with the disease.\n"
+ "Parameters: [CLUSTER SIZE] "
+ "[" + PREFIX_ADDRESS + "LOCATION] "
+ "[" + PREFIX_DIAGNOSIS + "DISEASE]\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public class UpdateCommand extends Command {
public static final String MESSAGE_UPDATE_PERSON_SUCCESS = "Updated Person ->\n%1$s";
public static final String MESSAGE_NOT_UPDATED = "At least one field to update must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
public static final String MESSAGE_NRIC_NOT_UPDATED = "NRIC cannot be updated.";
private final Nric nric;
private final UpdatePersonDescriptor updatePersonDescriptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DeleteCommandParser implements Parser<DeleteCommand> {
*/
public DeleteCommand parse(String args) throws ParseException {
try {
Nric nric = ParserUtil.parseNric(args.toUpperCase());
Nric nric = ParserUtil.parseNric(args);
return new DeleteCommand(nric);
} catch (ParseException pe) {
throw new ParseException(
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/seedu/address/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,41 @@ public FindCommand parse(String args) throws ParseException {
}

if (trimmedArgs.startsWith(PREFIX_NAME.getPrefix())) {
String[] nameKeywords = trimmedArgs.substring(2).trim().split("\\s+");
List<String> list = Arrays.asList(nameKeywords);
String nameKeywords = trimmedArgs.substring(2);
if (nameKeywords.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}
List<String> list = Arrays.asList(nameKeywords.trim().split("\\s+"));
return new FindCommand(new NameContainsKeywordsPredicate(list));
} else if (trimmedArgs.startsWith(PREFIX_ADDRESS.getPrefix())) {
String[] addressKeywords = trimmedArgs.substring(2).trim().split(",");
String doubleTrimmedArgs = trimmedArgs.substring(2);
if (doubleTrimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

String[] addressKeywords = doubleTrimmedArgs.trim().split(",");
int len = addressKeywords.length;
for (int i = 0; i < len; i++) {
addressKeywords[i] = addressKeywords[i].trim();
}

List<String> list = Arrays.asList(addressKeywords);
return new FindCommand(new AddressContainsKeywordsPredicate(list));
} else if (trimmedArgs.startsWith(PREFIX_CONDITION.getPrefix())) {
String[] conditionKeywords = trimmedArgs.substring(4).trim().split(",");
String doubleTrimmedArgs = trimmedArgs.substring(4);
if (doubleTrimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

String[] conditionKeywords = doubleTrimmedArgs.trim().split(",");
int len = conditionKeywords.length;
for (int i = 0; i < len; i++) {
conditionKeywords[i] = conditionKeywords[i].trim();
}

List<String> list = Arrays.asList(conditionKeywords);
return new FindCommand(new ConditionContainsKeywordsPredicate(list));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Nric parseNric(String nric) throws ParseException {
if (!Nric.isValidNric(trimmedNric)) {
throw new ParseException(Nric.MESSAGE_CONSTRAINTS);
}
return new Nric(trimmedNric);
return new Nric(trimmedNric.toUpperCase());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public UpdateCommand parse(String args) throws ParseException {

UpdatePersonDescriptor updatePersonDescriptor = new UpdatePersonDescriptor();
updatePersonDescriptor.setNric(nric);
//Un-updatable field
if (argMultimap.getValue(PREFIX_NRIC).isPresent()) {
throw new ParseException(UpdateCommand.MESSAGE_NRIC_NOT_UPDATED);
}

// Mandatory fields
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/model/person/Nric.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class Nric {
public static final String MESSAGE_CONSTRAINTS =
"NRIC number should contain a prefix of S or T, followed by 7 digits, and end with a letter. "
+ "There should not be blank.";
+ "There should not be blanks.";

/**
* The first character of the address must not be a whitespace,
Expand All @@ -30,7 +30,6 @@ public class Nric {
public Nric(String nric) {
requireNonNull(nric);
checkArgument(isValidNric(nric), MESSAGE_CONSTRAINTS);
//TODO: is this a bug?
this.nric = nric.toUpperCase();
}

Expand Down

0 comments on commit 912e19c

Please sign in to comment.