Skip to content

Commit

Permalink
Merge pull request #60 from random689/Bugfix_formClass
Browse files Browse the repository at this point in the history
Bugfix form class
  • Loading branch information
g4ryy authored Oct 13, 2021
2 parents 008aa6f + 23729bf commit 32c1e7b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]…​` <br> e.g., `student n/James p/94629424 e/[email protected] 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]…​` <br> e.g., `teacher n/Gabe p/91234567 e/[email protected] 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]…​` <br> e.g., `teacher n/Gabe p/91234567 e/[email protected] g/M o/151 i/Lunch buddy`
**Clear** | `clear`
**Delete** | `delete INDEX`<br> e.g., `delete 3`
**Edit** | `edit<Teacher/Student> INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`<br> e.g.,`editStudent 2 n/James Lee e/[email protected]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -63,6 +65,7 @@ public void resetData(ReadOnlyAddressBook newData) {
*/
public boolean hasPerson(Person person) {
requireNonNull(person);

return persons.contains(person);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/FormClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/seedu/address/model/person/UniquePersonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
*/
public class UniquePersonList implements Iterable<Person> {

private int lastStudentIndex = 0;

private final ObservableList<Person> internalList = FXCollections.observableArrayList();
private final ObservableList<Person> internalUnmodifiableList =
FXCollections.unmodifiableObservableList(internalList);
private int lastStudentIndex = 0;


/**
* Returns true if the list contains an equivalent person as the given argument.
Expand Down Expand Up @@ -106,8 +108,8 @@ public void setPersons(List<Person> persons) {
if (!personsAreUnique(persons)) {
throw new DuplicatePersonException();
}

internalList.setAll(persons);
resetStudentIndex();
}

/**
Expand All @@ -134,6 +136,18 @@ public int hashCode() {
return internalList.hashCode();
}

/**
* Resets the lastStudentIndex to the correct value.
*/
public void resetStudentIndex() {
lastStudentIndex = 0;
for (Person person: internalList) {
if (person instanceof Student) {
lastStudentIndex++;
}
}
}

/**
* Returns true if {@code persons} contains only unique persons.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/seedu/address/model/person/FormClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32c1e7b

Please sign in to comment.