Skip to content

Commit 49ca59b

Browse files
committed
Change predicate to contain both address and status
1 parent 6e1f8b6 commit 49ca59b

File tree

5 files changed

+55
-86
lines changed

5 files changed

+55
-86
lines changed

src/main/java/seedu/address/logic/commands/ClusterCommand.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,13 @@
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
77
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
88
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
9-
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
10-
11-
import java.util.ArrayList;
12-
import java.util.Collections;
13-
import java.util.HashSet;
14-
import java.util.List;
15-
import java.util.Objects;
16-
import java.util.Optional;
17-
import java.util.Set;
9+
1810
import java.util.function.Predicate;
1911

20-
import seedu.address.commons.util.CollectionUtil;
2112
import seedu.address.commons.util.ToStringBuilder;
22-
import seedu.address.logic.Messages;
2313
import seedu.address.logic.commands.exceptions.CommandException;
2414
import seedu.address.model.Model;
25-
import seedu.address.model.person.Address;
26-
import seedu.address.model.person.Allergies;
27-
import seedu.address.model.person.BloodType;
28-
import seedu.address.model.person.Condition;
29-
import seedu.address.model.person.Country;
30-
import seedu.address.model.person.DateOfAdmission;
31-
import seedu.address.model.person.DateOfBirth;
32-
import seedu.address.model.person.Diagnosis;
33-
import seedu.address.model.person.Email;
34-
import seedu.address.model.person.Name;
35-
import seedu.address.model.person.Nric;
36-
import seedu.address.model.person.NricContainsKeywordsPredicate;
3715
import seedu.address.model.person.Person;
38-
import seedu.address.model.person.Phone;
39-
import seedu.address.model.person.Sex;
40-
import seedu.address.model.person.Status;
41-
import seedu.address.model.person.StatusContainsKeywordsPredicate;
42-
import seedu.address.model.person.Symptom;
43-
import seedu.address.model.tag.Tag;
4416

4517

4618
/**
@@ -86,10 +58,6 @@ public CommandResult execute(Model model) throws CommandException {
8658
requireNonNull(model);
8759
model.updateFilteredPersonList(predicate);
8860

89-
ArrayList<String> statusKeywords = new ArrayList<>();
90-
statusKeywords.add("UNWELL");
91-
model.updateFilteredPersonList(new StatusContainsKeywordsPredicate(statusKeywords));
92-
9361
if (model.getFilteredPersonList().size() >= clusterSize) {
9462
return new CommandResult(String.format(MESSAGE_CLUSTER_FOUND_SUCCESS));
9563
} else {

src/main/java/seedu/address/logic/commands/UpdateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public CommandResult execute(Model model) throws CommandException {
9292
new NricContainsKeywordsPredicate(nric.toString())).findFirst().get();
9393
Person updatedPerson = createUpdatedPerson(personToUpdate, updatePersonDescriptor);
9494

95-
if (!personToUpdate.isSamePerson(updatedPerson) && model.hasPerson(updatedPerson)) {
95+
if (!(personToUpdate.isSamePerson(updatedPerson) && model.hasPerson(updatedPerson))) {
9696
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
9797
}
9898

src/main/java/seedu/address/logic/parser/ClusterCommandParser.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
44

5-
import java.util.Arrays;
6-
import java.util.List;
7-
85
import seedu.address.logic.commands.ClusterCommand;
96
import seedu.address.logic.parser.exceptions.ParseException;
10-
import seedu.address.model.person.AddressContainsKeywordsPredicate;
7+
import seedu.address.model.person.AddressAndStatusPredicate;
118

129
/**
1310
* Parses input arguments and creates a new FindCommand object
@@ -39,8 +36,7 @@ public ClusterCommand parse(String args) throws ParseException {
3936
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClusterCommand.MESSAGE_USAGE));
4037
}
4138

42-
String addressKeywords = keywords[1];
43-
List<String> list = Arrays.asList(addressKeywords);
44-
return new ClusterCommand(clusterSize, new AddressContainsKeywordsPredicate(list));
39+
String addressKeyword = keywords[1];
40+
return new ClusterCommand(clusterSize, new AddressAndStatusPredicate(addressKeyword, "UNWELL"));
4541
}
4642
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package seedu.address.model.person;
2+
3+
import java.util.List;
4+
import java.util.function.Predicate;
5+
6+
import seedu.address.commons.util.StringUtil;
7+
import seedu.address.commons.util.ToStringBuilder;
8+
9+
/**
10+
* Tests that a {@code Person}'s {@code Status} matches any of the keywords given.
11+
*/
12+
public class AddressAndStatusPredicate implements Predicate<Person> {
13+
private final String address;
14+
private final String status;
15+
public AddressAndStatusPredicate(String address, String status) {
16+
this.address = address;
17+
this.status = status;
18+
}
19+
20+
@Override
21+
public boolean test(Person person) {
22+
return person.getAddress().toString().toLowerCase().contains(address)
23+
&& person.getStatus().toString().equals(status);
24+
}
25+
26+
@Override
27+
public boolean equals(Object other) {
28+
if (other == this) {
29+
return true;
30+
}
31+
32+
// instanceof handles nulls
33+
if (!(other instanceof AddressAndStatusPredicate)) {
34+
return false;
35+
}
36+
37+
AddressAndStatusPredicate otherAddressAndStatusPredicate =
38+
(AddressAndStatusPredicate) other;
39+
return address.equals(otherAddressAndStatusPredicate.address)
40+
&& status.equals(otherAddressAndStatusPredicate.status);
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return new ToStringBuilder(this)
46+
.add("address", address)
47+
.add("status", status)
48+
.toString();
49+
}
50+
}

src/main/java/seedu/address/model/person/StatusContainsKeywordsPredicate.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)