Skip to content

Commit

Permalink
Integrate Resident model
Browse files Browse the repository at this point in the history
 * Update Person model to represent a resident
 * Update ui to show new fields
 * Update sample data
 * Update test cases to new model
 * Add TODOs to commented out testcases, to be handled when dealing with
   the commands
  • Loading branch information
vimuthm committed Oct 5, 2021
1 parent f02abb2 commit e0e3cb4
Show file tree
Hide file tree
Showing 40 changed files with 641 additions and 990 deletions.
9 changes: 6 additions & 3 deletions src/main/java/safeforhall/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ public CommandResult execute(Model model) throws CommandException {
* edited with {@code editPersonDescriptor}.
*/
private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) {
// TODO: Fix
assert personToEdit != null;

Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
// Name updatedRoom = editPersonDescriptor.getRoom().orElse(personToEdit.getRoom());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
// Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
// Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
// return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, null, null, null, null, null, null, null);
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/safeforhall/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class AddCommandParser implements Parser<AddCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
// TODO: Fix
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_PHONE,
CliSyntax.PREFIX_EMAIL, CliSyntax.PREFIX_ADDRESS, CliSyntax.PREFIX_TAG);
Expand All @@ -41,8 +42,10 @@ public AddCommand parse(String args) throws ParseException {
Address address = ParserUtil.parseAddress(argMultimap.getValue(CliSyntax.PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(CliSyntax.PREFIX_TAG));

Person person = new Person(name, phone, email, address, tagList);
// Person person = new Person(name, phone, email, address, tagList);

// TODO
Person person = new Person(null, null, null, null, null, null, null, null);
return new AddCommand(person);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package safeforhall.model.resident;
package safeforhall.model.person;

import static java.util.Objects.requireNonNull;
import static safeforhall.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's address in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)}
* Represents a Person's faculty in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidFaculty(String)} (String)}
*/
public class Faculty {

Expand All @@ -26,14 +26,14 @@ public class Faculty {
*/
public Faculty(String faculty) {
requireNonNull(faculty);
checkArgument(isValidAddress(faculty), MESSAGE_CONSTRAINTS);
checkArgument(isValidFaculty(faculty), MESSAGE_CONSTRAINTS);
this.faculty = faculty;
}

/**
* Returns true if a given string is a valid email.
* Returns true if a given string is a valid faculty.
*/
public static boolean isValidAddress(String test) {
public static boolean isValidFaculty(String test) {
return test.matches(VALIDATION_REGEX);
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/safeforhall/model/person/LastCollectionDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package safeforhall.model.person;

public class LastCollectionDate {

public static final String MESSAGE_CONSTRAINTS = "TODO";

public final String date;

public LastCollectionDate(String date) {
this.date = date;
}

public static boolean isValidCollectionDate(String date) {
return true;
}

public String getDate() {
return date;
}
}
20 changes: 20 additions & 0 deletions src/main/java/safeforhall/model/person/LastFetDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package safeforhall.model.person;

public class LastFetDate {

public static final String MESSAGE_CONSTRAINTS = "TODO";

public final String date;

public LastFetDate(String date) {
this.date = date;
}

public static boolean isValidFetDate(String date) {
return true;
}

public String getDate() {
return date;
}
}
74 changes: 41 additions & 33 deletions src/main/java/safeforhall/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import static safeforhall.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import safeforhall.model.tag.Tag;

/**
* Represents a Person in the address book.
Expand All @@ -17,29 +12,41 @@ public class Person {

// Identity fields
private final Name name;
private final Room room;
private final Phone phone;
private final Email email;

// Data fields
private final Address address;
private final Set<Tag> tags = new HashSet<>();
private final VaccStatus vaccStatus;
private final Faculty faculty;
private final LastFetDate lastFetDate;
private final LastCollectionDate lastCollectionDate;

/**
* Every field must be present and not null.
* Every field must be present and only last 3 can be null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
public Person(Name name, Room room, Phone phone, Email email, VaccStatus vaccStatus,
Faculty faculty, LastFetDate lastFetDate, LastCollectionDate lastCollectionDate) {
// Optionals: faculty, lastFetDate, lastCollectionDate
requireAllNonNull(name, room, phone, email, vaccStatus);
this.name = name;
this.room = room;
this.phone = phone;
this.email = email;
this.address = address;
this.tags.addAll(tags);
this.vaccStatus = vaccStatus;
this.faculty = faculty;
this.lastFetDate = lastFetDate;
this.lastCollectionDate = lastCollectionDate;
}

public Name getName() {
return name;
}

public Room getRoom() {
return room;
}

public Phone getPhone() {
return phone;
}
Expand All @@ -48,20 +55,24 @@ public Email getEmail() {
return email;
}

public Address getAddress() {
return address;
public VaccStatus getVaccStatus() {
return vaccStatus;
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Tag> getTags() {
return Collections.unmodifiableSet(tags);
public Faculty getFaculty() {
return faculty;
}

public LastFetDate getLastFetDate() {
return lastFetDate;
}

public LastCollectionDate getLastCollectionDate() {
return lastCollectionDate;
}

/**
* Returns true if both persons have the same name.
* Returns true if both persons have the same name and room.
* This defines a weaker notion of equality between two persons.
*/
public boolean isSamePerson(Person otherPerson) {
Expand All @@ -70,7 +81,8 @@ public boolean isSamePerson(Person otherPerson) {
}

return otherPerson != null
&& otherPerson.getName().equals(getName());
&& otherPerson.getName().equals(getName())
&& otherPerson.getRoom().equals(getRoom());
}

/**
Expand All @@ -89,34 +101,30 @@ public boolean equals(Object other) {

Person otherPerson = (Person) other;
return otherPerson.getName().equals(getName())
&& otherPerson.getRoom().equals(getRoom())
&& otherPerson.getPhone().equals(getPhone())
&& otherPerson.getEmail().equals(getEmail())
&& otherPerson.getAddress().equals(getAddress())
&& otherPerson.getTags().equals(getTags());
&& otherPerson.getEmail().equals(getEmail());
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, tags);
return Objects.hash(name, room, phone, email, vaccStatus);
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
.append("; Room: ")
.append(getRoom())
.append("; Phone: ")
.append(getPhone())
.append("; Email: ")
.append(getEmail())
.append("; Address: ")
.append(getAddress());
.append("; Vaccinated: ")
.append(getVaccStatus());

Set<Tag> tags = getTags();
if (!tags.isEmpty()) {
builder.append("; Tags: ");
tags.forEach(builder::append);
}
return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package safeforhall.model.resident;
package safeforhall.model.person;

import static java.util.Objects.requireNonNull;
import static safeforhall.commons.util.AppUtil.checkArgument;

/**
* Represents a Resident's room in the address book.
* Represents a Person's room in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidRoom(String)}
*/
public class Room {

public static final String MESSAGE_CONSTRAINTS = "Rooms should not contain spaces and be of the format AXXX:"
public static final String MESSAGE_CONSTRAINTS = "Rooms should not contain spaces and be of the format AXXX: \n"
+ "Character 1: The block, A-E\n"
+ "Character 2: The level, 1-4\n"
+ "Character 3: The room, 0-2\n"
Expand All @@ -23,7 +23,7 @@ public class Room {
* The fourth character of the room must be 0-9
* This check assumes 5 blocks, 4 levels and 30 rooms a level
*/
public static final String VALIDATION_REGEX = "/^[a-eA-E][1-4][0-2][0-9]$";
public static final String VALIDATION_REGEX = "^[a-eA-E][1-4][0-2][0-9]$";

public final String room;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package safeforhall.model.resident;
package safeforhall.model.person;

import static java.util.Objects.requireNonNull;
import static safeforhall.commons.util.AppUtil.checkArgument;

/**
* Represents a Resident's vaccination status in the address book.
* Represents a Person's vaccination status in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidVaccStatus(String)}
*/
public class VaccStatus {
Expand Down
71 changes: 0 additions & 71 deletions src/main/java/safeforhall/model/resident/Email.java

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/safeforhall/model/resident/LastFetDate.java

This file was deleted.

Loading

0 comments on commit e0e3cb4

Please sign in to comment.