From 78e71df9a8e5d019adb33ba671a2d09070e3f893 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Tue, 25 Sep 2018 11:28:23 +0800 Subject: [PATCH 1/8] changed parameters for person class and created a patrol resource class --- OffenceList.txt | 26 +++++++ src/seedu/addressbook/Main.java | 2 +- .../addressbook/commands/AddCommand.java | 29 ++++--- .../addressbook/data/PoliceOfficers/Case.java | 44 +++++++++++ .../data/PoliceOfficers/PatrolID.java | 52 +++++++++++++ .../data/PoliceOfficers/PatrolResource.java | 75 +++++++++++++++++++ .../ReadOnlyPatrolResource.java | 42 +++++++++++ .../data/PoliceOfficers/State.java | 47 ++++++++++++ src/seedu/addressbook/data/person/NRIC.java | 2 +- .../addressbook/data/person/Offense.java | 50 +++++++++++++ src/seedu/addressbook/data/person/Person.java | 46 ++++++------ .../data/person/ReadOnlyPerson.java | 57 ++++++-------- src/seedu/addressbook/data/person/Status.java | 62 +++++++++++++++ src/seedu/addressbook/parser/Parser.java | 24 +++--- .../storage/jaxb/AdaptedPerson.java | 40 +++++----- .../addressbook/storage/jaxb/AdaptedTag.java | 13 ++-- 16 files changed, 492 insertions(+), 119 deletions(-) create mode 100644 OffenceList.txt create mode 100644 src/seedu/addressbook/data/PoliceOfficers/Case.java create mode 100644 src/seedu/addressbook/data/PoliceOfficers/PatrolID.java create mode 100644 src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java create mode 100644 src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java create mode 100644 src/seedu/addressbook/data/PoliceOfficers/State.java create mode 100644 src/seedu/addressbook/data/person/Offense.java create mode 100644 src/seedu/addressbook/data/person/Status.java diff --git a/OffenceList.txt b/OffenceList.txt new file mode 100644 index 000000000..513eff1a2 --- /dev/null +++ b/OffenceList.txt @@ -0,0 +1,26 @@ +abetment +accident +unsound +piracy +rioting +dispute +drug offences +homicide +murder +manslaughter +fire +suicide +attempted suicide +assault +kidnap +outrage of modesty +rape +robbery +gunman +hostage +cheating +house-break +corruption +wanted +chemical attack + diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index fca4d5d1d..03481ce4c 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -14,7 +14,7 @@ public class Main extends Application implements Stoppable{ /** Version info of the program. */ - public static final String VERSION = "AddressBook Level 3 - Version 1.0"; + public static final String VERSION = "EX-SI-53 - Version 1.0"; private Gui gui; diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index 78ad0da21..dbbadc82a 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -14,11 +14,10 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the address book. " - + "Contact details can be marked private by prepending 'p' to the prefix.\n\t" - + "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n\t" + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the system. " + + "Parameters: NAME n/NRIC p/POSTALCODE s/STATUS [o/PASTOFFENSES]...\n\t" + "Example: " + COMMAND_WORD - + " John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; + + " John Doe n/s1234567a p/510246 s/excon o/theft o/drugs"; public static final String MESSAGE_SUCCESS = "New person added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; @@ -31,20 +30,20 @@ public class AddCommand extends Command { * @throws IllegalValueException if any of the raw values are invalid */ public AddCommand(String name, - String phone, boolean isPhonePrivate, - String email, boolean isEmailPrivate, - String address, boolean isAddressPrivate, - Set tags) throws IllegalValueException { - final Set tagSet = new HashSet<>(); - for (String tagName : tags) { - tagSet.add(new Tag(tagName)); + String nric, + String postalCode, + String status, + Set pastOffenses) throws IllegalValueException { + final Set pastOffenseSet = new HashSet<>(); + for (String offenseName : pastOffenses) { + pastOffenseSet.add(new Offense(offenseName)); } this.toAdd = new Person( new Name(name), - new Phone(phone, isPhonePrivate), - new Email(email, isEmailPrivate), - new Address(address, isAddressPrivate), - tagSet + new NRIC(nric), + new PostalCode(postalCode), + new Status(status), + pastOffenseSet ); } diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java new file mode 100644 index 000000000..69b41d716 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -0,0 +1,44 @@ +package seedu.addressbook.data.PoliceOfficers; + +import seedu.addressbook.data.exception.IllegalValueException; + +import java.sql.Timestamp; +import java.time.Instant; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Case { + + public static final String EXAMPLE_CASE = "PO3, robbery, GPS coordinates, timestamp"; + public static final String MESSAGE_CASE_CONSTRAINTS = "Case must have: PatrolID, message, GPS, timestamp"; + + public static final PatrolID attendingPO; + public String caseMessage; + //public GPS coordinates; + public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); + public static final String caseDateTime; + + private String SPACE = ", "; + public String value; + + public Case(){ + this.attendingPO = null; + this.caseMessage = "none"; + //this.GPS = null + this.caseDateTime = null; + } + public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime) throws IllegalValueException{ + if (!isValidCase){ + throw new IllegalValueException(MESSAGE_CASE_CONSTRAINTS); + } + this.attendingPO = patrolIDNo; + this.caseMessage = message; + //this.GPSCoordinates = GPS; + this.caseDateTime = dateFormat.format(dateTime); + this.value = patrolIDNo.patrolID + SPACE + caseMessage + SPACE + /*GPS*/ caseDateTime; + + } + + public static boolean isValidCase() //to be confirmed + +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java new file mode 100644 index 000000000..df4239d42 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java @@ -0,0 +1,52 @@ +package seedu.addressbook.data.PoliceOfficers; + +import seedu.addressbook.data.exception.IllegalValueException; + +/** + * Represents a Patrol resource's ID in EX-SI-53. + * Guarantees: immutable; is valid as declared in {@link #isValidID(int)} + */ + +public class PatrolID { + public static final String EXAMPLE = "PO1"; + public static final String MESSAGE_ID_CONSTRAINTS = "Patrol ID has to be a number excluding 0, and must not be an existing ID"; + public static final String PATROL_ID_PREFIX = "PO"; + public static final int CONSTRAINT = 0; + + public final int ID; + public final String patrolID; + + public PatrolID (int identification) throws IllegalValueException{ + if (!isValidID(identification)){ + throw new IllegalValueException(MESSAGE_ID_CONSTRAINTS); + } + this.ID = identification; + this.patrolID = PATROL_ID_PREFIX + Integer.toString(identification); + } + + /** + * Validates given ID. + * + * @throws IllegalValueException if given ID is invalid. + */ + + public static boolean isValidID(int test) {return test > CONSTRAINT; } + + @Override + public String toString() { + return patrolID; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof PatrolID // instanceof handles nulls + && this.patrolID.equals(((PatrolID) other).patrolID)); // state check + } + + @Override + public int hashCode() { + return patrolID.hashCode(); + } + +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java new file mode 100644 index 000000000..0a9d13087 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java @@ -0,0 +1,75 @@ +package seedu.addressbook.data.PoliceOfficers; + + +/** + * Represents a Patrol Resource in the system. + * Guarantees: details are present and not null, field values are validated. + */ +public class PatrolResource { + public PatrolID patrolID; + public State state; + public Case currentCase; + + + /** + * Assumption: Every field must be present and not null (except current case). + */ + public PatrolResource(PatrolID patrolID, State state, Case currentCase) { + this.patrolID = patrolID; + this.state = state; + this.currentCase = (state.currentState == state.FREE) ? new Case() : currentCase; + } + + public PatrolResource(ReadOnlyPatrolResource source) { + this(source.getPatrolID(), source.getState(), source.getCurrentCase()); + } + + public Case RA(){ + //would generate timestamp and GPS + //sent to HQP 'inbox' + } + + public Case RB(){ + //would generate timestamp and GPS + //sent to HQP 'inbox' + } + + public Case RF(){ + //would generate timestamp and GPS + //sent to HQP 'inbox' + } + + @Override + public PatrolID getPatrolID() { + return patrolID; + } + + @Override + public State getState() { + return state; + } + + @Override + public Case getCurrentCase() { + return currentCase; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReadOnlyPatrolResource // instanceof handles nulls + && this.isSameStateAs((ReadOnlyPatrolResource) other)); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(patrolID, state, currentCase); + } + + @Override + public String toString() { + return getAsTextShowAll(); + } + +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java new file mode 100644 index 000000000..a9bcf9841 --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java @@ -0,0 +1,42 @@ +package seedu.addressbook.data.PoliceOfficers; + + +/** + * A read-only immutable interface for a Patrol Resource in the system. + * Implementations should guarantee: details are present and not null, field values are validated. + */ +public interface ReadOnlyPatrolResource { + + PatrolID getPatrolID(); + State getState(); + Case getCurrentCase(); + Case RA(); //request ambulance + Case RB(); //request backup, can be other POs or can be enhanced like SWAT + Case RF(); //request fire fighters + + + /** + * Returns true if the values inside this object is same as those of the other (Note: interfaces cannot override .equals) + */ + default boolean isSameStateAs(ReadOnlyPatrolResource other) { + return other == this // short circuit if same object + || (other != null // this is first to avoid NPE below + && other.getPatrolID().equals(this.getPatrolID()) // state checks here onwards + && other.getState().equals(this.getState()) + && other.getCurrentCase().equals(this.getCurrentCase())); + + } + + + /** + * Formats a patrol resource as text, showing all details. + */ + default String getAsTextHidePrivate() { + final StringBuilder builder = new StringBuilder(); + builder.append(" Patrol ID: ").append(getPatrolID()); + builder.append(" State: ").append(getState()); + builder.append(" Current Case: ").append(getCurrentCase()); + + return builder.toString(); + } +} diff --git a/src/seedu/addressbook/data/PoliceOfficers/State.java b/src/seedu/addressbook/data/PoliceOfficers/State.java new file mode 100644 index 000000000..988b34c9d --- /dev/null +++ b/src/seedu/addressbook/data/PoliceOfficers/State.java @@ -0,0 +1,47 @@ +package seedu.addressbook.data.PoliceOfficers; + +import seedu.addressbook.data.exception.IllegalValueException; + +/** + * Represents a Patrol resource's current state in EX-SI-53. + * Guarantees: only 2 possible states; is valid as declared in {@link #isValidState(String)} + */ + +public class State { + + public static final String EXAMPLE_STATE = "free"; + public static final String MESSAGE_STATE_CONSTRAINTS = "Patrol resource can either be 'free' or 'engaged'"; + public static final String FREE = "free"; + public static final String ENGAGED = "engaged"; + public static final String DEFAULT_CASE = "none"; + public String currentState; + + + public State(String state) throws IllegalValueException{ + state = state.trim(); + if (!isValidState(state)){ + throw new IllegalValueException(MESSAGE_STATE_CONSTRAINTS); + } + this.currentState = state; + } + + public boolean isValidState(String test) {return test == FREE || test == ENGAGED;} + + @Override + public String toString() { + return currentState; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof PatrolID // instanceof handles nulls + && this.currentState.equals(((State) other).currentState)); // state check + } + + @Override + public int hashCode() { + return currentState.hashCode(); + } + +} diff --git a/src/seedu/addressbook/data/person/NRIC.java b/src/seedu/addressbook/data/person/NRIC.java index 27f620833..d4c29befe 100644 --- a/src/seedu/addressbook/data/person/NRIC.java +++ b/src/seedu/addressbook/data/person/NRIC.java @@ -6,7 +6,7 @@ import java.util.List; /** - * Represents a Person's identification number(NRIC or FIN) in the address book. + * Represents a Person's identification number(NRIC or FIN) in the EX-SI-53. * Guarantees: immutable; is valid as declared in {@link #isValidNRIC(String)} */ diff --git a/src/seedu/addressbook/data/person/Offense.java b/src/seedu/addressbook/data/person/Offense.java new file mode 100644 index 000000000..2b2a5379f --- /dev/null +++ b/src/seedu/addressbook/data/person/Offense.java @@ -0,0 +1,50 @@ +package seedu.addressbook.data.person; + +import seedu.addressbook.data.exception.IllegalValueException; +import java.util.Arrays; + +public class Offense { + public static final String EXAMPLE = "theft"; + public static final String MESSAGE_OFFENSE_CONSTRAINTS = "Offense should be in lower case and must be inside the list"; + + private static final String[] OFFENSE_LIST = {"theft","drugs","riot"}; + + public final String offense; + + /** + * Validates given tag name. + * + * @throws IllegalValueException if the given tag name string is invalid. + */ + public Offense(String name) throws IllegalValueException { + name = name.trim(); + if (!isValidOffense(name)) { + throw new IllegalValueException(MESSAGE_OFFENSE_CONSTRAINTS); + } + this.offense = name; + } + + /** + * Returns true if a given string is a valid tag name. + */ + public static boolean isValidOffense(String test) { + return Arrays.asList(OFFENSE_LIST).contains(test); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Offense // instanceof handles nulls + && this.offense.equals(((Offense) other).offense)); // state check + } + + @Override + public int hashCode() { + return offense.hashCode(); + } + + @Override + public String toString() { + return '[' + offense + ']'; + } +} diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index fdd99358b..eaa55afd1 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -7,33 +7,33 @@ import seedu.addressbook.data.tag.Tag; /** - * Represents a Person in the address book. + * Represents a Person in the system. * Guarantees: details are present and not null, field values are validated. */ public class Person implements ReadOnlyPerson { private Name name; - private Phone phone; - private Email email; - private Address address; + private NRIC nric; + private Status status; + private PostalCode postalCode; - private final Set tags = new HashSet<>(); + private final Set PastOffense = new HashSet<>(); /** * Assumption: Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { + public Person(Name name, NRIC nric, PostalCode postalCode, Status status ,Set PastOffense) { this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - this.tags.addAll(tags); + this.nric = nric; + this.postalCode = postalCode; + this.status = status; + this.PastOffense.addAll(PastOffense); } /** * Copy constructor. */ public Person(ReadOnlyPerson source) { - this(source.getName(), source.getPhone(), source.getEmail(), source.getAddress(), source.getTags()); + this(source.getName(), source.getNRIC(), source.getPostalCode(), source.getStatus(), source.getPastOffense()); } @Override @@ -42,31 +42,29 @@ public Name getName() { } @Override - public Phone getPhone() { - return phone; + public NRIC getNRIC() { + return nric; } @Override - public Email getEmail() { - return email; + public PostalCode getPostalCode() { + return postalCode; } @Override - public Address getAddress() { - return address; + public Status getStatus() { + return status; } @Override - public Set getTags() { - return new HashSet<>(tags); - } + public Set getPastOffense() {return PastOffense;} /** * Replaces this person's tags with the tags in {@code replacement}. */ - public void setTags(Set replacement) { - tags.clear(); - tags.addAll(replacement); + public void setPastOffense(Set replacement) { + PastOffense.clear(); + PastOffense.addAll(replacement); } @Override @@ -79,7 +77,7 @@ public boolean equals(Object other) { @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, nric, postalCode, status, PastOffense); } @Override diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 4fab58808..40da55c77 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -11,15 +11,15 @@ public interface ReadOnlyPerson { Name getName(); - Phone getPhone(); - Email getEmail(); - Address getAddress(); + NRIC getNRIC(); + PostalCode getPostalCode(); + Status getStatus(); /** * The returned {@code Set} is a deep copy of the internal {@code Set}, * changes on the returned list will not affect the person's internal tags. */ - Set getTags(); + Set getPastOffense(); /** * Returns true if the values inside this object is same as those of the other (Note: interfaces cannot override .equals) @@ -28,9 +28,9 @@ default boolean isSameStateAs(ReadOnlyPerson other) { return other == this // short circuit if same object || (other != null // this is first to avoid NPE below && other.getName().equals(this.getName()) // state checks here onwards - && other.getPhone().equals(this.getPhone()) - && other.getEmail().equals(this.getEmail()) - && other.getAddress().equals(this.getAddress())); + && other.getNRIC().equals(this.getNRIC()) + && other.getPostalCode().equals(this.getPostalCode()) + && other.getStatus().equals(this.getStatus())); } /** @@ -40,24 +40,15 @@ default String getAsTextShowAll() { final StringBuilder builder = new StringBuilder(); final String detailIsPrivate = "(private) "; builder.append(getName()) - .append(" Phone: "); - if (getPhone().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getPhone()) + .append(" NRIC: "); + builder.append(getNRIC()) .append(" Email: "); - if (getEmail().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getEmail()) - .append(" Address: "); - if (getAddress().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getAddress()) - .append(" Tags: "); - for (Tag tag : getTags()) { - builder.append(tag); + builder.append(getPostalCode()) + .append(" Postal Code: "); + builder.append(getPostalCode()) + .append(" Past Offenses: "); + for (Offense offense : getPastOffense()) { + builder.append(offense); } return builder.toString(); } @@ -68,18 +59,12 @@ default String getAsTextShowAll() { default String getAsTextHidePrivate() { final StringBuilder builder = new StringBuilder(); builder.append(getName()); - if (!getPhone().isPrivate()) { - builder.append(" Phone: ").append(getPhone()); - } - if (!getEmail().isPrivate()) { - builder.append(" Email: ").append(getEmail()); - } - if (!getAddress().isPrivate()) { - builder.append(" Address: ").append(getAddress()); - } - builder.append(" Tags: "); - for (Tag tag : getTags()) { - builder.append(tag); + builder.append(" NRIC: ").append(getNRIC()); + builder.append(" Postal Code: ").append(getPostalCode()); + builder.append(" Status: ").append(getStatus()); + builder.append(" Past Offenses: "); + for (Offense offense : getPastOffense()) { + builder.append(offense); } return builder.toString(); } diff --git a/src/seedu/addressbook/data/person/Status.java b/src/seedu/addressbook/data/person/Status.java new file mode 100644 index 000000000..d8cffdfb9 --- /dev/null +++ b/src/seedu/addressbook/data/person/Status.java @@ -0,0 +1,62 @@ +package seedu.addressbook.data.person; + +import seedu.addressbook.data.exception.IllegalValueException; + +import java.util.Arrays; + +/** + * Represents a Person's criminal status (if any) in EX-SI-53. + * Guarantees: mutable; is valid as declared in {@link #isValidStatus(String)} + */ + +public class Status { + + public static final String EXAMPLE = "wanted/excon/clear (xc is ex-convict or ex-offender)"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Status should be one of the 3: wanted/xc/clear"; + + private static final String WANTED_KEYWORD = "wanted"; + private static final String EXCONVICT_KEYWORD = "excon"; + private static final String CLEAR_KEYWORD = "clear"; + + private static final String[] STATUS_VALIDATION = {WANTED_KEYWORD,EXCONVICT_KEYWORD,CLEAR_KEYWORD}; + + public final String currentStatus; + + /** + * Validates given Status. + * + * @throws IllegalValueException if given name string is invalid. + */ + public Status(String status) throws IllegalValueException { + status = status.trim(); + if (!isValidStatus(status)) { + throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS); + } + this.currentStatus = status; + } + + /** + * Returns true if a given string is a valid NRIC. + */ + public static boolean isValidStatus(String test) { + return Arrays.asList(STATUS_VALIDATION).contains(test); + } + + @Override + public String toString() { + return currentStatus; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Status // instanceof handles nulls + && this.currentStatus.equals(((Status) other).currentStatus)); // state check + } + + @Override + public int hashCode() { + return currentStatus.hashCode(); + } + +} diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 58f4f7e6c..503560a0e 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -21,10 +21,10 @@ public class Parser { public static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]+)" - + " (?p?)p/(?[^/]+)" - + " (?p?)e/(?[^/]+)" - + " (?p?)a/(?
[^/]+)" - + "(?(?: t/[^/]+)*)"); // variable number of tags + + " n/(?[^/]+)" + + " p/(?[^/]+)" + + " s/(?[^/]+)" + + "(?(?: o/[^/]+)*)"); // variable number of offenses /** @@ -102,17 +102,11 @@ private Command prepareAdd(String args){ try { return new AddCommand( matcher.group("name"), + matcher.group("nric"), + matcher.group("postalCode"), + matcher.group("status"), - matcher.group("phone"), - isPrivatePrefixPresent(matcher.group("isPhonePrivate")), - - matcher.group("email"), - isPrivatePrefixPresent(matcher.group("isEmailPrivate")), - - matcher.group("address"), - isPrivatePrefixPresent(matcher.group("isAddressPrivate")), - - getTagsFromArgs(matcher.group("tagArguments")) + getTagsFromArgs(matcher.group("pastOffenseArguments")) ); } catch (IllegalValueException ive) { return new IncorrectCommand(ive.getMessage()); @@ -136,7 +130,7 @@ private static Set getTagsFromArgs(String tagArguments) throws IllegalVa return Collections.emptySet(); } // replace first delimiter prefix, then split - final Collection tagStrings = Arrays.asList(tagArguments.replaceFirst(" t/", "").split(" t/")); + final Collection tagStrings = Arrays.asList(tagArguments.replaceFirst(" o/", "").split(" o/")); return new HashSet<>(tagStrings); } diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java index 29a46e9fd..6b6cefa5d 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java @@ -28,11 +28,11 @@ private static class AdaptedContactDetail { @XmlElement(required = true) private String name; @XmlElement(required = true) - private AdaptedContactDetail phone; + private AdaptedContactDetail nric; @XmlElement(required = true) - private AdaptedContactDetail email; + private AdaptedContactDetail postalCode; @XmlElement(required = true) - private AdaptedContactDetail address; + private AdaptedContactDetail status; @XmlElement private List tagged = new ArrayList<>(); @@ -51,20 +51,18 @@ public AdaptedPerson() {} public AdaptedPerson(ReadOnlyPerson source) { name = source.getName().fullName; - phone = new AdaptedContactDetail(); - phone.isPrivate = source.getPhone().isPrivate(); - phone.value = source.getPhone().value; + nric = new AdaptedContactDetail(); - email = new AdaptedContactDetail(); - email.isPrivate = source.getEmail().isPrivate(); - email.value = source.getEmail().value; + nric.value = source.getNRIC().identificationNumber; - address = new AdaptedContactDetail(); - address.isPrivate = source.getAddress().isPrivate(); - address.value = source.getAddress().value; + postalCode = new AdaptedContactDetail(); + postalCode.value = source.getPostalCode().postalCode; + + status = new AdaptedContactDetail(); + status.value = source.getStatus().currentStatus; tagged = new ArrayList<>(); - for (Tag tag : source.getTags()) { + for (Offense tag : source.getPastOffense()) { tagged.add(new AdaptedTag(tag)); } } @@ -83,9 +81,9 @@ public boolean isAnyRequiredFieldMissing() { return true; } } - // second call only happens if phone/email/address are all not null - return Utils.isAnyNull(name, phone, email, address) - || Utils.isAnyNull(phone.value, email.value, address.value); + // second call only happens if nric/postalCode/status are all not null + return Utils.isAnyNull(name, nric, postalCode, status) + || Utils.isAnyNull(nric.value, postalCode.value, status.value); } /** @@ -94,14 +92,14 @@ public boolean isAnyRequiredFieldMissing() { * @throws IllegalValueException if there were any data constraints violated in the adapted person */ public Person toModelType() throws IllegalValueException { - final Set tags = new HashSet<>(); + final Set tags = new HashSet<>(); for (AdaptedTag tag : tagged) { tags.add(tag.toModelType()); } final Name name = new Name(this.name); - final Phone phone = new Phone(this.phone.value, this.phone.isPrivate); - final Email email = new Email(this.email.value, this.email.isPrivate); - final Address address = new Address(this.address.value, this.address.isPrivate); - return new Person(name, phone, email, address, tags); + final NRIC nric = new NRIC(this.nric.value); + final PostalCode postalCode = new PostalCode(this.postalCode.value); + final Status status = new Status(this.status.value); + return new Person(name, nric, postalCode, status, tags); } } diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedTag.java b/src/seedu/addressbook/storage/jaxb/AdaptedTag.java index cd5286a36..67c95d816 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedTag.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedTag.java @@ -2,6 +2,7 @@ import seedu.addressbook.common.Utils; import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.person.Offense; import seedu.addressbook.data.tag.Tag; import javax.xml.bind.annotation.XmlValue; @@ -12,7 +13,7 @@ public class AdaptedTag { @XmlValue - public String tagName; + public String offenseName; /** * No-arg constructor for JAXB use. @@ -24,8 +25,8 @@ public AdaptedTag() {} * * @param source future changes to this will not affect the created AdaptedTag */ - public AdaptedTag(Tag source) { - tagName = source.tagName; + public AdaptedTag(Offense source) { + offenseName = source.offense; } /** @@ -37,7 +38,7 @@ public AdaptedTag(Tag source) { * so we check for that. */ public boolean isAnyRequiredFieldMissing() { - return Utils.isAnyNull(tagName); + return Utils.isAnyNull(offenseName); } /** @@ -45,7 +46,7 @@ public boolean isAnyRequiredFieldMissing() { * * @throws IllegalValueException if there were any data constraints violated in the adapted person */ - public Tag toModelType() throws IllegalValueException { - return new Tag(tagName); + public Offense toModelType() throws IllegalValueException { + return new Offense(offenseName); } } From 4f3d359e4fb9c7e6ed45949669a65450125b76a6 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Wed, 26 Sep 2018 15:19:12 +0800 Subject: [PATCH 2/8] just temporarily commiting first --- .../addressbook/commands/AddCommand.java | 8 +- .../addressbook/commands/ViewCommand.java | 4 +- .../addressbook/data/PoliceOfficers/Case.java | 2 +- .../data/PoliceOfficers/PatrolResource.java | 2 +- .../ReadOnlyPatrolResource.java | 2 +- .../data/PoliceOfficers/State.java | 2 + .../addressbook/data/person/DateOfBirth.java | 47 +++++++ src/seedu/addressbook/data/person/NRIC.java | 4 + .../addressbook/data/person/Offense.java | 13 +- src/seedu/addressbook/data/person/Person.java | 24 +++- .../addressbook/data/person/PostalCode.java | 4 + .../data/person/ReadOnlyPerson.java | 37 ++++-- src/seedu/addressbook/data/person/Status.java | 9 +- src/seedu/addressbook/parser/Parser.java | 11 +- .../storage/jaxb/AdaptedPerson.java | 28 ++-- src/seedu/addressbook/ui/Formatter.java | 2 +- test/data/StorageFileTest/ValidData.txt | 22 ++-- .../seedu/addressbook/logic/LogicTest.java | 123 ++++++++++-------- .../seedu/addressbook/parser/ParserTest.java | 85 +++++++----- .../addressbook/storage/StorageFileTest.java | 24 ++-- 20 files changed, 312 insertions(+), 141 deletions(-) create mode 100644 src/seedu/addressbook/data/person/DateOfBirth.java diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index dbbadc82a..66b901ebb 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -15,9 +15,9 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the system. " - + "Parameters: NAME n/NRIC p/POSTALCODE s/STATUS [o/PASTOFFENSES]...\n\t" + + "Parameters: NAME n/NRIC d/DATEOFBIRTH p/POSTALCODE s/STATUS w/WANTEDFOR [o/PASTOFFENSES]...\n\t" + "Example: " + COMMAND_WORD - + " John Doe n/s1234567a p/510246 s/excon o/theft o/drugs"; + + " John Doe n/s1234567a d/1996 p/510246 s/excon w/none o/theft o/drugs"; public static final String MESSAGE_SUCCESS = "New person added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; @@ -31,8 +31,10 @@ public class AddCommand extends Command { */ public AddCommand(String name, String nric, + String dateOfBirth, String postalCode, String status, + String wantedFor, Set pastOffenses) throws IllegalValueException { final Set pastOffenseSet = new HashSet<>(); for (String offenseName : pastOffenses) { @@ -41,8 +43,10 @@ public AddCommand(String name, this.toAdd = new Person( new Name(name), new NRIC(nric), + new DateOfBirth(dateOfBirth), new PostalCode(postalCode), new Status(status), + new Offense(wantedFor), pastOffenseSet ); } diff --git a/src/seedu/addressbook/commands/ViewCommand.java b/src/seedu/addressbook/commands/ViewCommand.java index 1058c4b52..c2707fc8a 100644 --- a/src/seedu/addressbook/commands/ViewCommand.java +++ b/src/seedu/addressbook/commands/ViewCommand.java @@ -8,6 +8,7 @@ * Shows details of the person identified using the last displayed index. * Private contact details are not shown. */ +/** public class ViewCommand extends Command { public static final String COMMAND_WORD = "view"; @@ -32,10 +33,11 @@ public CommandResult execute() { if (!addressBook.containsPerson(target)) { return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); } - return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextHidePrivate())); + return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextShowAll())); } catch (IndexOutOfBoundsException ie) { return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } } } +*/ \ No newline at end of file diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java index 69b41d716..3b04cec72 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/Case.java +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -39,6 +39,6 @@ public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime) throws I } - public static boolean isValidCase() //to be confirmed + public static boolean isValidCase(); //to be confirmed } diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java index 0a9d13087..37ad05a48 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java @@ -17,7 +17,7 @@ public class PatrolResource { public PatrolResource(PatrolID patrolID, State state, Case currentCase) { this.patrolID = patrolID; this.state = state; - this.currentCase = (state.currentState == state.FREE) ? new Case() : currentCase; + this.currentCase = (state.getCurrentState() == state.FREE) ? new Case() : currentCase; } public PatrolResource(ReadOnlyPatrolResource source) { diff --git a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java index a9bcf9841..7d5b4ec0d 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java +++ b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java @@ -31,7 +31,7 @@ default boolean isSameStateAs(ReadOnlyPatrolResource other) { /** * Formats a patrol resource as text, showing all details. */ - default String getAsTextHidePrivate() { + default String getAsTextShowAll() { final StringBuilder builder = new StringBuilder(); builder.append(" Patrol ID: ").append(getPatrolID()); builder.append(" State: ").append(getState()); diff --git a/src/seedu/addressbook/data/PoliceOfficers/State.java b/src/seedu/addressbook/data/PoliceOfficers/State.java index 988b34c9d..bde958785 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/State.java +++ b/src/seedu/addressbook/data/PoliceOfficers/State.java @@ -25,6 +25,8 @@ public State(String state) throws IllegalValueException{ this.currentState = state; } + public String getCurrentState() {return currentState;} + public boolean isValidState(String test) {return test == FREE || test == ENGAGED;} @Override diff --git a/src/seedu/addressbook/data/person/DateOfBirth.java b/src/seedu/addressbook/data/person/DateOfBirth.java new file mode 100644 index 000000000..c97aa7ab6 --- /dev/null +++ b/src/seedu/addressbook/data/person/DateOfBirth.java @@ -0,0 +1,47 @@ +package seedu.addressbook.data.person; + +import seedu.addressbook.data.exception.IllegalValueException; + +import java.util.Calendar; + +/** + * Represents a Person's Date of Birth in the EX-SI-53. + * Guarantees: immutable; is valid as declared in {@link #isValidDateOfBirth(String)} + */ + +public class DateOfBirth { + public static final String EXAMPLE = "1996"; + public static final String MESSAGE_DATE_OF_BIRTH_CONSTRAINTS = "DoB must from 1900 onwards, and less than or equal to current year"; + public static final String DATE_OF_BIRTH_VALIDATION_REGEX = "[1-2][0-9]{3}"; + public final int year = Calendar.getInstance().get(Calendar.YEAR); + public final String birthYear; + + + + + /** + * Validates given DoB. + * + * @throws IllegalValueException if given DoB string is invalid. + */ + + public DateOfBirth(String dob) throws IllegalValueException{ + dob = dob.trim(); + if (!isValidDateOfBirth(dob)){ + throw new IllegalValueException(MESSAGE_DATE_OF_BIRTH_CONSTRAINTS); + } + this.birthYear = dob; + + } + + + public String getDOB() { + return birthYear; + } + + public boolean isValidDateOfBirth(String test) {return test.matches(DATE_OF_BIRTH_VALIDATION_REGEX) && + Integer.parseInt(test) <= year;} + + + +} diff --git a/src/seedu/addressbook/data/person/NRIC.java b/src/seedu/addressbook/data/person/NRIC.java index d4c29befe..9654b0b7d 100644 --- a/src/seedu/addressbook/data/person/NRIC.java +++ b/src/seedu/addressbook/data/person/NRIC.java @@ -31,6 +31,10 @@ public NRIC(String nric) throws IllegalValueException { this.identificationNumber = nric; } + public String getIdentificationNumber() { + return identificationNumber; + } + /** * Returns true if a given string is a valid NRIC. */ diff --git a/src/seedu/addressbook/data/person/Offense.java b/src/seedu/addressbook/data/person/Offense.java index 2b2a5379f..8800b7f1a 100644 --- a/src/seedu/addressbook/data/person/Offense.java +++ b/src/seedu/addressbook/data/person/Offense.java @@ -7,10 +7,21 @@ public class Offense { public static final String EXAMPLE = "theft"; public static final String MESSAGE_OFFENSE_CONSTRAINTS = "Offense should be in lower case and must be inside the list"; - private static final String[] OFFENSE_LIST = {"theft","drugs","riot"}; + private static final String[] OFFENSE_LIST = {"none","theft","drugs","riot","theft1","theft2","theft3","theft4"}; public final String offense; + public String getOffense() { + return offense; + } + + /** + * Default 'offense' when person is not wanted + * + */ + public Offense(){ + this.offense = "none"; + } /** * Validates given tag name. * diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index eaa55afd1..fd733ad6c 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -1,5 +1,6 @@ package seedu.addressbook.data.person; +import java.util.Date; import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -14,18 +15,23 @@ public class Person implements ReadOnlyPerson { private Name name; private NRIC nric; - private Status status; + private DateOfBirth dateOfBirth; private PostalCode postalCode; + private Status status; + private Offense wantedFor; private final Set PastOffense = new HashSet<>(); /** * Assumption: Every field must be present and not null. */ - public Person(Name name, NRIC nric, PostalCode postalCode, Status status ,Set PastOffense) { + public Person(Name name, NRIC nric, DateOfBirth dateOfBirth, PostalCode postalCode, Status status , + Offense wantedFor, Set PastOffense) { this.name = name; this.nric = nric; + this.dateOfBirth = dateOfBirth; this.postalCode = postalCode; this.status = status; + this.wantedFor = (status.getCurrentStatus() != status.WANTED_KEYWORD) ? new Offense() : wantedFor; this.PastOffense.addAll(PastOffense); } @@ -33,7 +39,9 @@ public Person(Name name, NRIC nric, PostalCode postalCode, Status status ,Set getPastOffense() {return PastOffense;} diff --git a/src/seedu/addressbook/data/person/PostalCode.java b/src/seedu/addressbook/data/person/PostalCode.java index ac2e77dff..6db96412b 100644 --- a/src/seedu/addressbook/data/person/PostalCode.java +++ b/src/seedu/addressbook/data/person/PostalCode.java @@ -31,6 +31,10 @@ public PostalCode(String pc) throws IllegalValueException { this.postalCode = pc; } + public String getPostalCode(){ + return postalCode; + } + /** * Returns true if a given string is a valid NRIC. */ diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 40da55c77..5f514a595 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -1,5 +1,6 @@ package seedu.addressbook.data.person; +import java.util.Date; import java.util.Set; import seedu.addressbook.data.tag.Tag; @@ -12,8 +13,10 @@ public interface ReadOnlyPerson { Name getName(); NRIC getNRIC(); + DateOfBirth getDateOfBirth(); PostalCode getPostalCode(); Status getStatus(); + Offense getWantedFor(); /** * The returned {@code Set} is a deep copy of the internal {@code Set}, @@ -29,8 +32,10 @@ default boolean isSameStateAs(ReadOnlyPerson other) { || (other != null // this is first to avoid NPE below && other.getName().equals(this.getName()) // state checks here onwards && other.getNRIC().equals(this.getNRIC()) + && other.getDateOfBirth().equals((this.getDateOfBirth())) && other.getPostalCode().equals(this.getPostalCode()) - && other.getStatus().equals(this.getStatus())); + && other.getStatus().equals(this.getStatus()) + && other.getWantedFor().equals(this.getWantedFor())); } /** @@ -38,15 +43,18 @@ default boolean isSameStateAs(ReadOnlyPerson other) { */ default String getAsTextShowAll() { final StringBuilder builder = new StringBuilder(); - final String detailIsPrivate = "(private) "; builder.append(getName()) .append(" NRIC: "); builder.append(getNRIC()) - .append(" Email: "); - builder.append(getPostalCode()) + .append(" DateOfBirth: "); + builder.append(getDateOfBirth()) .append(" Postal Code: "); builder.append(getPostalCode()) - .append(" Past Offenses: "); + .append(" Status: "); + builder.append(getStatus()) + .append(" Wanted For: "); + builder.append(getWantedFor()) + .append(" Past Offences:"); for (Offense offense : getPastOffense()) { builder.append(offense); } @@ -56,16 +64,25 @@ default String getAsTextShowAll() { /** * Formats a person as text, showing only non-private contact details. */ + /** default String getAsTextHidePrivate() { final StringBuilder builder = new StringBuilder(); - builder.append(getName()); - builder.append(" NRIC: ").append(getNRIC()); - builder.append(" Postal Code: ").append(getPostalCode()); - builder.append(" Status: ").append(getStatus()); - builder.append(" Past Offenses: "); + builder.append(getName()) + .append(" NRIC: "); + builder.append(getNRIC()) + .append(" DateOfBirth: "); + builder.append(getDateOfBirth()) + .append(" Postal Code"); + builder.append(getPostalCode()) + .append(" Status: "); + builder.append(getStatus()) + .append(" Wanted For: "); + builder.append(getWantedFor()) + .append(" Past Offences:"); for (Offense offense : getPastOffense()) { builder.append(offense); } return builder.toString(); } + */ } diff --git a/src/seedu/addressbook/data/person/Status.java b/src/seedu/addressbook/data/person/Status.java index d8cffdfb9..96e271228 100644 --- a/src/seedu/addressbook/data/person/Status.java +++ b/src/seedu/addressbook/data/person/Status.java @@ -11,10 +11,10 @@ public class Status { - public static final String EXAMPLE = "wanted/excon/clear (xc is ex-convict or ex-offender)"; + public static final String EXAMPLE = "wanted"; public static final String MESSAGE_NAME_CONSTRAINTS = "Status should be one of the 3: wanted/xc/clear"; - private static final String WANTED_KEYWORD = "wanted"; + public static final String WANTED_KEYWORD = "wanted"; private static final String EXCONVICT_KEYWORD = "excon"; private static final String CLEAR_KEYWORD = "clear"; @@ -35,9 +35,12 @@ public Status(String status) throws IllegalValueException { this.currentStatus = status; } + public String getCurrentStatus() {return currentStatus;} + /** - * Returns true if a given string is a valid NRIC. + * Returns true if a given string is a valid Status. */ + public static boolean isValidStatus(String test) { return Arrays.asList(STATUS_VALIDATION).contains(test); } diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 503560a0e..00ff811df 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -22,8 +22,10 @@ public class Parser { public static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]+)" + " n/(?[^/]+)" + + " d/(?[^/]+)" + " p/(?[^/]+)" + " s/(?[^/]+)" + + " w/(?[^/]+)" + "(?(?: o/[^/]+)*)"); // variable number of offenses @@ -72,8 +74,9 @@ public Command parseCommand(String userInput) { case ListCommand.COMMAND_WORD: return new ListCommand(); - case ViewCommand.COMMAND_WORD: + /**case ViewCommand.COMMAND_WORD: return prepareView(arguments); + */ case ViewAllCommand.COMMAND_WORD: return prepareViewAll(arguments); @@ -103,8 +106,10 @@ private Command prepareAdd(String args){ return new AddCommand( matcher.group("name"), matcher.group("nric"), + matcher.group("dateOfBirth"), matcher.group("postalCode"), matcher.group("status"), + matcher.group("wantedFor"), getTagsFromArgs(matcher.group("pastOffenseArguments")) ); @@ -160,10 +165,10 @@ private Command prepareView(String args) { try { final int targetIndex = parseArgsAsDisplayedIndex(args); - return new ViewCommand(targetIndex); + return new ViewAllCommand(targetIndex); } catch (ParseException | NumberFormatException e) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, - ViewCommand.MESSAGE_USAGE)); + ViewAllCommand.MESSAGE_USAGE)); } } diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java index 6b6cefa5d..66ded3f58 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java @@ -8,10 +8,7 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlValue; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * JAXB-friendly adapted person data holder class. @@ -30,9 +27,13 @@ private static class AdaptedContactDetail { @XmlElement(required = true) private AdaptedContactDetail nric; @XmlElement(required = true) + private AdaptedContactDetail dateOfBirth; + @XmlElement(required = true) private AdaptedContactDetail postalCode; @XmlElement(required = true) private AdaptedContactDetail status; + @XmlElement(required = true) + private AdaptedContactDetail wantedFor; @XmlElement private List tagged = new ArrayList<>(); @@ -52,14 +53,19 @@ public AdaptedPerson(ReadOnlyPerson source) { name = source.getName().fullName; nric = new AdaptedContactDetail(); + nric.value = source.getNRIC().getIdentificationNumber(); - nric.value = source.getNRIC().identificationNumber; + dateOfBirth = new AdaptedContactDetail(); + dateOfBirth.value = source.getDateOfBirth().getDOB(); postalCode = new AdaptedContactDetail(); - postalCode.value = source.getPostalCode().postalCode; + postalCode.value = source.getPostalCode().getPostalCode(); status = new AdaptedContactDetail(); - status.value = source.getStatus().currentStatus; + status.value = source.getStatus().getCurrentStatus(); + + wantedFor = new AdaptedContactDetail(); + wantedFor.value = source.getWantedFor().getOffense(); tagged = new ArrayList<>(); for (Offense tag : source.getPastOffense()) { @@ -82,8 +88,8 @@ public boolean isAnyRequiredFieldMissing() { } } // second call only happens if nric/postalCode/status are all not null - return Utils.isAnyNull(name, nric, postalCode, status) - || Utils.isAnyNull(nric.value, postalCode.value, status.value); + return Utils.isAnyNull(name, nric, dateOfBirth, postalCode, status, wantedFor) + || Utils.isAnyNull(nric.value, dateOfBirth.value, postalCode.value, status.value, wantedFor.value); } /** @@ -98,8 +104,10 @@ public Person toModelType() throws IllegalValueException { } final Name name = new Name(this.name); final NRIC nric = new NRIC(this.nric.value); + final DateOfBirth dateOfBirth = new DateOfBirth(this.dateOfBirth.value); final PostalCode postalCode = new PostalCode(this.postalCode.value); final Status status = new Status(this.status.value); - return new Person(name, nric, postalCode, status, tags); + final Offense wantedFor = new Offense(this.wantedFor.value); + return new Person(name, nric, dateOfBirth, postalCode, status, wantedFor, tags); } } diff --git a/src/seedu/addressbook/ui/Formatter.java b/src/seedu/addressbook/ui/Formatter.java index 635df3f08..ea23b5b30 100644 --- a/src/seedu/addressbook/ui/Formatter.java +++ b/src/seedu/addressbook/ui/Formatter.java @@ -38,7 +38,7 @@ public String format(String... messages) { public String format(List persons) { final List formattedPersons = new ArrayList<>(); for (ReadOnlyPerson person : persons) { - formattedPersons.add(person.getAsTextHidePrivate()); + formattedPersons.add(person.getAsTextShowAll()); } return format(asIndexedList(formattedPersons)); } diff --git a/test/data/StorageFileTest/ValidData.txt b/test/data/StorageFileTest/ValidData.txt index fc6b00df6..35eec5ba3 100644 --- a/test/data/StorageFileTest/ValidData.txt +++ b/test/data/StorageFileTest/ValidData.txt @@ -1,17 +1,19 @@ - John Doe - 98765432 - johnd@gmail.com -
John street, block 123, #01-01
+ Betsy Crowe + g1534567a + 520246 + excon + drugs + theft
- Betsy Crowe - 1234567 - betsycrowe@gmail.com -
Newgate Prison
- friend - criminal + John Doe + s1234567a + 510246 + excon + drugs + theft
diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 396fb4bc9..5ee914f18 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -112,9 +112,9 @@ public void execute_exit() throws Exception { @Test public void execute_clear() throws Exception { TestDataHelper helper = new TestDataHelper(); - addressBook.addPerson(helper.generatePerson(1, true)); - addressBook.addPerson(helper.generatePerson(2, true)); - addressBook.addPerson(helper.generatePerson(3, true)); + addressBook.addPerson(helper.generatePerson(1)); + addressBook.addPerson(helper.generatePerson(2)); + addressBook.addPerson(helper.generatePerson(3)); assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, AddressBook.empty(), false, Collections.emptyList()); } @@ -123,25 +123,35 @@ public void execute_clear() throws Exception { public void execute_add_invalidArgsFormat() throws Exception { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); assertCommandBehavior( - "add wrong args wrong args", expectedMessage); + "add wrong args wrong args wrong args", expectedMessage); assertCommandBehavior( - "add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address", expectedMessage); + "add Valid Name s1234567a d/1980 p/123456 s/clear w/none", expectedMessage); assertCommandBehavior( - "add Valid Name p/12345 valid@email.butNoPrefix a/valid, address", expectedMessage); + "add Valid Name n/s1234567a 1980 p/123456 s/clear w/none", expectedMessage); assertCommandBehavior( - "add Valid Name p/12345 e/valid@email.butNoAddressPrefix valid, address", expectedMessage); + "add Valid Name n/s1234567a d/1980 123456 s/clear w/none", expectedMessage); + assertCommandBehavior( + "add Valid Name n/s1234567a d/1980 p/123456 clear w/none", expectedMessage); + assertCommandBehavior( + "add Valid Name n/s1234567a d/1980 123456 s/clear none", expectedMessage); } @Test public void execute_add_invalidPersonData() throws Exception { assertCommandBehavior( - "add []\\[;] p/12345 e/valid@e.mail a/valid, address", Name.MESSAGE_NAME_CONSTRAINTS); + "add []\\[;] n/s1234567a d/1980 p/123456 s/clear w/none", Name.MESSAGE_NAME_CONSTRAINTS); + assertCommandBehavior( + "add Valid Name s123457a d/1980 p/123456 s/clear w/none", NRIC.MESSAGE_NAME_CONSTRAINTS); + assertCommandBehavior( + "add Valid Name n/s1234567a d/188 p/123456 s/clear w/none", DateOfBirth.MESSAGE_DATE_OF_BIRTH_CONSTRAINTS); + assertCommandBehavior( + "add Valid Name n/s1234567a d/1980 p/13456 s/clear w/none", PostalCode.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name p/not_numbers e/valid@e.mail a/valid, address", Phone.MESSAGE_PHONE_CONSTRAINTS); + "add Valid Name n/s1234567a 1980 p/123456 s/not a convict w/none", Status.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name p/12345 e/notAnEmail a/valid, address", Email.MESSAGE_EMAIL_CONSTRAINTS); + "add Valid Name n/s1234567a 1980 p/123456 s/wanted w/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); assertCommandBehavior( - "add Valid Name p/12345 e/valid@e.mail a/valid, address t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); + "add Valid Name n/s1234567a 1980 p/123456 s/excon w/none o/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); } @@ -230,12 +240,13 @@ private void assertInvalidIndexBehaviorForCommand(String commandWord) throws Exc } - @Test + //@Test + /** public void execute_view_onlyShowsNonPrivate() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, true); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = helper.generateAddressBook(lastShownList); helper.addToAddressBook(addressBook, lastShownList); @@ -254,12 +265,12 @@ public void execute_view_onlyShowsNonPrivate() throws Exception { false, lastShownList); } - +*/ @Test public void execute_tryToViewMissingPerson_errorMessage() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = new AddressBook(); @@ -290,8 +301,8 @@ public void execute_viewAll_invalidIndex() throws Exception { @Test public void execute_viewAll_alsoShowsPrivate() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, true); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = helper.generateAddressBook(lastShownList); helper.addToAddressBook(addressBook, lastShownList); @@ -314,8 +325,8 @@ public void execute_viewAll_alsoShowsPrivate() throws Exception { @Test public void execute_tryToViewAllPersonMissingInAddressBook_errorMessage() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, false); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); List lastShownList = helper.generatePersonList(p1, p2); AddressBook expectedAB = new AddressBook(); @@ -346,9 +357,9 @@ public void execute_delete_invalidIndex() throws Exception { @Test public void execute_delete_removesCorrectPerson() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, true); - Person p3 = helper.generatePerson(3, true); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); + Person p3 = helper.generatePerson(3); List threePersons = helper.generatePersonList(p1, p2, p3); @@ -370,9 +381,9 @@ public void execute_delete_removesCorrectPerson() throws Exception { public void execute_delete_missingInAddressBook() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, true); - Person p3 = helper.generatePerson(3, true); + Person p1 = helper.generatePerson(1); + Person p2 = helper.generatePerson(2); + Person p3 = helper.generatePerson(3); List threePersons = helper.generatePersonList(p1, p2, p3); @@ -463,13 +474,15 @@ class TestDataHelper{ Person adam() throws Exception { Name name = new Name("Adam Brown"); - Phone privatePhone = new Phone("111111", true); - Email email = new Email("adam@gmail.com", false); - Address privateAddress = new Address("111, alpha street", true); - Tag tag1 = new Tag("tag1"); - Tag tag2 = new Tag("tag2"); - Set tags = new HashSet<>(Arrays.asList(tag1, tag2)); - return new Person(name, privatePhone, email, privateAddress, tags); + NRIC nric = new NRIC("f1234567j"); + DateOfBirth dateOfBirth = new DateOfBirth("2001"); + PostalCode postalCode = new PostalCode("444444"); + Status status = new Status("excon"); + Offense wantedFor = new Offense(); + Offense tag1 = new Offense("drugs"); + Offense tag2 = new Offense("riot"); + Set tags = new HashSet<>(Arrays.asList(tag1, tag2)); + return new Person(name, nric, dateOfBirth, postalCode, status, wantedFor, tags); } /** @@ -478,15 +491,17 @@ Person adam() throws Exception { * Each unique seed will generate a unique Person object. * * @param seed used to generate the person data field values - * @param isAllFieldsPrivate determines if private-able fields (phone, email, address) will be private + * */ - Person generatePerson(int seed, boolean isAllFieldsPrivate) throws Exception { + Person generatePerson(int seed) throws Exception { return new Person( new Name("Person " + seed), - new Phone("" + Math.abs(seed), isAllFieldsPrivate), - new Email(seed + "@email", isAllFieldsPrivate), - new Address("House of " + seed, isAllFieldsPrivate), - new HashSet<>(Arrays.asList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))) + new NRIC("g999999" + Math.abs(seed) + "t"), + new DateOfBirth(Integer.toString(seed + Integer.parseInt("1901"))), + new PostalCode("77777" + seed), + new Status("excon"), + new Offense(), + new HashSet<>(Arrays.asList(new Offense("theft" + Math.abs(seed)), new Offense("theft" + Math.abs(seed + 1)))) ); } @@ -497,13 +512,15 @@ String generateAddCommand(Person p) { cmd.add("add"); cmd.add(p.getName().toString()); - cmd.add((p.getPhone().isPrivate() ? "pp/" : "p/") + p.getPhone()); - cmd.add((p.getEmail().isPrivate() ? "pe/" : "e/") + p.getEmail()); - cmd.add((p.getAddress().isPrivate() ? "pa/" : "a/") + p.getAddress()); - - Set tags = p.getTags(); - for(Tag t: tags){ - cmd.add("t/" + t.tagName); + cmd.add("n/" + p.getNRIC()); + cmd.add("d/" + p.getDateOfBirth()); + cmd.add("p/" + p.getPostalCode()); + cmd.add("s/" + p.getStatus()); + cmd.add("w/" + p.getWantedFor()); + + Set tags = p.getPastOffense(); + for(Offense t: tags){ + cmd.add("o/" + t.getOffense()); } return cmd.toString(); @@ -568,7 +585,7 @@ List generatePersonList(Boolean... isPrivateStatuses) throws Exception{ List persons = new ArrayList<>(); int i = 1; for(Boolean p: isPrivateStatuses){ - persons.add(generatePerson(i++, p)); + persons.add(generatePerson(i++)); } return persons; } @@ -579,10 +596,12 @@ List generatePersonList(Boolean... isPrivateStatuses) throws Exception{ Person generatePersonWithName(String name) throws Exception { return new Person( new Name(name), - new Phone("1", false), - new Email("1@email", false), - new Address("House of 1", false), - Collections.singleton(new Tag("tag")) + new NRIC("S1234567A"), + new DateOfBirth("2005"), + new PostalCode("123456"), + new Status("excon"), + new Offense(), + Collections.singleton(new Offense("riot")) ); } } diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 5b5f5b013..21b66ba04 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -8,6 +8,7 @@ import seedu.addressbook.data.person.*; import java.util.Arrays; +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -184,12 +185,21 @@ public void addCommand_invalidArgs() { "add", "add ", "add wrong args format", - // no phone prefix - String.format("add $s $s e/$s a/$s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE), - // no email prefix - String.format("add $s p/$s $s a/$s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE), - // no address prefix - String.format("add $s p/$s e/$s $s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE) + // no nric prefix + String.format("add $s $s d/$s p/$s s/$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no dateOfBirth prefix + String.format("add $s n/$s $s p/$s s/$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no postalCode prefix + String.format("add $s n/$s d/$s $s s/$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no status prefix + String.format("add $s n/$s d/$s p/$s /$s w/$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE), + // no offense(for wantedFor) prefix + String.format("add $s n/$s d/$s p/$s s/$s /$s", Name.EXAMPLE, NRIC.EXAMPLE, DateOfBirth.EXAMPLE, PostalCode.EXAMPLE, + Status.EXAMPLE, Offense.EXAMPLE) }; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); @@ -199,25 +209,36 @@ public void addCommand_invalidArgs() { public void addCommand_invalidPersonDataInArgs() { final String invalidName = "[]\\[;]"; final String validName = Name.EXAMPLE; - final String invalidPhoneArg = "p/not__numbers"; - final String validPhoneArg = "p/" + Phone.EXAMPLE; - final String invalidEmailArg = "e/notAnEmail123"; - final String validEmailArg = "e/" + Email.EXAMPLE; - final String invalidTagArg = "t/invalid_-[.tag"; + final String invalidNricArg = "n/not__numbers"; + final String validNricArg = "n/" + NRIC.EXAMPLE; + final String invalidDateOfBirthArg = "d/1000"; + final String validDateOfBirthArg = "d/" + DateOfBirth.EXAMPLE; + final String invalidPostalCodeArg = "p/11234565"; + final String validPostalCode = "p/" + PostalCode.EXAMPLE; + final String invalidStatusArg = "s/not a convict"; + final String validStatusArg = "s/" + Status.EXAMPLE; + final String invalidWantedForArg = "w/no offence"; + final String validWantedForArg = "w/" + Offense.EXAMPLE; + final String invalidTagArg = "o/invalid_-[.tag"; // address can be any string, so no invalid address - final String addCommandFormatString = "add $s $s $s a/" + Address.EXAMPLE; + final String addCommandFormatString = "add $s $s $s $s $s $s"; // test each incorrect person data field argument individually final String[] inputs = { // invalid name - String.format(addCommandFormatString, invalidName, validPhoneArg, validEmailArg), - // invalid phone - String.format(addCommandFormatString, validName, invalidPhoneArg, validEmailArg), - // invalid email - String.format(addCommandFormatString, validName, validPhoneArg, invalidEmailArg), - // invalid tag - String.format(addCommandFormatString, validName, validPhoneArg, validEmailArg) + " " + invalidTagArg + String.format(addCommandFormatString, invalidName, validNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg), + // invalid nric + String.format(addCommandFormatString, validName, invalidNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg), + // invalid dateOfBirth + String.format(addCommandFormatString, validName, validNricArg, invalidDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg), + // invalid postalCode + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, invalidPostalCodeArg, validStatusArg, validWantedForArg), + // invalid status + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, validPostalCode, invalidStatusArg, validWantedForArg), + // invalid wantedFor + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, invalidWantedForArg), + String.format(addCommandFormatString, validName, validNricArg, validDateOfBirthArg, validPostalCode, validStatusArg, validWantedForArg) + " " + invalidTagArg }; for (String input : inputs) { parseAndAssertCommandType(input, IncorrectCommand.class); @@ -236,9 +257,9 @@ public void addCommand_validPersonData_parsedCorrectly() { public void addCommand_duplicateTags_merged() throws IllegalValueException { final Person testPerson = generateTestPerson(); String input = convertPersonToAddCommandString(testPerson); - for (Tag tag : testPerson.getTags()) { + for (Offense tag : testPerson.getPastOffense()) { // create duplicates by doubling each tag - input += " t/" + tag.tagName; + input += " o/" + tag.getOffense(); } final AddCommand result = parseAndAssertCommandType(input, AddCommand.class); @@ -249,10 +270,12 @@ private static Person generateTestPerson() { try { return new Person( new Name(Name.EXAMPLE), - new Phone(Phone.EXAMPLE, true), - new Email(Email.EXAMPLE, false), - new Address(Address.EXAMPLE, true), - new HashSet<>(Arrays.asList(new Tag("tag1"), new Tag("tag2"), new Tag("tag3"))) + new NRIC(NRIC.EXAMPLE), + new DateOfBirth(DateOfBirth.EXAMPLE), + new PostalCode(PostalCode.EXAMPLE), + new Status(Status.EXAMPLE), + new Offense(Offense.EXAMPLE), + new HashSet<>(Arrays.asList(new Offense("theft"), new Offense("drugs"), new Offense("riot"))) ); } catch (IllegalValueException ive) { throw new RuntimeException("test person data should be valid by definition"); @@ -262,11 +285,13 @@ private static Person generateTestPerson() { private static String convertPersonToAddCommandString(ReadOnlyPerson person) { String addCommand = "add " + person.getName().fullName - + (person.getPhone().isPrivate() ? " pp/" : " p/") + person.getPhone().value - + (person.getEmail().isPrivate() ? " pe/" : " e/") + person.getEmail().value - + (person.getAddress().isPrivate() ? " pa/" : " a/") + person.getAddress().value; - for (Tag tag : person.getTags()) { - addCommand += " t/" + tag.tagName; + + " n/" + person.getNRIC().getIdentificationNumber() + + " d/" + person.getDateOfBirth().getDateOfBirth() + + " p/" + person.getPostalCode().getPostalCode() + + " s/" + person.getStatus().getCurrentStatus() + + " w/" + person.getWantedFor().getOffense(); + for (Offense tag : person.getPastOffense()) { + addCommand += " o/" + tag.getOffense(); } return addCommand; } diff --git a/test/java/seedu/addressbook/storage/StorageFileTest.java b/test/java/seedu/addressbook/storage/StorageFileTest.java index f7d9721db..d0fdcd3f5 100644 --- a/test/java/seedu/addressbook/storage/StorageFileTest.java +++ b/test/java/seedu/addressbook/storage/StorageFileTest.java @@ -13,11 +13,7 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.person.Address; -import seedu.addressbook.data.person.Email; -import seedu.addressbook.data.person.Name; -import seedu.addressbook.data.person.Person; -import seedu.addressbook.data.person.Phone; +import seedu.addressbook.data.person.*; import seedu.addressbook.data.tag.Tag; import seedu.addressbook.storage.StorageFile.StorageOperationException; import static seedu.addressbook.util.TestUtil.assertTextFilesEqual; @@ -97,15 +93,19 @@ private StorageFile getTempStorage() throws Exception { private AddressBook getTestAddressBook() throws Exception { AddressBook ab = new AddressBook(); ab.addPerson(new Person(new Name("John Doe"), - new Phone("98765432", false), - new Email("johnd@gmail.com", false), - new Address("John street, block 123, #01-01", false), + new NRIC("s1234567a"), + new DateOfBirth("1998"), + new PostalCode("510244"), + new Status("clear"), + new Offense(), Collections.emptySet())); ab.addPerson(new Person(new Name("Betsy Crowe"), - new Phone("1234567", true), - new Email("betsycrowe@gmail.com", false), - new Address("Newgate Prison", true), - new HashSet<>(Arrays.asList(new Tag("friend"), new Tag("criminal"))))); + new NRIC("g7654321b"), + new DateOfBirth("2000"), + new PostalCode("123456"), + new Status("wanted"), + new Offense("drugs"), + new HashSet<>(Arrays.asList(new Offense("theft"), new Offense("riot"))))); return ab; } } From de28ef2fa05a1b2d636038b27d539c427929e1c4 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Thu, 27 Sep 2018 11:19:23 +0800 Subject: [PATCH 3/8] edited person class --- .../Case.java | 0 .../PatrolID.java | 0 .../PatrolResource.java | 0 .../ReadOnlyPatrolResource.java | 0 .../State.java | 0 .../addressbook/commands/AddCommand.java | 2 +- .../addressbook/commands/DeleteCommand.java | 6 ++-- .../addressbook/commands/HelpCommand.java | 2 +- .../addressbook/data/person/DateOfBirth.java | 2 +- .../addressbook/data/person/Offense.java | 2 +- src/seedu/addressbook/data/person/Person.java | 36 +++++++++++++------ .../addressbook/data/person/PostalCode.java | 2 +- .../data/person/ReadOnlyPerson.java | 2 +- src/seedu/addressbook/data/person/Status.java | 3 +- test/data/StorageFileTest/ValidData.txt | 24 +++++++------ .../seedu/addressbook/logic/LogicTest.java | 14 ++++---- .../seedu/addressbook/parser/ParserTest.java | 12 +++---- 17 files changed, 62 insertions(+), 45 deletions(-) rename {src/seedu/addressbook/data/PoliceOfficers => PoliceOfficers}/Case.java (100%) rename {src/seedu/addressbook/data/PoliceOfficers => PoliceOfficers}/PatrolID.java (100%) rename {src/seedu/addressbook/data/PoliceOfficers => PoliceOfficers}/PatrolResource.java (100%) rename {src/seedu/addressbook/data/PoliceOfficers => PoliceOfficers}/ReadOnlyPatrolResource.java (100%) rename {src/seedu/addressbook/data/PoliceOfficers => PoliceOfficers}/State.java (100%) diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/PoliceOfficers/Case.java similarity index 100% rename from src/seedu/addressbook/data/PoliceOfficers/Case.java rename to PoliceOfficers/Case.java diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java b/PoliceOfficers/PatrolID.java similarity index 100% rename from src/seedu/addressbook/data/PoliceOfficers/PatrolID.java rename to PoliceOfficers/PatrolID.java diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java b/PoliceOfficers/PatrolResource.java similarity index 100% rename from src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java rename to PoliceOfficers/PatrolResource.java diff --git a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java b/PoliceOfficers/ReadOnlyPatrolResource.java similarity index 100% rename from src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java rename to PoliceOfficers/ReadOnlyPatrolResource.java diff --git a/src/seedu/addressbook/data/PoliceOfficers/State.java b/PoliceOfficers/State.java similarity index 100% rename from src/seedu/addressbook/data/PoliceOfficers/State.java rename to PoliceOfficers/State.java diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index 66b901ebb..4d1de5e50 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -17,7 +17,7 @@ public class AddCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a person to the system. " + "Parameters: NAME n/NRIC d/DATEOFBIRTH p/POSTALCODE s/STATUS w/WANTEDFOR [o/PASTOFFENSES]...\n\t" + "Example: " + COMMAND_WORD - + " John Doe n/s1234567a d/1996 p/510246 s/excon w/none o/theft o/drugs"; + + " John Doe n/s1234567a d/1996 p/510246 s/xc w/none o/theft o/drugs"; public static final String MESSAGE_SUCCESS = "New person added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 1dd78f85e..9f82378c1 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -13,9 +13,9 @@ public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" - + "Deletes the person identified by the index number used in the last person listing.\n\t" - + "Parameters: INDEX\n\t" - + "Example: " + COMMAND_WORD + " 1"; + + "Deletes the person by nric.\n\t" + + "Parameters: NRIC\n\t" + + "Example: " + COMMAND_WORD + " s1234567"; public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index ef2ed7d0e..4e1c257e9 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -16,7 +16,7 @@ public class HelpCommand extends Command { + "\n" + ClearCommand.MESSAGE_USAGE + "\n" + FindCommand.MESSAGE_USAGE + "\n" + ListCommand.MESSAGE_USAGE - + "\n" + ViewCommand.MESSAGE_USAGE + //+ "\n" + ViewCommand.MESSAGE_USAGE + "\n" + ViewAllCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE + "\n" + ExitCommand.MESSAGE_USAGE; diff --git a/src/seedu/addressbook/data/person/DateOfBirth.java b/src/seedu/addressbook/data/person/DateOfBirth.java index c97aa7ab6..fcb973fa4 100644 --- a/src/seedu/addressbook/data/person/DateOfBirth.java +++ b/src/seedu/addressbook/data/person/DateOfBirth.java @@ -24,7 +24,7 @@ public class DateOfBirth { * * @throws IllegalValueException if given DoB string is invalid. */ - + public DateOfBirth(String dob) throws IllegalValueException{ dob = dob.trim(); if (!isValidDateOfBirth(dob)){ diff --git a/src/seedu/addressbook/data/person/Offense.java b/src/seedu/addressbook/data/person/Offense.java index 8800b7f1a..78319a852 100644 --- a/src/seedu/addressbook/data/person/Offense.java +++ b/src/seedu/addressbook/data/person/Offense.java @@ -8,7 +8,7 @@ public class Offense { public static final String MESSAGE_OFFENSE_CONSTRAINTS = "Offense should be in lower case and must be inside the list"; private static final String[] OFFENSE_LIST = {"none","theft","drugs","riot","theft1","theft2","theft3","theft4"}; - + public static final String NULL_OFFENSE = "none"; public final String offense; public String getOffense() { diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index fd733ad6c..e2afa9f60 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -1,10 +1,8 @@ package seedu.addressbook.data.person; -import java.util.Date; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; +import java.util.*; +import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.tag.Tag; /** @@ -20,25 +18,43 @@ public class Person implements ReadOnlyPerson { private Status status; private Offense wantedFor; + public static String WANTED_FOR_WARNING = "State the offence if person's status is wanted"; + private final Set PastOffense = new HashSet<>(); + + /** * Assumption: Every field must be present and not null. */ public Person(Name name, NRIC nric, DateOfBirth dateOfBirth, PostalCode postalCode, Status status , - Offense wantedFor, Set PastOffense) { + Offense wantedFor, Set PastOffense) throws IllegalValueException { this.name = name; this.nric = nric; this.dateOfBirth = dateOfBirth; this.postalCode = postalCode; this.status = status; - this.wantedFor = (status.getCurrentStatus() != status.WANTED_KEYWORD) ? new Offense() : wantedFor; + this.wantedFor = wantedFor; + if ((this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD)) && (this.wantedFor.getOffense().equals(this.wantedFor.NULL_OFFENSE))){ + throw new IllegalValueException(WANTED_FOR_WARNING); + } + + else if (!(this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD))){ + this.wantedFor = new Offense(); + + } + + else{ + + this.wantedFor = wantedFor; + } + System.out.print(" but why "); this.PastOffense.addAll(PastOffense); } /** * Copy constructor. */ - public Person(ReadOnlyPerson source) { + public Person(ReadOnlyPerson source) throws IllegalValueException { this(source.getName(), source.getNRIC(), source.getDateOfBirth(), source.getPostalCode(), source.getStatus(), source.getWantedFor(), source.getPastOffense()); @@ -55,9 +71,7 @@ public NRIC getNRIC() { } @Override - public DateOfBirth getDateOfBirth() { - return dateOfBirth; - } + public DateOfBirth getDateOfBirth() {return dateOfBirth;} @Override public PostalCode getPostalCode() { @@ -95,7 +109,7 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, nric, postalCode, status, PastOffense); + return Objects.hash(name, nric, dateOfBirth, postalCode, status, wantedFor, PastOffense); } @Override diff --git a/src/seedu/addressbook/data/person/PostalCode.java b/src/seedu/addressbook/data/person/PostalCode.java index 6db96412b..382be88ca 100644 --- a/src/seedu/addressbook/data/person/PostalCode.java +++ b/src/seedu/addressbook/data/person/PostalCode.java @@ -13,7 +13,7 @@ public class PostalCode { public static final String EXAMPLE = "510123"; - public static final String MESSAGE_NAME_CONSTRAINTS = "Must be 6 digits long"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Postal Code must be 6 digits long"; public static final String NAME_VALIDATION_REGEX = "[0-9]{6}"; public final String postalCode; diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 5f514a595..11ebdb2dd 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -47,7 +47,7 @@ default String getAsTextShowAll() { .append(" NRIC: "); builder.append(getNRIC()) .append(" DateOfBirth: "); - builder.append(getDateOfBirth()) + builder.append(getDateOfBirth().getDOB()) .append(" Postal Code: "); builder.append(getPostalCode()) .append(" Status: "); diff --git a/src/seedu/addressbook/data/person/Status.java b/src/seedu/addressbook/data/person/Status.java index 96e271228..56451385c 100644 --- a/src/seedu/addressbook/data/person/Status.java +++ b/src/seedu/addressbook/data/person/Status.java @@ -15,7 +15,7 @@ public class Status { public static final String MESSAGE_NAME_CONSTRAINTS = "Status should be one of the 3: wanted/xc/clear"; public static final String WANTED_KEYWORD = "wanted"; - private static final String EXCONVICT_KEYWORD = "excon"; + private static final String EXCONVICT_KEYWORD = "xc"; //ex-convict private static final String CLEAR_KEYWORD = "clear"; private static final String[] STATUS_VALIDATION = {WANTED_KEYWORD,EXCONVICT_KEYWORD,CLEAR_KEYWORD}; @@ -42,6 +42,7 @@ public Status(String status) throws IllegalValueException { */ public static boolean isValidStatus(String test) { + return Arrays.asList(STATUS_VALIDATION).contains(test); } diff --git a/test/data/StorageFileTest/ValidData.txt b/test/data/StorageFileTest/ValidData.txt index 35eec5ba3..b5e23eb54 100644 --- a/test/data/StorageFileTest/ValidData.txt +++ b/test/data/StorageFileTest/ValidData.txt @@ -1,19 +1,21 @@ - - Betsy Crowe - g1534567a - 520246 - excon - drugs - theft - John Doe s1234567a - 510246 - excon - drugs + 1998 + 510244 + clear + none + + + Betsy Crowe + g7654321b + 2000 + 123456 + wanted + drugs + riot theft diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 5ee914f18..c095a5f11 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -141,17 +141,17 @@ public void execute_add_invalidPersonData() throws Exception { assertCommandBehavior( "add []\\[;] n/s1234567a d/1980 p/123456 s/clear w/none", Name.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name s123457a d/1980 p/123456 s/clear w/none", NRIC.MESSAGE_NAME_CONSTRAINTS); + "add Valid Name n/s123457a d/1980 p/123456 s/clear w/none", NRIC.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( "add Valid Name n/s1234567a d/188 p/123456 s/clear w/none", DateOfBirth.MESSAGE_DATE_OF_BIRTH_CONSTRAINTS); assertCommandBehavior( "add Valid Name n/s1234567a d/1980 p/13456 s/clear w/none", PostalCode.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name n/s1234567a 1980 p/123456 s/not a convict w/none", Status.MESSAGE_NAME_CONSTRAINTS); + "add Valid Name n/s1234567a d/1980 p/123456 s/not a convict w/none", Status.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name n/s1234567a 1980 p/123456 s/wanted w/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); + "add Valid Name n/s1234567a d/1980 p/123456 s/wanted w/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); assertCommandBehavior( - "add Valid Name n/s1234567a 1980 p/123456 s/excon w/none o/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); + "add Valid Name n/s1234567a d/1980 p/123456 s/excon w/none o/rob", Offense.MESSAGE_OFFENSE_CONSTRAINTS); } @@ -212,7 +212,7 @@ public void execute_list_showsAllPersons() throws Exception { @Test public void execute_view_invalidArgsFormat() throws Exception { - String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); assertCommandBehavior("view ", expectedMessage); assertCommandBehavior("view arg not number", expectedMessage); } @@ -310,13 +310,13 @@ public void execute_viewAll_alsoShowsPrivate() throws Exception { logic.setLastShownList(lastShownList); assertCommandBehavior("viewall 1", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p1.getAsTextShowAll()), + String.format(ViewAllCommand.MESSAGE_VIEW_PERSON_DETAILS, p1.getAsTextShowAll()), expectedAB, false, lastShownList); assertCommandBehavior("viewall 2", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p2.getAsTextShowAll()), + String.format(ViewAllCommand.MESSAGE_VIEW_PERSON_DETAILS, p2.getAsTextShowAll()), expectedAB, false, lastShownList); diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 21b66ba04..4a29d47db 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -91,17 +91,17 @@ public void deleteCommand_numericArg_indexParsedCorrectly() { assertEquals(result.getTargetIndex(), testIndex); } - @Test + /**@Test public void viewCommand_noArgs() { final String[] inputs = { "view", "view " }; - final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); + final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); - } + }*/ @Test public void viewCommand_argsIsNotSingleNumber() { final String[] inputs = { "view notAnumber ", "view 8*wh12", "view 1 2 3 4 5" }; - final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); + final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); } @@ -109,7 +109,7 @@ public void viewCommand_argsIsNotSingleNumber() { public void viewCommand_numericArg_indexParsedCorrectly() { final int testIndex = 2; final String input = "view " + testIndex; - final ViewCommand result = parseAndAssertCommandType(input, ViewCommand.class); + final ViewAllCommand result = parseAndAssertCommandType(input, ViewAllCommand.class); assertEquals(result.getTargetIndex(), testIndex); } @@ -286,7 +286,7 @@ private static String convertPersonToAddCommandString(ReadOnlyPerson person) { String addCommand = "add " + person.getName().fullName + " n/" + person.getNRIC().getIdentificationNumber() - + " d/" + person.getDateOfBirth().getDateOfBirth() + + " d/" + person.getDateOfBirth().getDOB() + " p/" + person.getPostalCode().getPostalCode() + " s/" + person.getStatus().getCurrentStatus() + " w/" + person.getWantedFor().getOffense(); From ba2a2d179b8aa48aec9fa00b1b80b7c70bef87a3 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Thu, 27 Sep 2018 11:40:55 +0800 Subject: [PATCH 4/8] removed isValidCase method from case class --- PoliceOfficers/Case.java | 11 ++++------- src/seedu/addressbook/data/person/Person.java | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/PoliceOfficers/Case.java b/PoliceOfficers/Case.java index 3b04cec72..06bff3586 100644 --- a/PoliceOfficers/Case.java +++ b/PoliceOfficers/Case.java @@ -14,7 +14,7 @@ public class Case { public static final PatrolID attendingPO; public String caseMessage; - //public GPS coordinates; + public static Location gpsCoordinates; public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); public static final String caseDateTime; @@ -24,13 +24,11 @@ public class Case { public Case(){ this.attendingPO = null; this.caseMessage = "none"; - //this.GPS = null + this.gpsCoordinates = null this.caseDateTime = null; } - public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime) throws IllegalValueException{ - if (!isValidCase){ - throw new IllegalValueException(MESSAGE_CASE_CONSTRAINTS); - } + public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime){ + this.attendingPO = patrolIDNo; this.caseMessage = message; //this.GPSCoordinates = GPS; @@ -39,6 +37,5 @@ public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime) throws I } - public static boolean isValidCase(); //to be confirmed } diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index e2afa9f60..a7378a41f 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -34,7 +34,8 @@ public Person(Name name, NRIC nric, DateOfBirth dateOfBirth, PostalCode postalCo this.postalCode = postalCode; this.status = status; this.wantedFor = wantedFor; - if ((this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD)) && (this.wantedFor.getOffense().equals(this.wantedFor.NULL_OFFENSE))){ + if ((this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD)) && ((this.wantedFor.getOffense().equals(this.wantedFor.NULL_OFFENSE)) || + this.wantedFor == null)){ throw new IllegalValueException(WANTED_FOR_WARNING); } @@ -47,7 +48,6 @@ else if (!(this.status.getCurrentStatus().equals(this.status.WANTED_KEYWORD))){ this.wantedFor = wantedFor; } - System.out.print(" but why "); this.PastOffense.addAll(PastOffense); } From a4e40a5fe0df15b7773bfe905f5a937d19600631 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Thu, 27 Sep 2018 11:56:52 +0800 Subject: [PATCH 5/8] edited case parameters --- .../seedu/addressbook/data/PoliceOfficers}/Case.java | 6 +++--- .../seedu/addressbook/data/PoliceOfficers}/PatrolID.java | 0 .../addressbook/data/PoliceOfficers}/PatrolResource.java | 2 +- .../data/PoliceOfficers}/ReadOnlyPatrolResource.java | 0 .../seedu/addressbook/data/PoliceOfficers}/State.java | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename {PoliceOfficers => src/seedu/addressbook/data/PoliceOfficers}/Case.java (90%) rename {PoliceOfficers => src/seedu/addressbook/data/PoliceOfficers}/PatrolID.java (100%) rename {PoliceOfficers => src/seedu/addressbook/data/PoliceOfficers}/PatrolResource.java (94%) rename {PoliceOfficers => src/seedu/addressbook/data/PoliceOfficers}/ReadOnlyPatrolResource.java (100%) rename {PoliceOfficers => src/seedu/addressbook/data/PoliceOfficers}/State.java (100%) diff --git a/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java similarity index 90% rename from PoliceOfficers/Case.java rename to src/seedu/addressbook/data/PoliceOfficers/Case.java index 06bff3586..10d2625bd 100644 --- a/PoliceOfficers/Case.java +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -12,11 +12,11 @@ public class Case { public static final String EXAMPLE_CASE = "PO3, robbery, GPS coordinates, timestamp"; public static final String MESSAGE_CASE_CONSTRAINTS = "Case must have: PatrolID, message, GPS, timestamp"; - public static final PatrolID attendingPO; + public static PatrolID attendingPO; public String caseMessage; public static Location gpsCoordinates; public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); - public static final String caseDateTime; + public static String caseDateTime; private String SPACE = ", "; public String value; @@ -24,7 +24,7 @@ public class Case { public Case(){ this.attendingPO = null; this.caseMessage = "none"; - this.gpsCoordinates = null + this.gpsCoordinates = null; this.caseDateTime = null; } public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime){ diff --git a/PoliceOfficers/PatrolID.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java similarity index 100% rename from PoliceOfficers/PatrolID.java rename to src/seedu/addressbook/data/PoliceOfficers/PatrolID.java diff --git a/PoliceOfficers/PatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java similarity index 94% rename from PoliceOfficers/PatrolResource.java rename to src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java index 37ad05a48..4a7636e2f 100644 --- a/PoliceOfficers/PatrolResource.java +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java @@ -17,7 +17,7 @@ public class PatrolResource { public PatrolResource(PatrolID patrolID, State state, Case currentCase) { this.patrolID = patrolID; this.state = state; - this.currentCase = (state.getCurrentState() == state.FREE) ? new Case() : currentCase; + this.currentCase = (state.getCurrentState().equals(state.FREE)) ? new Case() : currentCase; } public PatrolResource(ReadOnlyPatrolResource source) { diff --git a/PoliceOfficers/ReadOnlyPatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java similarity index 100% rename from PoliceOfficers/ReadOnlyPatrolResource.java rename to src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java diff --git a/PoliceOfficers/State.java b/src/seedu/addressbook/data/PoliceOfficers/State.java similarity index 100% rename from PoliceOfficers/State.java rename to src/seedu/addressbook/data/PoliceOfficers/State.java From 5e555fbddc2e951148994ecb0ed32907597bd93a Mon Sep 17 00:00:00 2001 From: muhdharun Date: Fri, 28 Sep 2018 11:36:47 +0800 Subject: [PATCH 6/8] can print case now --- .../addressbook/data/PoliceOfficers/Case.java | 45 ++++++++++++++----- .../data/PoliceOfficers/PatrolID.java | 11 +++-- .../data/PoliceOfficers/PatrolResource.java | 13 ++++-- .../ReadOnlyPatrolResource.java | 1 - 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java index 10d2625bd..79c98d3c4 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/Case.java +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -1,11 +1,12 @@ package seedu.addressbook.data.PoliceOfficers; -import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.Location; + +import seedu.addressbook.Location; import java.sql.Timestamp; -import java.time.Instant; -import java.text.SimpleDateFormat; -import java.util.Date; + + public class Case { @@ -15,8 +16,8 @@ public class Case { public static PatrolID attendingPO; public String caseMessage; public static Location gpsCoordinates; - public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); - public static String caseDateTime; + public static Timestamp caseTimeStamp; + private String SPACE = ", "; public String value; @@ -25,17 +26,39 @@ public Case(){ this.attendingPO = null; this.caseMessage = "none"; this.gpsCoordinates = null; - this.caseDateTime = null; + this.caseTimeStamp = null; } - public Case(PatrolID patrolIDNo, String message, /*GPS*/ Date dateTime){ + public Case(PatrolID patrolIDNo, String message, Location location, Timestamp dateTime){ this.attendingPO = patrolIDNo; this.caseMessage = message; - //this.GPSCoordinates = GPS; - this.caseDateTime = dateFormat.format(dateTime); - this.value = patrolIDNo.patrolID + SPACE + caseMessage + SPACE + /*GPS*/ caseDateTime; + this.gpsCoordinates = location; + this.caseTimeStamp = dateTime; + this.value = patrolIDNo.patrolID + SPACE + caseMessage + SPACE + Double.toString(location.getLongitude()) + SPACE + + Double.toString(location.getLatitude()) + SPACE + dateTime; } + public String PrintCase() {return value;} + + public String getAttendingPO(){return attendingPO.patrolID;} + + public String getCaseMessage() {return caseMessage;} + + public String getGpsCoorinates() {return Double.toString(gpsCoordinates.getLongitude()) + SPACE + Double.toString(gpsCoordinates.getLatitude());} + + public Timestamp getCaseTimeStamp() {return caseTimeStamp;} + + /*public static void main(String[] args) { + Location location = new Location(-6.206968,106.751365); + Location origin = new Location(-6.189482, 106.733902); + PatrolID id = new PatrolID(5); + String msg = "Fire"; + Timestamp now = new Timestamp(System.currentTimeMillis()); + Case c = new Case(id,msg,location,now); + System.out.print(c.PrintCase()); + + + }*/ } diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java index df4239d42..e15cd1cb9 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java @@ -11,26 +11,25 @@ public class PatrolID { public static final String EXAMPLE = "PO1"; public static final String MESSAGE_ID_CONSTRAINTS = "Patrol ID has to be a number excluding 0, and must not be an existing ID"; public static final String PATROL_ID_PREFIX = "PO"; - public static final int CONSTRAINT = 0; + //public static final int CONSTRAINT = 0; public final int ID; public final String patrolID; - public PatrolID (int identification) throws IllegalValueException{ - if (!isValidID(identification)){ - throw new IllegalValueException(MESSAGE_ID_CONSTRAINTS); - } + public PatrolID (int identification){ + this.ID = identification; this.patrolID = PATROL_ID_PREFIX + Integer.toString(identification); } + public String getPatrolID() {return patrolID;} /** * Validates given ID. * * @throws IllegalValueException if given ID is invalid. */ - public static boolean isValidID(int test) {return test > CONSTRAINT; } + //public static boolean isValidID(int test) {return test > CONSTRAINT; } @Override public String toString() { diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java index 4a7636e2f..737b8f437 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolResource.java @@ -1,11 +1,13 @@ package seedu.addressbook.data.PoliceOfficers; +import java.util.Objects; + /** * Represents a Patrol Resource in the system. * Guarantees: details are present and not null, field values are validated. */ -public class PatrolResource { +public class PatrolResource implements ReadOnlyPatrolResource { public PatrolID patrolID; public State state; public Case currentCase; @@ -27,29 +29,32 @@ public PatrolResource(ReadOnlyPatrolResource source) { public Case RA(){ //would generate timestamp and GPS //sent to HQP 'inbox' + return new Case(); //dummy line } public Case RB(){ //would generate timestamp and GPS //sent to HQP 'inbox' + return new Case(); } public Case RF(){ //would generate timestamp and GPS //sent to HQP 'inbox' + return new Case(); } - @Override + //@Override public PatrolID getPatrolID() { return patrolID; } - @Override + //@Override public State getState() { return state; } - @Override + //@Override public Case getCurrentCase() { return currentCase; } diff --git a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java index 7d5b4ec0d..d82ba3414 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java +++ b/src/seedu/addressbook/data/PoliceOfficers/ReadOnlyPatrolResource.java @@ -1,6 +1,5 @@ package seedu.addressbook.data.PoliceOfficers; - /** * A read-only immutable interface for a Patrol Resource in the system. * Implementations should guarantee: details are present and not null, field values are validated. From 636fae9fd42f524f33d07bcabf516c9881247da6 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Fri, 28 Sep 2018 12:58:04 +0800 Subject: [PATCH 7/8] changed timestamp to sdf --- .../addressbook/data/PoliceOfficers/Case.java | 16 ++++++++++------ .../data/PoliceOfficers/PatrolID.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java index 79c98d3c4..ab96100a9 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/Case.java +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -2,10 +2,10 @@ import seedu.addressbook.Location; -import seedu.addressbook.Location; -import java.sql.Timestamp; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; public class Case { @@ -17,6 +17,8 @@ public class Case { public String caseMessage; public static Location gpsCoordinates; public static Timestamp caseTimeStamp; + public static String caseTimeStampFormatted; + private static final SimpleDateFormat timestampFormatter = new SimpleDateFormat("dd.MM.yyyy.HH.mm.ss"); private String SPACE = ", "; @@ -33,9 +35,9 @@ public Case(PatrolID patrolIDNo, String message, Location location, Timestamp da this.attendingPO = patrolIDNo; this.caseMessage = message; this.gpsCoordinates = location; - this.caseTimeStamp = dateTime; + this.caseTimeStampFormatted = timestampFormatter.format(dateTime); this.value = patrolIDNo.patrolID + SPACE + caseMessage + SPACE + Double.toString(location.getLongitude()) + SPACE + - Double.toString(location.getLatitude()) + SPACE + dateTime; + Double.toString(location.getLatitude()) + SPACE + timestampFormatter.format(dateTime); } @@ -49,7 +51,9 @@ public Case(PatrolID patrolIDNo, String message, Location location, Timestamp da public Timestamp getCaseTimeStamp() {return caseTimeStamp;} - /*public static void main(String[] args) { + public String getCaseTimeStampFormatted() {return caseTimeStampFormatted;} + + public static void main(String[] args) { Location location = new Location(-6.206968,106.751365); Location origin = new Location(-6.189482, 106.733902); PatrolID id = new PatrolID(5); @@ -59,6 +63,6 @@ public Case(PatrolID patrolIDNo, String message, Location location, Timestamp da System.out.print(c.PrintCase()); - }*/ + } } diff --git a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java index e15cd1cb9..cf307d963 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java +++ b/src/seedu/addressbook/data/PoliceOfficers/PatrolID.java @@ -4,7 +4,7 @@ /** * Represents a Patrol resource's ID in EX-SI-53. - * Guarantees: immutable; is valid as declared in {@link #isValidID(int)} + * Guarantees: immutable */ public class PatrolID { From 371710f7b886769066506844693dece459e37d04 Mon Sep 17 00:00:00 2001 From: muhdharun Date: Fri, 28 Sep 2018 17:18:57 +0800 Subject: [PATCH 8/8] handles dupicate nrics --- .../addressbook/commands/AddCommand.java | 2 +- src/seedu/addressbook/data/AddressBook.java | 2 +- .../addressbook/data/PoliceOfficers/Case.java | 4 ++-- .../data/person/UniquePersonList.java | 24 ++++++++++++++++--- .../seedu/addressbook/logic/LogicTest.java | 8 +++---- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index 4d1de5e50..b1dd734f5 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -64,7 +64,7 @@ public CommandResult execute() { try { addressBook.addPerson(toAdd); return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); - } catch (UniquePersonList.DuplicatePersonException dpe) { + } catch (UniquePersonList.DuplicateNricException dpe) { return new CommandResult(MESSAGE_DUPLICATE_PERSON); } } diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index ba69c21e3..b4dcf1a8e 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -38,7 +38,7 @@ public AddressBook(UniquePersonList persons) { * * @throws DuplicatePersonException if an equivalent person already exists. */ - public void addPerson(Person toAdd) throws DuplicatePersonException { + public void addPerson(Person toAdd) throws UniquePersonList.DuplicateNricException { allPersons.add(toAdd); } diff --git a/src/seedu/addressbook/data/PoliceOfficers/Case.java b/src/seedu/addressbook/data/PoliceOfficers/Case.java index ab96100a9..02c6da91f 100644 --- a/src/seedu/addressbook/data/PoliceOfficers/Case.java +++ b/src/seedu/addressbook/data/PoliceOfficers/Case.java @@ -53,7 +53,7 @@ public Case(PatrolID patrolIDNo, String message, Location location, Timestamp da public String getCaseTimeStampFormatted() {return caseTimeStampFormatted;} - public static void main(String[] args) { + /*public static void main(String[] args) { Location location = new Location(-6.206968,106.751365); Location origin = new Location(-6.189482, 106.733902); PatrolID id = new PatrolID(5); @@ -63,6 +63,6 @@ public static void main(String[] args) { System.out.print(c.PrintCase()); - } + }*/ } diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index c4848a1b4..5e85a4cc0 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -22,6 +22,12 @@ protected DuplicatePersonException() { } } + public static class DuplicateNricException extends DuplicateDataException { + protected DuplicateNricException() { + super("Operation would result in duplicate NRIC"); + } + } + /** * Signals that an operation targeting a specified person in the list would fail because * there is no such matching person in the list. @@ -35,6 +41,16 @@ public static class PersonNotFoundException extends Exception {} */ public UniquePersonList() {} + + public boolean containNric(Person toCheck) { + for ( Person person : internalList){ + if (person.getNRIC().getIdentificationNumber().equals(toCheck.getNRIC().getIdentificationNumber())){ + return true; + } + } + return false; + } + /** * Constructs a person list with the given persons. */ @@ -82,14 +98,16 @@ public boolean contains(ReadOnlyPerson toCheck) { return internalList.contains(toCheck); } + + /** * Adds a person to the list. * * @throws DuplicatePersonException if the person to add is a duplicate of an existing person in the list. */ - public void add(Person toAdd) throws DuplicatePersonException { - if (contains(toAdd)) { - throw new DuplicatePersonException(); + public void add(Person toAdd) throws DuplicateNricException { + if (contains(toAdd) || containNric(toAdd)) { + throw new DuplicateNricException(); } internalList.add(toAdd); } diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index c095a5f11..d1f281211 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -197,11 +197,11 @@ public void execute_addDuplicate_notAllowed() throws Exception { public void execute_list_showsAllPersons() throws Exception { // prepare expectations TestDataHelper helper = new TestDataHelper(); - AddressBook expectedAB = helper.generateAddressBook(false, true); + AddressBook expectedAB = helper.generateAddressBook(false, false); List expectedList = expectedAB.getAllPersons().immutableListView(); // prepare address book state - helper.addToAddressBook(addressBook, false, true); + helper.addToAddressBook(addressBook, false, false); assertCommandBehavior("list", Command.getMessageForPersonListShownSummary(expectedList), @@ -477,7 +477,7 @@ Person adam() throws Exception { NRIC nric = new NRIC("f1234567j"); DateOfBirth dateOfBirth = new DateOfBirth("2001"); PostalCode postalCode = new PostalCode("444444"); - Status status = new Status("excon"); + Status status = new Status("xc"); Offense wantedFor = new Offense(); Offense tag1 = new Offense("drugs"); Offense tag2 = new Offense("riot"); @@ -499,7 +499,7 @@ Person generatePerson(int seed) throws Exception { new NRIC("g999999" + Math.abs(seed) + "t"), new DateOfBirth(Integer.toString(seed + Integer.parseInt("1901"))), new PostalCode("77777" + seed), - new Status("excon"), + new Status("xc"), new Offense(), new HashSet<>(Arrays.asList(new Offense("theft" + Math.abs(seed)), new Offense("theft" + Math.abs(seed + 1)))) );