forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from victorpengmx/branch-fix-list-commands
Fix list commands
- Loading branch information
Showing
14 changed files
with
211 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/connectify/model/person/PersonNameComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package connectify.model.person; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* Compares a {@code Person} to another using the alphabetical ordering of their {@code Name}. | ||
*/ | ||
public class PersonNameComparator implements Comparator<Person> { | ||
|
||
@Override | ||
public int compare(Person o1, Person o2) { | ||
return o1.compareNameWith(o2); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/connectify/model/person/PersonPriorityComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package connectify.model.person; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* Compares a {@code Person} to another using their {@code Priority}. | ||
*/ | ||
public class PersonPriorityComparator implements Comparator<Person> { | ||
|
||
@Override | ||
public int compare(Person o1, Person o2) { | ||
if (o1.getPriority().getValue() < o2.getPriority().getValue()) { | ||
return 1; | ||
} else if (o1.getPriority().getValue() > o2.getPriority().getValue()) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/java/connectify/model/person/PersonNameComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package connectify.model.person; | ||
|
||
import static connectify.testutil.TypicalPersons.ALICE; | ||
import static connectify.testutil.TypicalPersons.BOB; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Comparator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Compares a {@code Person} to another using the alphabetical ordering of their {@code Name}. | ||
*/ | ||
public class PersonNameComparatorTest { | ||
|
||
@Test | ||
public void compare() { | ||
Comparator<Person> comparator = new PersonNameComparator(); | ||
assertEquals(comparator.compare(ALICE, BOB), -1); | ||
assertEquals(comparator.compare(ALICE, ALICE), 0); | ||
assertEquals(comparator.compare(BOB, ALICE), 1); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/connectify/model/person/PersonPriorityComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package connectify.model.person; | ||
|
||
import static connectify.testutil.TypicalPersons.ALICE; | ||
import static connectify.testutil.TypicalPersons.BOB; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Comparator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Compares a {@code Person} to another using their {@code Priority}. | ||
*/ | ||
public class PersonPriorityComparatorTest { | ||
|
||
@Test | ||
public void compare() { | ||
Comparator<Person> comparator = new PersonPriorityComparator(); | ||
assertEquals(comparator.compare(ALICE, BOB), 1); | ||
assertEquals(comparator.compare(ALICE, ALICE), 0); | ||
assertEquals(comparator.compare(BOB, ALICE), -1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package connectify.testutil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import connectify.logic.commands.CommandTestUtil; | ||
import connectify.model.AddressBook; | ||
import connectify.model.company.Company; | ||
import connectify.model.person.Person; | ||
|
||
/** | ||
* A utility class containing a list of {@code Person} objects to be used in tests. | ||
*/ | ||
public class RankedPersons { | ||
|
||
public static final Person ALICE = new PersonBuilder().withName("Alice Pauline") | ||
.withAddress("123, Jurong West Ave 6, #08-111").withEmail("[email protected]") | ||
.withPhone("94351253") | ||
.withNote("") | ||
.withTags("friends") | ||
.withPriority("1") | ||
.build(); | ||
public static final Person BENSON = new PersonBuilder().withName("Benson Meier") | ||
.withAddress("311, Clementi Ave 2, #02-25") | ||
.withEmail("[email protected]").withPhone("98765432").withNote("") | ||
.withTags("owesMoney", "friends").withPriority("2").build(); | ||
public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563") | ||
.withEmail("[email protected]").withAddress("wall street").withPriority("3").build(); | ||
public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533") | ||
.withEmail("[email protected]").withAddress("10th street").withPriority("4").withTags("friends").build(); | ||
public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224") | ||
.withEmail("[email protected]").withAddress("michegan ave").withPriority("5").build(); | ||
public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427") | ||
.withEmail("[email protected]").withAddress("little tokyo").withPriority("6").build(); | ||
public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442") | ||
.withEmail("[email protected]").withAddress("4th street").withPriority("7").build(); | ||
|
||
// Manually added | ||
public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424") | ||
.withEmail("[email protected]").withAddress("little india").withPriority("7").build(); | ||
public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131") | ||
.withEmail("[email protected]").withAddress("chicago ave").withPriority("8").build(); | ||
|
||
// Manually added - Person's details found in {@code CommandTestUtil} | ||
public static final Person AMY = new PersonBuilder().withName(CommandTestUtil.VALID_NAME_AMY) | ||
.withPhone(CommandTestUtil.VALID_PHONE_AMY).withEmail(CommandTestUtil.VALID_EMAIL_AMY) | ||
.withAddress(CommandTestUtil.VALID_ADDRESS_AMY).withTags(CommandTestUtil.VALID_TAG_FRIEND) | ||
.withPriority(CommandTestUtil.VALID_PRIORITY_AMY).build(); | ||
public static final Person BOB = new PersonBuilder().withName(CommandTestUtil.VALID_NAME_BOB) | ||
.withPhone(CommandTestUtil.VALID_PHONE_BOB).withEmail(CommandTestUtil.VALID_EMAIL_BOB) | ||
.withAddress(CommandTestUtil.VALID_ADDRESS_BOB).withTags(CommandTestUtil.VALID_TAG_HUSBAND, | ||
CommandTestUtil.VALID_TAG_FRIEND).withPriority(CommandTestUtil.VALID_PRIORITY_BOB).build(); | ||
|
||
public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER | ||
|
||
private RankedPersons() {} // prevents instantiation | ||
|
||
/** | ||
* Returns an {@code AddressBook} with all the ranked persons. | ||
*/ | ||
public static AddressBook getRankedAddressBook() { | ||
AddressBook ab = new AddressBook(); | ||
for (Person person : getRankedPersons()) { | ||
ab.addPerson(person); | ||
} | ||
Company company1 = TypicalCompanies.DUMMY_COMPANY; | ||
company1 = company1.addPersonToCompany(ALICE); | ||
company1 = company1.addPersonToCompany(BENSON); | ||
ab.addCompany(company1); | ||
|
||
Company company2 = TypicalCompanies.COMPANY_1; | ||
company2 = company2.addPersonToCompany(CARL); | ||
company2 = company2.addPersonToCompany(DANIEL); | ||
ab.addCompany(company2); | ||
|
||
Company company3 = TypicalCompanies.COMPANY_2; | ||
company3 = company3.addPersonToCompany(DANIEL); | ||
company3 = company3.addPersonToCompany(FIONA); | ||
ab.addCompany(company3); | ||
return ab; | ||
} | ||
|
||
public static List<Person> getRankedPersons() { | ||
return new ArrayList<>(Arrays.asList(GEORGE, FIONA, ELLE, DANIEL, CARL, BENSON, ALICE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters