Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W5][W15-3]Teng Yun #158

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Please refer to the <<DeveloperGuide#setting-up, Setting up>> section to learn h
What's different from AddressBook-Level1:

* Support for storing address (`a/`) and tags (`t/`)
* Support for marking a contact detail as 'private' (`pa/`) (`pe/`) (`pp/`)
* Support for marking a contact detail as 'private' (`pa/`) (`pe/`) (`pp/`) (`pm/`)
* View details of a person (`view` : shows non-private details), (`viewall` : shows all details)

== Viewing help : `help`
Expand All @@ -50,13 +50,13 @@ Help is also shown if you enter an incorrect command e.g. `abcd`
== Adding a person: `add`

Adds a person to the address book. +
Format: `add NAME [p]p/PHONE_NUMBER [p]e/EMAIL [p]a/ADDRESS [t/TAG]...`
Format: `add NAME [p]p/PHONE_NUMBER [p]e/EMAIL [p]a/ADDRESS [p]m/MAJOR [t/TAG]...`

****
Words in `UPPER_CASE` are the parameters, items in `SQUARE_BRACKETS` are optional,
items with `...` after them can have multiple instances. Order of parameters are fixed.

Put a `p` before the phone / email / address prefixes to mark it as `private`. `private` details can only
Put a `p` before the phone / email / address / major prefixes to mark it as `private`. `private` details can only
be seen using the `viewall` command.

Persons can have any number of tags (including 0).
Expand All @@ -65,7 +65,7 @@ Persons can have any number of tags (including 0).
Examples:

* `add John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01`
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison t/criminal t/friend`
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison m/CS t/criminal t/friend`

== Listing all persons : `list`

Expand Down
7 changes: 5 additions & 2 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.Address;
import seedu.addressbook.data.person.Email;
import seedu.addressbook.data.person.Major;
import seedu.addressbook.data.person.Name;
import seedu.addressbook.data.person.Person;
import seedu.addressbook.data.person.Phone;
Expand All @@ -22,9 +23,9 @@ public class AddCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Contact details can be marked private by prepending 'p' to the prefix.\n"
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n"
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [p]m/MAJOR [t/TAG]...\n"
+ "Example: " + COMMAND_WORD
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney";
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 m/CS t/friends t/owesMoney";

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";
Expand All @@ -40,6 +41,7 @@ public AddCommand(String name,
String phone, boolean isPhonePrivate,
String email, boolean isEmailPrivate,
String address, boolean isAddressPrivate,
String major, boolean isMajorPrivate,
Set<String> tags) throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
Expand All @@ -50,6 +52,7 @@ public AddCommand(String name,
new Phone(phone, isPhonePrivate),
new Email(email, isEmailPrivate),
new Address(address, isAddressPrivate),
new Major(major, isMajorPrivate),
tagSet
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly
/**
* Executes the command and returns the result.
*/
public CommandResult execute(){
public CommandResult execute() {
throw new UnsupportedOperationException("This method is to be implemented by child classes");
};
}

;

/**
* Supplies the data the command will operate on.
Expand Down
8 changes: 6 additions & 2 deletions src/seedu/addressbook/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
*/
public class CommandResult {

/** The feedback message to be shown to the user. Contains a description of the execution result */
/**
* The feedback message to be shown to the user. Contains a description of the execution result
*/
public final String feedbackToUser;

/** The list of persons that was produced by the command */
/**
* The list of persons that was produced by the command
*/
private final List<? extends ReadOnlyPerson> relevantPersons;

public CommandResult(String feedbackToUser) {
Expand Down
16 changes: 8 additions & 8 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class HelpCommand extends Command {
public CommandResult execute() {
return new CommandResult(
AddCommand.MESSAGE_USAGE
+ "\n" + DeleteCommand.MESSAGE_USAGE
+ "\n" + ClearCommand.MESSAGE_USAGE
+ "\n" + FindCommand.MESSAGE_USAGE
+ "\n" + ListCommand.MESSAGE_USAGE
+ "\n" + ViewCommand.MESSAGE_USAGE
+ "\n" + ViewAllCommand.MESSAGE_USAGE
+ "\n" + HelpCommand.MESSAGE_USAGE
+ "\n" + ExitCommand.MESSAGE_USAGE
+ "\n" + DeleteCommand.MESSAGE_USAGE
+ "\n" + ClearCommand.MESSAGE_USAGE
+ "\n" + FindCommand.MESSAGE_USAGE
+ "\n" + ListCommand.MESSAGE_USAGE
+ "\n" + ViewCommand.MESSAGE_USAGE
+ "\n" + ViewAllCommand.MESSAGE_USAGE
+ "\n" + HelpCommand.MESSAGE_USAGE
+ "\n" + ExitCommand.MESSAGE_USAGE
);
}
}
2 changes: 1 addition & 1 deletion src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public UniquePersonList getAllPersons() {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddressBook // instanceof handles nulls
&& this.allPersons.equals(((AddressBook) other).allPersons));
&& this.allPersons.equals(((AddressBook) other).allPersons));
}
}
59 changes: 59 additions & 0 deletions src/seedu/addressbook/data/person/Major.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package seedu.addressbook.data.person;

import seedu.addressbook.data.exception.IllegalValueException;

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

public static final String EXAMPLE = "Computing";
public static final String MESSAGE_MAJOR_CONSTRAINTS = "Person addresses can be in any format";
public static final String MAJOR_VALIDATION_REGEX = ".+";

public final String value;
private boolean isPrivate;

/**
* Validates given major.
*
* @throws IllegalValueException if given major string is invalid.
*/
public Major(String major, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
String trimmedMajor = major.trim();
if (!isValidMajor(trimmedMajor)) {
throw new IllegalValueException(MESSAGE_MAJOR_CONSTRAINTS);
}
this.value = trimmedMajor;
}

/**
* Returns true if the given string is a valid person major.
*/
public static boolean isValidMajor(String test) {
return test.matches(MAJOR_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Major // instanceof handles nulls
&& this.value.equals(((Major) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}

public boolean isPrivate() {
return isPrivate;
}
}
15 changes: 9 additions & 6 deletions src/seedu/addressbook/data/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ public class Person implements ReadOnlyPerson {
private Phone phone;
private Email email;
private Address address;
private Major major;

private final Set<Tag> tags = new HashSet<>();

/**
* Assumption: Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
public Person(Name name, Phone phone, Email email, Address address, Major major, Set<Tag> tags) {
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.major = major;
this.tags.addAll(tags);
}

/**
* Copy constructor.
*/
public Person(ReadOnlyPerson source) {
this(source.getName(), source.getPhone(), source.getEmail(), source.getAddress(), source.getTags());
this(source.getName(), source.getPhone(), source.getEmail(), source.getAddress(), source.getMajor(),source.getTags());
}

@Override
Expand All @@ -53,9 +55,10 @@ public Email getEmail() {
}

@Override
public Address getAddress() {
return address;
}
public Address getAddress() { return address; }

@Override
public Major getMajor() { return major; }

@Override
public Set<Tag> getTags() {
Expand All @@ -80,7 +83,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, phone, email, address, major, tags);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface ReadOnlyPerson {
Phone getPhone();
Email getEmail();
Address getAddress();
Major getMajor();

/**
* Returns a new TagSet that is a deep copy of the internal TagSet,
Expand Down Expand Up @@ -42,6 +43,7 @@ default boolean hasSameData(ReadOnlyPerson other) {
&& other.getPhone().equals(this.getPhone())
&& other.getEmail().equals(this.getEmail())
&& other.getAddress().equals(this.getAddress())
&& other.getMajor().equals(this.getMajor())
&& other.getTags().equals(this.getTags()));
}

Expand All @@ -67,6 +69,11 @@ default String getAsTextShowAll() {
builder.append(detailIsPrivate);
}
builder.append(getAddress())
.append(" Major: ");
if (getMajor().isPrivate()) {
builder.append(detailIsPrivate);
}
builder.append(getMajor())
.append(" Tags: ");
for (Tag tag : getTags()) {
builder.append(tag);
Expand All @@ -89,6 +96,9 @@ default String getAsTextHidePrivate() {
if (!getAddress().isPrivate()) {
builder.append(" Address: ").append(getAddress());
}
if (!getMajor().isPrivate()) {
builder.append(" Major: ").append(getMajor());
}
builder.append(" Tags: ");
for (Tag tag : getTags()) {
builder.append(tag);
Expand Down
6 changes: 5 additions & 1 deletion src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Parser {
+ " (?<isPhonePrivate>p?)p/(?<phone>[^/]+)"
+ " (?<isEmailPrivate>p?)e/(?<email>[^/]+)"
+ " (?<isAddressPrivate>p?)a/(?<address>[^/]+)"
+ " (?<isMajorPrivate>p?)m/(?<major>[^/]+)"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags


Expand Down Expand Up @@ -128,6 +129,9 @@ private Command prepareAdd(String args) {
matcher.group("address"),
isPrivatePrefixPresent(matcher.group("isAddressPrivate")),

matcher.group("major"),
isPrivatePrefixPresent(matcher.group("isMajorPrivate")),

getTagsFromArgs(matcher.group("tagArguments"))
);
} catch (IllegalValueException ive) {
Expand Down Expand Up @@ -217,7 +221,7 @@ private Command prepareViewAll(String args) {
*
* @param args arguments string to parse as index number
* @return the parsed index number
* @throws ParseException if no region of the args string could be found for the index
* @throws ParseException if no region of the args string could be found for the index
* @throws NumberFormatException the args string region is not a valid number
*/
private int parseArgsAsDisplayedIndex(String args) throws ParseException, NumberFormatException {
Expand Down
6 changes: 4 additions & 2 deletions src/seedu/addressbook/storage/AddressBookDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.Address;
import seedu.addressbook.data.person.Email;
import seedu.addressbook.data.person.Major;
import seedu.addressbook.data.person.Name;
import seedu.addressbook.data.person.Person;
import seedu.addressbook.data.person.Phone;
Expand All @@ -28,7 +29,7 @@ public class AddressBookDecoder {
/**
* Decodes {@code encodedAddressBook} into an {@code AddressBook} containing the decoded persons.
*
* @throws IllegalValueException if any of the fields in any encoded person string is invalid.
* @throws IllegalValueException if any of the fields in any encoded person string is invalid.
* @throws StorageOperationException if the {@code encodedAddressBook} is in an invalid format.
*/
public static AddressBook decodeAddressBook(List<String> encodedAddressBook)
Expand All @@ -43,7 +44,7 @@ public static AddressBook decodeAddressBook(List<String> encodedAddressBook)
/**
* Decodes {@code encodedPerson} into a {@code Person}.
*
* @throws IllegalValueException if any field in the {@code encodedPerson} is invalid.
* @throws IllegalValueException if any field in the {@code encodedPerson} is invalid.
* @throws StorageOperationException if {@code encodedPerson} is in an invalid format.
*/
private static Person decodePersonFromString(String encodedPerson)
Expand All @@ -58,6 +59,7 @@ private static Person decodePersonFromString(String encodedPerson)
new Phone(matcher.group("phone"), isPrivatePrefixPresent(matcher.group("isPhonePrivate"))),
new Email(matcher.group("email"), isPrivatePrefixPresent(matcher.group("isEmailPrivate"))),
new Address(matcher.group("address"), isPrivatePrefixPresent(matcher.group("isAddressPrivate"))),
new Major(matcher.group("major"), isPrivatePrefixPresent(matcher.group("isMajorPrivate"))),
getTagsFromEncodedPerson(matcher.group("tagArguments"))
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/seedu/addressbook/storage/AddressBookEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private static String encodePersonToString(Person person) {
encodedPersonBuilder.append(person.getAddress().isPrivate() ? " p" : " ");
encodedPersonBuilder.append("a/").append(person.getAddress().value);

encodedPersonBuilder.append(person.getMajor().isPrivate() ? " p" : " ");
encodedPersonBuilder.append("m/").append(person.getMajor().value);

person.getTags().forEach(tag -> encodedPersonBuilder.append(" t/").append(tag.tagName));

return encodedPersonBuilder.toString();
Expand Down
6 changes: 4 additions & 2 deletions src/seedu/addressbook/storage/StorageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
public class StorageFile {

/** Default file path used if the user doesn't provide the file name. */
/**
* Default file path used if the user doesn't provide the file name.
*/
public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt";

/* Note: Note the use of nested classes below.
Expand Down Expand Up @@ -98,7 +100,7 @@ public AddressBook load() throws StorageOperationException {
return AddressBookDecoder.decodeAddressBook(Files.readAllLines(path));
} catch (FileNotFoundException fnfe) {
throw new AssertionError("A non-existent file scenario is already handled earlier.");
// other errors
// other errors
} catch (IOException ioe) {
throw new StorageOperationException("Error writing to file: " + path);
} catch (IllegalValueException ive) {
Expand Down
Loading