From b75d496ac835bf49035070f09487fffd599c9abc Mon Sep 17 00:00:00 2001 From: Sean Yap Date: Sun, 24 Feb 2019 00:17:51 +0800 Subject: [PATCH 1/5] Refactor class and package names to suit "planmysem" --- PlanMySem.txt | 2 +- src/planmysem/commands/Command.java | 6 +- .../data/{AddressBook.java => Planner.java} | 14 +-- src/planmysem/data/person/Person.java | 1 - src/planmysem/data/slot/DateTime.java | 53 ++++++++++ src/planmysem/data/slot/Description.java | 68 +++++++++++++ src/planmysem/data/slot/Location.java | 14 +++ src/planmysem/data/slot/Name.java | 64 ++++++++++++ src/planmysem/data/slot/ReadOnlySlot.java | 91 +++++++++++++++++ src/planmysem/data/slot/Slot.java | 97 +++++++++++++++++++ src/planmysem/logic/Logic.java | 10 +- src/planmysem/storage/StorageFile.java | 8 +- .../storage/jaxb/AdaptedAddressBook.java | 14 +-- src/planmysem/ui/Formatter.java | 2 +- test/java/planmysem/logic/LogicTest.java | 66 ++++++------- .../planmysem/storage/StorageFileTest.java | 18 ++-- 16 files changed, 457 insertions(+), 71 deletions(-) rename src/planmysem/data/{AddressBook.java => Planner.java} (86%) create mode 100644 src/planmysem/data/slot/DateTime.java create mode 100644 src/planmysem/data/slot/Description.java create mode 100644 src/planmysem/data/slot/Location.java create mode 100644 src/planmysem/data/slot/Name.java create mode 100644 src/planmysem/data/slot/ReadOnlySlot.java create mode 100644 src/planmysem/data/slot/Slot.java diff --git a/PlanMySem.txt b/PlanMySem.txt index 81ad97290..ccedbe77c 100644 --- a/PlanMySem.txt +++ b/PlanMySem.txt @@ -1,2 +1,2 @@ - + diff --git a/src/planmysem/commands/Command.java b/src/planmysem/commands/Command.java index 925948b42..c5e276b12 100644 --- a/src/planmysem/commands/Command.java +++ b/src/planmysem/commands/Command.java @@ -5,14 +5,14 @@ import java.util.List; import planmysem.common.Messages; -import planmysem.data.AddressBook; +import planmysem.data.Planner; import planmysem.data.person.ReadOnlyPerson; /** * Represents an executable command. */ public abstract class Command { - protected AddressBook addressBook; + protected Planner addressBook; protected List relevantPersons; private int targetIndex = -1; @@ -49,7 +49,7 @@ public CommandResult execute() { /** * Supplies the data the command will operate on. */ - public void setData(AddressBook addressBook, List relevantPersons) { + public void setData(Planner addressBook, List relevantPersons) { this.addressBook = addressBook; this.relevantPersons = relevantPersons; } diff --git a/src/planmysem/data/AddressBook.java b/src/planmysem/data/Planner.java similarity index 86% rename from src/planmysem/data/AddressBook.java rename to src/planmysem/data/Planner.java index d59a43f78..8f9626557 100644 --- a/src/planmysem/data/AddressBook.java +++ b/src/planmysem/data/Planner.java @@ -9,14 +9,14 @@ /** * Represents the entire address book. Contains the data of the address book. */ -public class AddressBook { +public class Planner { private final UniquePersonList allPersons; /** * Creates an empty address book. */ - public AddressBook() { + public Planner() { allPersons = new UniquePersonList(); } @@ -25,12 +25,12 @@ public AddressBook() { * * @param persons external changes to this will not affect this address book */ - public AddressBook(UniquePersonList persons) { + public Planner(UniquePersonList persons) { this.allPersons = new UniquePersonList(persons); } - public static AddressBook empty() { - return new AddressBook(); + public static Planner empty() { + return new Planner(); } /** @@ -75,8 +75,8 @@ public UniquePersonList getAllPersons() { @Override 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)); + || (other instanceof Planner // instanceof handles nulls + && this.allPersons.equals(((Planner) other).allPersons)); } @Override diff --git a/src/planmysem/data/person/Person.java b/src/planmysem/data/person/Person.java index 800513bd8..664cd747c 100644 --- a/src/planmysem/data/person/Person.java +++ b/src/planmysem/data/person/Person.java @@ -11,7 +11,6 @@ * Guarantees: details are present and not null, field values are validated. */ public class Person implements ReadOnlyPerson { - private final Set tags = new HashSet<>(); private Name name; private Phone phone; diff --git a/src/planmysem/data/slot/DateTime.java b/src/planmysem/data/slot/DateTime.java new file mode 100644 index 000000000..26b994dc6 --- /dev/null +++ b/src/planmysem/data/slot/DateTime.java @@ -0,0 +1,53 @@ +package planmysem.data.slot; + +import planmysem.data.exception.IllegalValueException; + +/** + * Represents a Person's email in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValid(String)} + */ +public class DateTime { + + public static final String EXAMPLE = "valid@e.mail"; + public static final String MESSAGE_EMAIL_CONSTRAINTS = + "Person emails should be 2 alphanumeric/period strings separated by '@'"; + public static final String EMAIL_VALIDATION_REGEX = "[\\w\\.]+@[\\w\\.]+"; + + public final String value; + private boolean isPrivate; + + /** + * Validates given email. + * + * @throws IllegalValueException if given email address string is invalid. + */ + public DateTime(String email, boolean isPrivate) throws IllegalValueException { + this.isPrivate = isPrivate; + email = email.trim(); + if (!isValid(email)) { + throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS); + } + this.value = email; + } + + /** + * Checks if a given string is a valid Date and Time. + */ + public static boolean isValid(String test) { + return test.matches(EMAIL_VALIDATION_REGEX); + } + + public boolean isPrivate() { + return isPrivate; + } + + @Override + public String toString() { + return value; + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/planmysem/data/slot/Description.java b/src/planmysem/data/slot/Description.java new file mode 100644 index 000000000..00808a136 --- /dev/null +++ b/src/planmysem/data/slot/Description.java @@ -0,0 +1,68 @@ +package planmysem.data.slot; + +import java.util.Arrays; +import java.util.List; + +import planmysem.data.exception.IllegalValueException; + +/** + * Represents a Slot's description in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidName(String)} + */ +public class Description { + + public static final String EXAMPLE = "John Doe"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphanumeric characters"; + public static final String NAME_VALIDATION_REGEX = "[\\p{Alnum} ]+"; + + public final String fullName; + private boolean isPrivate; + + /** + * Validates given name. + * + * @throws IllegalValueException if given name string is invalid. + */ + public Description(String name) throws IllegalValueException { + name = name.trim(); + if (!isValidName(name)) { + throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS); + } + this.fullName = name; + } + + /** + * Returns true if a given string is a valid slot name. + */ + public static boolean isValidName(String test) { + return test.matches(NAME_VALIDATION_REGEX); + } + + /** + * Retrieves a listing of every word in the name, in order. + */ + public List getWordsInName() { + return Arrays.asList(fullName.split("\\s+")); + } + public boolean isPrivate() { + return isPrivate; + } + + @Override + public String toString() { + return fullName; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Description // instanceof handles nulls + && this.fullName.equals(((Description) other).fullName)); // state check + } + + @Override + public int hashCode() { + return fullName.hashCode(); + } + +} diff --git a/src/planmysem/data/slot/Location.java b/src/planmysem/data/slot/Location.java new file mode 100644 index 000000000..dbb85fc4e --- /dev/null +++ b/src/planmysem/data/slot/Location.java @@ -0,0 +1,14 @@ +package planmysem.data.slot; + +/** + * Represents a Person's email in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValid(String)} + */ +public class Location { + private boolean isPrivate; + + public boolean isPrivate() { + return isPrivate; + } + +} diff --git a/src/planmysem/data/slot/Name.java b/src/planmysem/data/slot/Name.java new file mode 100644 index 000000000..fb5af7cb4 --- /dev/null +++ b/src/planmysem/data/slot/Name.java @@ -0,0 +1,64 @@ +package planmysem.data.slot; + +import java.util.Arrays; +import java.util.List; + +import planmysem.data.exception.IllegalValueException; + +/** + * Represents a Slot's name in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidName(String)} + */ +public class Name { + + public static final String EXAMPLE = "John Doe"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphanumeric characters"; + public static final String NAME_VALIDATION_REGEX = "[\\p{Alnum} ]+"; + + public final String fullName; + + /** + * Validates given name. + * + * @throws IllegalValueException if given name string is invalid. + */ + public Name(String name) throws IllegalValueException { + name = name.trim(); + if (!isValidName(name)) { + throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS); + } + this.fullName = name; + } + + /** + * Returns true if a given string is a valid slot name. + */ + public static boolean isValidName(String test) { + return test.matches(NAME_VALIDATION_REGEX); + } + + /** + * Retrieves a listing of every word in the name, in order. + */ + public List getWordsInName() { + return Arrays.asList(fullName.split("\\s+")); + } + + @Override + public String toString() { + return fullName; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Name // instanceof handles nulls + && this.fullName.equals(((Name) other).fullName)); // state check + } + + @Override + public int hashCode() { + return fullName.hashCode(); + } + +} diff --git a/src/planmysem/data/slot/ReadOnlySlot.java b/src/planmysem/data/slot/ReadOnlySlot.java new file mode 100644 index 000000000..9410040c0 --- /dev/null +++ b/src/planmysem/data/slot/ReadOnlySlot.java @@ -0,0 +1,91 @@ +package planmysem.data.slot; + +import java.util.Set; + +import planmysem.data.person.Address; +import planmysem.data.person.Email; +import planmysem.data.person.Name; +import planmysem.data.person.Phone; +import planmysem.data.tag.Tag; + +/** + * A read-only immutable interface for a Person in the planmysem. + * Implementations should guarantee: details are present and not null, field values are validated. + */ +public interface ReadOnlySlot { + + Name getName(); + Location getLocation(); + Description getDescription(); + DateTime getDateTime(); + + /** + * 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(); + + /** + * Returns true if the values inside this object is same as + * those of the other (Note: interfaces cannot override .equals) + */ + default boolean isSameStateAs(ReadOnlySlot 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.getLocation().equals(this.getLocation()) + && other.getDescription().equals(this.getDescription()) + && other.getDateTime().equals(this.getDateTime())); + } + + /** + * Formats the person as text, showing all contact details. + */ + default String getAsTextShowAll() { + final StringBuilder builder = new StringBuilder(); + final String detailIsPrivate = "(private) "; + builder.append(getName()) + .append(" Location: "); + if (getLocation().isPrivate()) { + builder.append(detailIsPrivate); + } + builder.append(getLocation()) + .append(" DateTime: "); + if (getDescription().isPrivate()) { + builder.append(detailIsPrivate); + } + builder.append(getDateTime()) + .append(" Tags: "); + if (getDateTime().isPrivate()) { + builder.append(detailIsPrivate); + } + builder.append(getDescription()) + .append(" Tags: "); + for (Tag tag : getTags()) { + builder.append(tag); + } + return builder.toString(); + } + + /** + * Formats a person as text, showing only non-private contact details. + */ + // default String getAsTextHidePrivate() { + // final StringBuilder builder = new StringBuilder(); + // builder.append(getName()); + // if (!getLocation().isPrivate()) { + // builder.append(" Phone: ").append(getPhone()); + // } + // if (!getDescription().isPrivate()) { + // builder.append(" Email: ").append(getEmail()); + // } + // if (!getDateTime().isPrivate()) { + // builder.append(" Address: ").append(getAddress()); + // } + // builder.append(" Tags: "); + // for (Tag tag : getTags()) { + // builder.append(tag); + // } + // return builder.toString(); + // } +} diff --git a/src/planmysem/data/slot/Slot.java b/src/planmysem/data/slot/Slot.java new file mode 100644 index 000000000..3ee2b5319 --- /dev/null +++ b/src/planmysem/data/slot/Slot.java @@ -0,0 +1,97 @@ +package planmysem.data.slot; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import planmysem.data.person.Name; +import planmysem.data.tag.Tag; + +/** + * Represents a Person in the address book. + * Guarantees: details are present and not null, field values are validated. + */ +public class Slot implements ReadOnlySlot { + private final Set tags = new HashSet<>(); + private Name name; + private Location location; + private Description description; + private DateTime dateTime; + + // private Phone phone; + // private Email email; + // private Address address; + + /** + * Assumption: Every field must be present and not null. + */ + public Slot(Name name, Location location, Description description, DateTime dateTime, Set tags) { + this.name = name; + this.location = location; + this.description = description; + this.dateTime = dateTime; + // this.phone = phone; + // this.email = email; + // this.address = address; + this.tags.addAll(tags); + } + + /** + * Copy constructor. + */ + public Slot(ReadOnlySlot source) { + this(source.getName(), source.getLocation(), source.getDescription(), source.getDateTime(), source.getTags()); + } + + @Override + public Name getName() { + return name; + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public Description getDescription() { + return description; + } + + @Override + public DateTime getDateTime() { + return dateTime; + } + + @Override + public Set getTags() { + return new HashSet<>(tags); + } + + /** + * Replaces this person's tags with the tags in {@code replacement}. + */ + public void setTags(Set replacement) { + tags.clear(); + tags.addAll(replacement); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReadOnlySlot // instanceof handles nulls + && this.isSameStateAs((ReadOnlySlot) other)); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(name, location, description, dateTime, tags); + } + + @Override + public String toString() { + return getAsTextShowAll(); + } + +} diff --git a/src/planmysem/logic/Logic.java b/src/planmysem/logic/Logic.java index f9df5a906..295c6e5bb 100644 --- a/src/planmysem/logic/Logic.java +++ b/src/planmysem/logic/Logic.java @@ -6,19 +6,19 @@ import planmysem.commands.Command; import planmysem.commands.CommandResult; -import planmysem.data.AddressBook; +import planmysem.data.Planner; import planmysem.data.person.ReadOnlyPerson; import planmysem.parser.Parser; import planmysem.storage.StorageFile; /** - * Represents the main Logic of the AddressBook. + * Represents the main Logic of the Planner. */ public class Logic { private StorageFile storage; - private AddressBook addressBook; + private Planner addressBook; /** * The list of person shown to the user most recently. @@ -30,7 +30,7 @@ public Logic() throws Exception { setAddressBook(storage.load()); } - Logic(StorageFile storageFile, AddressBook addressBook) { + Logic(StorageFile storageFile, Planner addressBook) { setStorage(storageFile); setAddressBook(addressBook); } @@ -39,7 +39,7 @@ void setStorage(StorageFile storage) { this.storage = storage; } - void setAddressBook(AddressBook addressBook) { + void setAddressBook(Planner addressBook) { this.addressBook = addressBook; } diff --git a/src/planmysem/storage/StorageFile.java b/src/planmysem/storage/StorageFile.java index b73efefae..d624af52d 100644 --- a/src/planmysem/storage/StorageFile.java +++ b/src/planmysem/storage/StorageFile.java @@ -16,7 +16,7 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import planmysem.data.AddressBook; +import planmysem.data.Planner; import planmysem.data.exception.IllegalValueException; import planmysem.storage.jaxb.AdaptedAddressBook; @@ -72,7 +72,7 @@ private static boolean isValidPath(Path filePath) { * * @throws StorageOperationException if there were errors converting and/or storing data to file. */ - public void save(AddressBook addressBook) throws StorageOperationException { + public void save(Planner addressBook) throws StorageOperationException { /* Note: Note the 'try with resource' statement below. * More info: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html @@ -97,7 +97,7 @@ public void save(AddressBook addressBook) throws StorageOperationException { * * @throws StorageOperationException if there were errors reading and/or converting data from file. */ - public AddressBook load() throws StorageOperationException { + public Planner load() throws StorageOperationException { try (final Reader fileReader = new BufferedReader(new FileReader(path.toFile()))) { @@ -116,7 +116,7 @@ public AddressBook load() throws StorageOperationException { // create empty file if not found } catch (FileNotFoundException fnfe) { - final AddressBook empty = new AddressBook(); + final Planner empty = new Planner(); save(empty); return empty; diff --git a/src/planmysem/storage/jaxb/AdaptedAddressBook.java b/src/planmysem/storage/jaxb/AdaptedAddressBook.java index 010a6615d..bf0636475 100644 --- a/src/planmysem/storage/jaxb/AdaptedAddressBook.java +++ b/src/planmysem/storage/jaxb/AdaptedAddressBook.java @@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import planmysem.data.AddressBook; +import planmysem.data.Planner; import planmysem.data.exception.IllegalValueException; import planmysem.data.person.Person; import planmysem.data.person.UniquePersonList; @@ -14,7 +14,7 @@ /** * JAXB-friendly adapted address book data holder class. */ -@XmlRootElement(name = "AddressBook") +@XmlRootElement(name = "Planner") public class AdaptedAddressBook { @XmlElement @@ -27,11 +27,11 @@ public AdaptedAddressBook() { } /** - * Converts a given AddressBook into this class for JAXB use. + * Converts a given Planner into this class for JAXB use. * * @param source future changes to this will not affect the created AdaptedAddressBook */ - public AdaptedAddressBook(AddressBook source) { + public AdaptedAddressBook(Planner source) { persons = new ArrayList<>(); source.getAllPersons().forEach(person -> persons.add(new AdaptedPerson(person))); } @@ -51,15 +51,15 @@ public boolean isAnyRequiredFieldMissing() { /** - * Converts this jaxb-friendly {@code AdaptedAddressBook} object into the corresponding(@code AddressBook} object. + * Converts this jaxb-friendly {@code AdaptedAddressBook} object into the corresponding(@code Planner} object. * * @throws IllegalValueException if there were any data constraints violated in the adapted person */ - public AddressBook toModelType() throws IllegalValueException { + public Planner toModelType() throws IllegalValueException { final List personList = new ArrayList<>(); for (AdaptedPerson person : persons) { personList.add(person.toModelType()); } - return new AddressBook(new UniquePersonList(personList)); + return new Planner(new UniquePersonList(personList)); } } diff --git a/src/planmysem/ui/Formatter.java b/src/planmysem/ui/Formatter.java index c1df03e52..f3a8bfe70 100644 --- a/src/planmysem/ui/Formatter.java +++ b/src/planmysem/ui/Formatter.java @@ -11,7 +11,7 @@ public class Formatter { /** - * A decorative prefix added to the beginning of lines printed by AddressBook + * A decorative prefix added to the beginning of lines printed by Planner */ private static final String LINE_PREFIX = " "; diff --git a/test/java/planmysem/logic/LogicTest.java b/test/java/planmysem/logic/LogicTest.java index cb6331bb6..f379760a4 100644 --- a/test/java/planmysem/logic/LogicTest.java +++ b/test/java/planmysem/logic/LogicTest.java @@ -27,7 +27,7 @@ import planmysem.commands.ViewAllCommand; import planmysem.commands.ViewCommand; import planmysem.common.Messages; -import planmysem.data.AddressBook; +import planmysem.data.Planner; import planmysem.data.person.Address; import planmysem.data.person.Email; import planmysem.data.person.Name; @@ -47,13 +47,13 @@ public class LogicTest { public TemporaryFolder saveFolder = new TemporaryFolder(); private StorageFile saveFile; - private AddressBook addressBook; + private Planner addressBook; private Logic logic; @Before public void setup() throws Exception { saveFile = new StorageFile(saveFolder.newFile("testSaveFile.txt").getPath()); - addressBook = new AddressBook(); + addressBook = new Planner(); saveFile.save(addressBook); logic = new Logic(saveFile, addressBook); } @@ -77,10 +77,10 @@ public void execute_invalid() throws Exception { * Executes the command and confirms that the result message is correct. * Both the 'address book' and the 'last shown list' are expected to be empty. * - * @see #assertCommandBehavior(String, String, AddressBook, boolean, List) + * @see #assertCommandBehavior(String, String, Planner, boolean, List) */ private void assertCommandBehavior(String inputCommand, String expectedMessage) throws Exception { - assertCommandBehavior(inputCommand, expectedMessage, AddressBook.empty(), false, Collections.emptyList()); + assertCommandBehavior(inputCommand, expectedMessage, Planner.empty(), false, Collections.emptyList()); } /** @@ -92,7 +92,7 @@ private void assertCommandBehavior(String inputCommand, String expectedMessage) */ private void assertCommandBehavior(String inputCommand, String expectedMessage, - AddressBook expectedAddressBook, + Planner expectedAddressBook, boolean isRelevantPersonsExpected, List lastShownList) throws Exception { @@ -136,7 +136,7 @@ public void execute_clear() throws Exception { addressBook.addPerson(helper.generatePerson(2, true)); addressBook.addPerson(helper.generatePerson(3, true)); - assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, AddressBook.empty(), false, Collections.emptyList()); + assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, Planner.empty(), false, Collections.emptyList()); } @Test @@ -170,7 +170,7 @@ public void execute_add_successful() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); Person toBeAdded = helper.adam(); - AddressBook expectedAB = new AddressBook(); + Planner expectedAB = new Planner(); expectedAB.addPerson(toBeAdded); // execute command and verify result @@ -187,7 +187,7 @@ public void execute_addDuplicate_notAllowed() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); Person toBeAdded = helper.adam(); - AddressBook expectedAB = new AddressBook(); + Planner expectedAB = new Planner(); expectedAB.addPerson(toBeAdded); // setup starting state @@ -207,7 +207,7 @@ 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); + Planner expectedAB = helper.generateAddressBook(false, true); List expectedList = expectedAB.getAllPersons().immutableListView(); // prepare address book state @@ -245,9 +245,9 @@ private void assertInvalidIndexBehaviorForCommand(String commandWord) throws Exc logic.setLastShownList(lastShownList); - assertCommandBehavior(commandWord + " -1", expectedMessage, AddressBook.empty(), false, lastShownList); - assertCommandBehavior(commandWord + " 0", expectedMessage, AddressBook.empty(), false, lastShownList); - assertCommandBehavior(commandWord + " 3", expectedMessage, AddressBook.empty(), false, lastShownList); + assertCommandBehavior(commandWord + " -1", expectedMessage, Planner.empty(), false, lastShownList); + assertCommandBehavior(commandWord + " 0", expectedMessage, Planner.empty(), false, lastShownList); + assertCommandBehavior(commandWord + " 3", expectedMessage, Planner.empty(), false, lastShownList); } @@ -258,7 +258,7 @@ public void execute_view_onlyShowsNonPrivate() throws Exception { Person p1 = helper.generatePerson(1, true); Person p2 = helper.generatePerson(2, false); List lastShownList = helper.generatePersonList(p1, p2); - AddressBook expectedAB = helper.generateAddressBook(lastShownList); + Planner expectedAB = helper.generateAddressBook(lastShownList); helper.addToAddressBook(addressBook, lastShownList); logic.setLastShownList(lastShownList); @@ -283,7 +283,7 @@ public void execute_tryToViewMissingPerson_errorMessage() throws Exception { Person p2 = helper.generatePerson(2, false); List lastShownList = helper.generatePersonList(p1, p2); - AddressBook expectedAB = new AddressBook(); + Planner expectedAB = new Planner(); expectedAB.addPerson(p2); addressBook.addPerson(p2); @@ -314,7 +314,7 @@ public void execute_viewAll_alsoShowsPrivate() throws Exception { Person p1 = helper.generatePerson(1, true); Person p2 = helper.generatePerson(2, false); List lastShownList = helper.generatePersonList(p1, p2); - AddressBook expectedAB = helper.generateAddressBook(lastShownList); + Planner expectedAB = helper.generateAddressBook(lastShownList); helper.addToAddressBook(addressBook, lastShownList); logic.setLastShownList(lastShownList); @@ -339,7 +339,7 @@ public void execute_tryToViewAllPersonMissingInAddressBook_errorMessage() throws Person p2 = helper.generatePerson(2, false); List lastShownList = helper.generatePersonList(p1, p2); - AddressBook expectedAB = new AddressBook(); + Planner expectedAB = new Planner(); expectedAB.addPerson(p1); addressBook.addPerson(p1); @@ -373,7 +373,7 @@ public void execute_delete_removesCorrectPerson() throws Exception { List threePersons = helper.generatePersonList(p1, p2, p3); - AddressBook expectedAB = helper.generateAddressBook(threePersons); + Planner expectedAB = helper.generateAddressBook(threePersons); expectedAB.removePerson(p2); @@ -397,7 +397,7 @@ public void execute_delete_missingInAddressBook() throws Exception { List threePersons = helper.generatePersonList(p1, p2, p3); - AddressBook expectedAB = helper.generateAddressBook(threePersons); + Planner expectedAB = helper.generateAddressBook(threePersons); expectedAB.removePerson(p2); helper.addToAddressBook(addressBook, threePersons); @@ -426,7 +426,7 @@ public void execute_find_onlyMatchesFullWordsInNames() throws Exception { Person p2 = helper.generatePersonWithName("KEYKEYKEY sduauo"); List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); - AddressBook expectedAB = helper.generateAddressBook(fourPersons); + Planner expectedAB = helper.generateAddressBook(fourPersons); List expectedList = helper.generatePersonList(pTarget1, pTarget2); helper.addToAddressBook(addressBook, fourPersons); @@ -446,7 +446,7 @@ public void execute_find_isCaseSensitive() throws Exception { Person p2 = helper.generatePersonWithName("KEy sduauo"); List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); - AddressBook expectedAB = helper.generateAddressBook(fourPersons); + Planner expectedAB = helper.generateAddressBook(fourPersons); List expectedList = helper.generatePersonList(pTarget1, pTarget2); helper.addToAddressBook(addressBook, fourPersons); @@ -466,7 +466,7 @@ public void execute_find_matchesIfAnyKeywordPresent() throws Exception { Person p2 = helper.generatePersonWithName("KEy sduauo"); List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); - AddressBook expectedAB = helper.generateAddressBook(fourPersons); + Planner expectedAB = helper.generateAddressBook(fourPersons); List expectedList = helper.generatePersonList(pTarget1, pTarget2); helper.addToAddressBook(addressBook, fourPersons); @@ -533,41 +533,41 @@ String generateAddCommand(Person p) { } /** - * Generates an AddressBook with auto-generated persons. + * Generates an Planner with auto-generated persons. * * @param isPrivateStatuses flags to indicate if all contact details of respective persons should be set to * private. */ - AddressBook generateAddressBook(Boolean... isPrivateStatuses) throws Exception { - AddressBook addressBook = new AddressBook(); + Planner generateAddressBook(Boolean... isPrivateStatuses) throws Exception { + Planner addressBook = new Planner(); addToAddressBook(addressBook, isPrivateStatuses); return addressBook; } /** - * Generates an AddressBook based on the list of Persons given. + * Generates an Planner based on the list of Persons given. */ - AddressBook generateAddressBook(List persons) throws Exception { - AddressBook addressBook = new AddressBook(); + Planner generateAddressBook(List persons) throws Exception { + Planner addressBook = new Planner(); addToAddressBook(addressBook, persons); return addressBook; } /** - * Adds auto-generated Person objects to the given AddressBook + * Adds auto-generated Person objects to the given Planner * - * @param addressBook The AddressBook to which the Persons will be added + * @param addressBook The Planner to which the Persons will be added * @param isPrivateStatuses flags to indicate if all contact details of generated persons should be set to * private. */ - void addToAddressBook(AddressBook addressBook, Boolean... isPrivateStatuses) throws Exception { + void addToAddressBook(Planner addressBook, Boolean... isPrivateStatuses) throws Exception { addToAddressBook(addressBook, generatePersonList(isPrivateStatuses)); } /** - * Adds the given list of Persons to the given AddressBook + * Adds the given list of Persons to the given Planner */ - void addToAddressBook(AddressBook addressBook, List personsToAdd) throws Exception { + void addToAddressBook(Planner addressBook, List personsToAdd) throws Exception { for (Person p : personsToAdd) { addressBook.addPerson(p); } diff --git a/test/java/planmysem/storage/StorageFileTest.java b/test/java/planmysem/storage/StorageFileTest.java index 241794f1c..9a9807869 100644 --- a/test/java/planmysem/storage/StorageFileTest.java +++ b/test/java/planmysem/storage/StorageFileTest.java @@ -12,7 +12,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import planmysem.data.AddressBook; +import planmysem.data.Planner; import planmysem.data.exception.IllegalValueException; import planmysem.data.person.Address; import planmysem.data.person.Email; @@ -45,7 +45,7 @@ public void constructor_noTxtExtension_exceptionThrown() throws Exception { @Test public void load_invalidFormat_exceptionThrown() throws Exception { - // The file contains valid xml data, but does not match the AddressBook class + // The file contains valid xml data, but does not match the Planner class StorageFile storage = getStorage("InvalidData.txt"); thrown.expect(StorageOperationException.class); storage.load(); @@ -53,11 +53,11 @@ public void load_invalidFormat_exceptionThrown() throws Exception { @Test public void load_validFormat() throws Exception { - AddressBook actualAB = getStorage("ValidData.txt").load(); - AddressBook expectedAB = getTestAddressBook(); + Planner actualAB = getStorage("ValidData.txt").load(); + Planner expectedAB = getTestAddressBook(); - // ensure loaded AddressBook is properly constructed with test data - // TODO: overwrite equals method in AddressBook class and replace with equals method below + // ensure loaded Planner is properly constructed with test data + // TODO: overwrite equals method in Planner class and replace with equals method below assertEquals(actualAB.getAllPersons(), expectedAB.getAllPersons()); } @@ -70,7 +70,7 @@ public void save_nullAddressBook_exceptionThrown() throws Exception { @Test public void save_validAddressBook() throws Exception { - AddressBook ab = getTestAddressBook(); + Planner ab = getTestAddressBook(); StorageFile storage = getTempStorage(); storage.save(ab); @@ -94,8 +94,8 @@ private StorageFile getTempStorage() throws Exception { return new StorageFile(testFolder.getRoot().getPath() + "/" + "temp.txt"); } - private AddressBook getTestAddressBook() throws Exception { - AddressBook ab = new AddressBook(); + private Planner getTestAddressBook() throws Exception { + Planner ab = new Planner(); ab.addPerson(new Person(new Name("John Doe"), new Phone("98765432", false), new Email("johnd@gmail.com", false), From dc0eafc22b655c719f7427af92c30cebac8452f9 Mon Sep 17 00:00:00 2001 From: Sean Yap Date: Sun, 24 Feb 2019 00:18:44 +0800 Subject: [PATCH 2/5] travis.yml: update script to suit morphed AB3 --- .travis.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ed8f7a8f..7df4f372d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,12 @@ matrix: - jdk: oraclejdk9 script: >- - ./gradlew test asciidoctor + travis_retry ./gradlew clean test coverage coveralls asciidoctor checkstyleMain checkstyleTest deploy: skip_cleanup: true provider: script - script: ./config/travis/deploy_github_pages.sh + script: bash ./config/travis/deploy_github_pages.sh on: branch: master @@ -17,3 +17,12 @@ addons: apt: packages: - oracle-java9-installer + +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ + +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ From 0015765ae148642e1520c5b5209344fda05afc0d Mon Sep 17 00:00:00 2001 From: Sean Yap Date: Sun, 24 Feb 2019 00:27:54 +0800 Subject: [PATCH 3/5] Update tests to fit new data --- test/data/StorageFileTest/InvalidData.txt | 4 ++-- test/data/StorageFileTest/ValidData.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/data/StorageFileTest/InvalidData.txt b/test/data/StorageFileTest/InvalidData.txt index 91e8971a4..ad994ee9b 100644 --- a/test/data/StorageFileTest/InvalidData.txt +++ b/test/data/StorageFileTest/InvalidData.txt @@ -1,6 +1,6 @@ - + data - + diff --git a/test/data/StorageFileTest/ValidData.txt b/test/data/StorageFileTest/ValidData.txt index fc6b00df6..30760b6d1 100644 --- a/test/data/StorageFileTest/ValidData.txt +++ b/test/data/StorageFileTest/ValidData.txt @@ -1,5 +1,5 @@ - + John Doe 98765432 @@ -14,4 +14,4 @@ friend criminal - + From 1b342416032b6fcd9a1475b403fe7d4e8874997d Mon Sep 17 00:00:00 2001 From: Sean Yap Date: Sun, 24 Feb 2019 00:34:08 +0800 Subject: [PATCH 4/5] ReadOnlySlot: remove unused imports --- src/planmysem/data/slot/ReadOnlySlot.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/planmysem/data/slot/ReadOnlySlot.java b/src/planmysem/data/slot/ReadOnlySlot.java index 9410040c0..b0241a002 100644 --- a/src/planmysem/data/slot/ReadOnlySlot.java +++ b/src/planmysem/data/slot/ReadOnlySlot.java @@ -2,10 +2,7 @@ import java.util.Set; -import planmysem.data.person.Address; -import planmysem.data.person.Email; import planmysem.data.person.Name; -import planmysem.data.person.Phone; import planmysem.data.tag.Tag; /** From b50419b00c9b8cf1f68433bbb18f006270003b91 Mon Sep 17 00:00:00 2001 From: Sean Yap Date: Sun, 24 Feb 2019 01:11:53 +0800 Subject: [PATCH 5/5] Fix Codacy errors --- src/planmysem/data/slot/DateTime.java | 8 ++++---- src/planmysem/data/slot/Description.java | 8 ++++---- src/planmysem/data/slot/Name.java | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/planmysem/data/slot/DateTime.java b/src/planmysem/data/slot/DateTime.java index 26b994dc6..4b47f1f1c 100644 --- a/src/planmysem/data/slot/DateTime.java +++ b/src/planmysem/data/slot/DateTime.java @@ -21,13 +21,13 @@ public class DateTime { * * @throws IllegalValueException if given email address string is invalid. */ - public DateTime(String email, boolean isPrivate) throws IllegalValueException { + public DateTime(String value, boolean isPrivate) throws IllegalValueException { this.isPrivate = isPrivate; - email = email.trim(); - if (!isValid(email)) { + String dateTime = value.trim(); + if (!isValid(dateTime)) { throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS); } - this.value = email; + this.value = dateTime; } /** diff --git a/src/planmysem/data/slot/Description.java b/src/planmysem/data/slot/Description.java index 00808a136..563d89920 100644 --- a/src/planmysem/data/slot/Description.java +++ b/src/planmysem/data/slot/Description.java @@ -23,12 +23,12 @@ public class Description { * * @throws IllegalValueException if given name string is invalid. */ - public Description(String name) throws IllegalValueException { - name = name.trim(); - if (!isValidName(name)) { + public Description(String value) throws IllegalValueException { + String description = value.trim(); + if (!isValidName(description)) { throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS); } - this.fullName = name; + this.fullName = description; } /** diff --git a/src/planmysem/data/slot/Name.java b/src/planmysem/data/slot/Name.java index fb5af7cb4..12469ce83 100644 --- a/src/planmysem/data/slot/Name.java +++ b/src/planmysem/data/slot/Name.java @@ -22,8 +22,8 @@ public class Name { * * @throws IllegalValueException if given name string is invalid. */ - public Name(String name) throws IllegalValueException { - name = name.trim(); + public Name(String value) throws IllegalValueException { + String name = value.trim(); if (!isValidName(name)) { throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS); }