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

WIP: Implement concrete classes (Don't review) #29

Merged
merged 15 commits into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'checkstyle'
// id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'application'
id 'jacoco'
Expand All @@ -16,9 +16,9 @@ repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

checkstyle {
toolVersion = '8.29'
}
//checkstyle {
// toolVersion = '8.29'
//}

test {
useJUnitPlatform()
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/ArchitectureSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ activate model MODEL_COLOR
model -[MODEL_COLOR]-> logic
deactivate model

logic -[LOGIC_COLOR]> storage : saveAddressBook(addressBook)
logic -[LOGIC_COLOR]> storage : saveAddressBook(trackIter)
activate storage STORAGE_COLOR

storage -[STORAGE_COLOR]> storage : Save to file
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/RemovingFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Fortunately, IntelliJ IDEA provides a robust refactoring tool that can identify

### Assisted refactoring

The `address` field in `Person` is actually an instance of the `seedu.address.model.contact.Address` class. Since removing the `Address` class will break the application, we start by identifying `Address`'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` \> `Safe Delete` through the menu.
The `address` field in `Person` is actually an instance of the `seedu.address.model.commons.Address` class. Since removing the `Address` class will break the application, we start by identifying `Address`'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` \> `Safe Delete` through the menu.

![Usages detected](../images/remove/UnsafeDelete.png)

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyTrackIter;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.TrackIter;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class MainApp extends Application {

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
logger.info("=============================[ Initializing TrackIter ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
Expand All @@ -74,20 +74,20 @@ public void init() throws Exception {
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
Optional<ReadOnlyTrackIter> addressBookOptional;
ReadOnlyTrackIter initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
logger.info("Data file not found. Will be starting with a sample TrackIter");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Data file not in the correct format. Will be starting with an empty TrackIter");
initialData = new TrackIter();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Problem while reading from the file. Will be starting with an empty TrackIter");
initialData = new TrackIter();
}

return new ModelManager(initialData, userPrefs);
Expand Down Expand Up @@ -151,7 +151,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
logger.warning("Problem while reading from the file. Will be starting with an empty TrackIter");
initializedPrefs = new UserPrefs();
}

Expand All @@ -167,7 +167,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting TrackIter " + MainApp.VERSION);
ui.start(primaryStage);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Contact;
import seedu.address.model.ReadOnlyTrackIter;
import seedu.address.model.contact.Contact;

/**
* API of the Logic component
Expand All @@ -24,11 +24,11 @@ public interface Logic {
CommandResult execute(String commandText) throws CommandException, ParseException;

/**
* Returns the AddressBook.
* Returns the TrackIter.
*
* @see seedu.address.model.Model#getAddressBook()
* @see seedu.address.model.Model#getTrackIter()
*/
ReadOnlyAddressBook getAddressBook();
ReadOnlyTrackIter getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Contact> getFilteredPersonList();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Contact;
import seedu.address.model.ReadOnlyTrackIter;
import seedu.address.model.contact.Contact;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -46,7 +46,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
commandResult = command.execute(model);

try {
storage.saveAddressBook(model.getAddressBook());
storage.saveAddressBook(model.getTrackIter());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
Expand All @@ -55,18 +55,18 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
public ReadOnlyTrackIter getAddressBook() {
return model.getTrackIter();
}

@Override
public ObservableList<Contact> getFilteredPersonList() {
return model.getFilteredPersonList();
return model.getFilteredContactList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
return model.getTrackIterFilePath();
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Contact;
import seedu.address.model.contact.Contact;

/**
* Adds a contact to the address book.
Expand Down Expand Up @@ -50,11 +50,11 @@ public AddCommand(Contact contact) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
if (model.hasContact(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
model.addContact(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static java.util.Objects.requireNonNull;

import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.TrackIter;

/**
* Clears the address book.
Expand All @@ -17,7 +17,7 @@ public class ClearCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
model.setTrackIter(new TrackIter());
return new CommandResult(MESSAGE_SUCCESS);
}
}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Contact;
import seedu.address.model.contact.Contact;

/**
* Deletes a contact identified using it's displayed index from the address book.
Expand All @@ -33,14 +33,14 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Contact> lastShownList = model.getFilteredPersonList();
List<Contact> lastShownList = model.getFilteredContactList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Contact contactToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(contactToDelete);
model.deleteContact(contactToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, contactToDelete));
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CONTACTS;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -19,11 +19,11 @@
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Contact;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.commons.Address;
import seedu.address.model.commons.Name;
import seedu.address.model.contact.Contact;
import seedu.address.model.contact.Email;
import seedu.address.model.contact.Phone;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Contact> lastShownList = model.getFilteredPersonList();
List<Contact> lastShownList = model.getFilteredContactList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand All @@ -77,12 +77,12 @@ public CommandResult execute(Model model) throws CommandException {
Contact contactToEdit = lastShownList.get(index.getZeroBased());
Contact editedContact = createEditedPerson(contactToEdit, editPersonDescriptor);

if (!contactToEdit.isSamePerson(editedContact) && model.hasPerson(editedContact)) {
if (!contactToEdit.isSamePerson(editedContact) && model.hasContact(editedContact)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.setPerson(contactToEdit, editedContact);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.setContact(contactToEdit, editedContact);
model.updateFilteredContactList(PREDICATE_SHOW_ALL_CONTACTS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedContact));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.contact.NameContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
Expand All @@ -28,9 +28,9 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
model.updateFilteredContactList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredContactList().size()));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CONTACTS;

import seedu.address.model.Model;

Expand All @@ -18,7 +18,7 @@ public class ListCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredContactList(PREDICATE_SHOW_ALL_CONTACTS);
return new CommandResult(MESSAGE_SUCCESS);
}
}
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Contact;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.commons.Address;
import seedu.address.model.commons.Name;
import seedu.address.model.contact.Contact;
import seedu.address.model.contact.Email;
import seedu.address.model.contact.Phone;
import seedu.address.model.tag.Tag;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Contact;
import seedu.address.model.contact.Contact;

/**
* Parses user input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.contact.NameContainsKeywordsPredicate;

/**
* Parses input arguments and creates a new FindCommand object
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.commons.Address;
import seedu.address.model.commons.Name;
import seedu.address.model.contact.Email;
import seedu.address.model.contact.Phone;
import seedu.address.model.tag.Tag;

/**
Expand Down