From 5e4ecb645616409117f2a7481ebe024ff538c4b3 Mon Sep 17 00:00:00 2001 From: random689 Date: Wed, 13 Oct 2021 04:20:33 +0800 Subject: [PATCH 1/6] bugfix for FormClass so it does not see other PREFIX as a FormClass --- src/main/java/seedu/address/model/person/FormClass.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/FormClass.java b/src/main/java/seedu/address/model/person/FormClass.java index de4b03aeb4a..e9acf88053e 100644 --- a/src/main/java/seedu/address/model/person/FormClass.java +++ b/src/main/java/seedu/address/model/person/FormClass.java @@ -16,7 +16,7 @@ public class FormClass { * The first character of FormClass must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ - public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ].*"; public final String value; From ded5bf4f35dd28e17fcd4ae70bea4301299148b8 Mon Sep 17 00:00:00 2001 From: random689 Date: Wed, 13 Oct 2021 05:11:27 +0800 Subject: [PATCH 2/6] bugfix for FormClass so it does not see other PREFIX as a FormClass --- src/main/java/seedu/address/model/person/FormClass.java | 4 ++-- .../java/seedu/address/logic/commands/CommandTestUtil.java | 2 +- src/test/java/seedu/address/logic/parser/ParserUtilTest.java | 2 +- src/test/java/seedu/address/model/person/FormClassTest.java | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/address/model/person/FormClass.java b/src/main/java/seedu/address/model/person/FormClass.java index e9acf88053e..008db2b3489 100644 --- a/src/main/java/seedu/address/model/person/FormClass.java +++ b/src/main/java/seedu/address/model/person/FormClass.java @@ -10,13 +10,13 @@ public class FormClass { public static final String MESSAGE_CONSTRAINTS = - "Form class should only contain alphanumeric characters and spaces, and it should not be blank"; + "Form class can take any values, and it should not be blank"; /* * The first character of FormClass must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ - public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ].*"; + public static final String VALIDATION_REGEX = "[^\\s].*"; public final String value; diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 6eee2569c09..ccb136a6812 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -109,7 +109,7 @@ public class CommandTestUtil { // allowed in phones public static final String INVALID_INVOLVEMENT_DESC = " " + PREFIX_INVOLVEMENT; // empty string not allowed public static final String INVALID_FORM_CLASS_DESC = " " - + PREFIX_FORM_CLASS + "4*1"; // '*' not allowed in form class + + PREFIX_FORM_CLASS + ""; // empty string not allowed public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "d"; //Anything other than M/F/N (not allow) public static final String INVALID_OFFICE_TABLE_DESC = " " + PREFIX_OFFICE_TABLE + "12a"; // 'a' not allowed in // office table number diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 7ef06e32a82..b28c0608896 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -29,7 +29,7 @@ public class ParserUtilTest { private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_TAG = "#friend"; private static final String INVALID_INVOLVEMENT = " "; - private static final String INVALID_FORM_CLASS = "4*1"; + private static final String INVALID_FORM_CLASS = " "; private static final String VALID_NAME = "Rachel Walker"; private static final String VALID_PHONE = "123456"; diff --git a/src/test/java/seedu/address/model/person/FormClassTest.java b/src/test/java/seedu/address/model/person/FormClassTest.java index 616407903ec..57d70401a79 100644 --- a/src/test/java/seedu/address/model/person/FormClassTest.java +++ b/src/test/java/seedu/address/model/person/FormClassTest.java @@ -27,8 +27,6 @@ public void isValidFormClass() { // invalid FormClass assertFalse(FormClass.isValidFormClass("")); // empty string assertFalse(FormClass.isValidFormClass(" ")); // spaces only - assertFalse(FormClass.isValidFormClass("^")); // only non-alphanumeric characters - assertFalse(FormClass.isValidFormClass("4E1*")); // contains non-alphanumeric characters assertFalse(FormClass.isValidFormClass(" 4E1")); // contains whitespace at start // valid FormClass From f5a0c00fc8f19c8dbc24be7dc9145d346cfd613c Mon Sep 17 00:00:00 2001 From: random689 Date: Wed, 13 Oct 2021 12:09:54 +0800 Subject: [PATCH 3/6] bugfix for UniquePersonList where students cannot be added after a clear command --- docs/UserGuide.md | 2 +- src/main/java/seedu/address/model/person/UniquePersonList.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 6b4a70003c9..d3567a17b2b 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -285,7 +285,7 @@ _Details coming soon ..._ Action | Format, Examples --------|------------------ **Student** | `student n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS f/FORM_CLASS g/GENDER i/INVOLVEMENT em/EMERGENCY_NUMBER [m/MEDICAL_HISTORY]…​ [t/TAG]…​`
e.g., `student n/James p/94629424 e/j77@example.com a/George street, block 123, #01-01 f/3A2 g/M i/Math class em/92696977 m/asthma t/representative` -**Teacher** | `teacher n/Name p/PHONE_NUMBER e/EMAIL g/GENDER o/OFFICE_TABLE_NUMBER i/INVOLVEMENT [t/TAG]…​`
e.g., `teacher n/Gabe p/91234567 e/gabe@example.com g/M o/151 i/Lunch buddy` +**Teacher** | `teacher n/NAME p/PHONE_NUMBER e/EMAIL g/GENDER o/OFFICE_TABLE_NUMBER i/INVOLVEMENT [t/TAG]…​`
e.g., `teacher n/Gabe p/91234567 e/gabe@example.com g/M o/151 i/Lunch buddy` **Clear** | `clear` **Delete** | `delete INDEX`
e.g., `delete 3` **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`
e.g.,`editStudent 2 n/James Lee e/jameslee@example.com` diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 9c1814660b7..d2e4f468e85 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -50,6 +50,9 @@ public void add(Person toAdd) { if (toAdd instanceof Teacher) { internalList.add(toAdd); } else if (toAdd instanceof Student) { + if (internalList.size() == 0) { //handles a cleared list + lastStudentIndex = 0; + } internalList.add(lastStudentIndex, toAdd); lastStudentIndex++; } From 205a4852986061662e374779ca18012417dc87b8 Mon Sep 17 00:00:00 2001 From: random689 Date: Wed, 13 Oct 2021 13:42:16 +0800 Subject: [PATCH 4/6] bugfix for UniquePersonList where students cannot be added after a clear command --- .../commands/teacher/AddTeacherCommand.java | 2 +- .../java/seedu/address/model/AddressBook.java | 5 ++++- .../address/model/person/UniquePersonList.java | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java b/src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java index 38edff03366..a0be86c4d9e 100644 --- a/src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java +++ b/src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java @@ -30,7 +30,7 @@ public class AddTeacherCommand extends Command { + PREFIX_GENDER + "GENDER " + PREFIX_OFFICE_TABLE + "OFFICE TABLE NUMBER " + PREFIX_INVOLVEMENT + "INVOLVEMENT " - + "[" + PREFIX_TAG + "TAG]... " + + "[" + PREFIX_TAG + "TAG]... + \n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 1a943a0781a..c5af88af2e4 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -27,7 +27,9 @@ public class AddressBook implements ReadOnlyAddressBook { persons = new UniquePersonList(); } - public AddressBook() {} + public AddressBook() { + persons.resetStudentIndex(); + } /** * Creates an AddressBook using the Persons in the {@code toBeCopied} @@ -63,6 +65,7 @@ public void resetData(ReadOnlyAddressBook newData) { */ public boolean hasPerson(Person person) { requireNonNull(person); + return persons.contains(person); } diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index d2e4f468e85..3b495f0026e 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -27,7 +27,7 @@ public class UniquePersonList implements Iterable { private final ObservableList internalList = FXCollections.observableArrayList(); private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); - private int lastStudentIndex = 0; + private static int lastStudentIndex = 0; /** * Returns true if the list contains an equivalent person as the given argument. @@ -50,12 +50,11 @@ public void add(Person toAdd) { if (toAdd instanceof Teacher) { internalList.add(toAdd); } else if (toAdd instanceof Student) { - if (internalList.size() == 0) { //handles a cleared list - lastStudentIndex = 0; - } internalList.add(lastStudentIndex, toAdd); lastStudentIndex++; } + System.out.println(lastStudentIndex); + System.out.println(internalList.size()); } /** @@ -109,8 +108,8 @@ public void setPersons(List persons) { if (!personsAreUnique(persons)) { throw new DuplicatePersonException(); } - internalList.setAll(persons); + resetStudentIndex(); } /** @@ -137,6 +136,15 @@ public int hashCode() { return internalList.hashCode(); } + public void resetStudentIndex() { + lastStudentIndex = 0; + for (Person person: internalList) { + if (person instanceof Student) { + lastStudentIndex++; + } + } + } + /** * Returns true if {@code persons} contains only unique persons. */ From c5dfbd0bbb716aff9766c6bb85361b5a8502f473 Mon Sep 17 00:00:00 2001 From: random689 Date: Wed, 13 Oct 2021 13:59:36 +0800 Subject: [PATCH 5/6] bugfix for UniquePersonList where students cannot be added after a clear command --- .../java/seedu/address/model/person/UniquePersonList.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 3b495f0026e..23f2a6c1480 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -24,10 +24,12 @@ */ public class UniquePersonList implements Iterable { + private int lastStudentIndex = 0; + private final ObservableList internalList = FXCollections.observableArrayList(); private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); - private static int lastStudentIndex = 0; + /** * Returns true if the list contains an equivalent person as the given argument. @@ -136,6 +138,9 @@ public int hashCode() { return internalList.hashCode(); } + /** + * Resets the lastStudentIndex to the correct value. + */ public void resetStudentIndex() { lastStudentIndex = 0; for (Person person: internalList) { From 23729bfb8af6b6be915b41e7ab887f6b70216063 Mon Sep 17 00:00:00 2001 From: random689 Date: Wed, 13 Oct 2021 14:00:44 +0800 Subject: [PATCH 6/6] bugfix for UniquePersonList where students cannot be added after a clear command --- src/main/java/seedu/address/model/person/UniquePersonList.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 23f2a6c1480..00dbc0ec633 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -55,8 +55,6 @@ public void add(Person toAdd) { internalList.add(lastStudentIndex, toAdd); lastStudentIndex++; } - System.out.println(lastStudentIndex); - System.out.println(internalList.size()); } /**