Skip to content

Commit

Permalink
Merge branch 'master' of github.com:se-edu/addressbook-level4
Browse files Browse the repository at this point in the history
  • Loading branch information
okkhoy committed Aug 17, 2018
2 parents 35f3a7e + 385809b commit f1c3d39
Show file tree
Hide file tree
Showing 66 changed files with 405 additions and 371 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void stop() {
@Subscribe
public void handleExitAppRequestEvent(ExitAppRequestEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));
this.stop();
stop();
}

public static void main(String[] args) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class GuiSettings implements Serializable {
private Point windowCoordinates;

public GuiSettings() {
this.windowWidth = DEFAULT_WIDTH;
this.windowHeight = DEFAULT_HEIGHT;
this.windowCoordinates = null; // null represent no coordinates
windowWidth = DEFAULT_WIDTH;
windowHeight = DEFAULT_HEIGHT;
windowCoordinates = null; // null represent no coordinates
}

public GuiSettings(Double windowWidth, Double windowHeight, int xPosition, int yPosition) {
this.windowWidth = windowWidth;
this.windowHeight = windowHeight;
this.windowCoordinates = new Point(xPosition, yPosition);
windowCoordinates = new Point(xPosition, yPosition);
}

public Double getWindowWidth() {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/commons/core/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ public String toString() {

@Override
public int compareTo(Version other) {
if (this.major != other.major) {
return this.major - other.major;
if (major != other.major) {
return major - other.major;
}
if (this.minor != other.minor) {
return this.minor - other.minor;
if (minor != other.minor) {
return minor - other.minor;
}
if (this.patch != other.patch) {
return this.patch - other.patch;
if (patch != other.patch) {
return patch - other.patch;
}
if (this.isEarlyAccess == other.isEarlyAccess()) {
if (isEarlyAccess == other.isEarlyAccess()) {
return 0;
}
if (this.isEarlyAccess) {
if (isEarlyAccess) {
return -1;
}
return 1;
Expand All @@ -99,7 +99,7 @@ public boolean equals(Object obj) {
}
final Version other = (Version) obj;

return this.compareTo(other) == 0;
return compareTo(other) == 0;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public static Index fromOneBased(int oneBasedIndex) {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Index // instanceof handles nulls
&& this.zeroBasedIndex == ((Index) other).zeroBasedIndex); // state check
&& zeroBasedIndex == ((Index) other).zeroBasedIndex); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class ExitAppRequestEvent extends BaseEvent {

@Override
public String toString() {
return this.getClass().getSimpleName();
return getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public JumpToListRequestEvent(Index targetIndex) {

@Override
public String toString() {
return this.getClass().getSimpleName();
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public NewResultAvailableEvent(String message) {

@Override
public String toString() {
return this.getClass().getSimpleName();
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PersonPanelSelectionChangedEvent(Person newSelection) {

@Override
public String toString() {
return this.getClass().getSimpleName();
return getClass().getSimpleName();
}

public Person getNewSelection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ShowHelpRequestEvent extends BaseEvent {

@Override
public String toString() {
return this.getClass().getSimpleName();
return getClass().getSimpleName();
}

}
26 changes: 26 additions & 0 deletions src/main/java/seedu/address/logic/CommandHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public CommandHistory() {
userInputHistory = new LinkedList<>();
}

public CommandHistory(CommandHistory commandHistory) {
userInputHistory = new LinkedList<>(commandHistory.userInputHistory);
}

/**
* Appends {@code userInput} to the list of user input entered.
*/
Expand All @@ -29,4 +33,26 @@ public void add(String userInput) {
public List<String> getHistory() {
return new LinkedList<>(userInputHistory);
}

@Override
public boolean equals(Object obj) {
// short circuit if same object
if (obj == this) {
return true;
}

// instanceof handles nulls
if (!(obj instanceof CommandHistory)) {
return false;
}

// state check
CommandHistory other = (CommandHistory) obj;
return userInputHistory.equals(other.userInputHistory);
}

@Override
public int hashCode() {
return userInputHistory.hashCode();
}
}
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
logger.info("----------------[USER COMMAND][" + commandText + "]");
try {
Command command = addressBookParser.parseCommand(commandText);
command.setData(model, history);
return command.execute();
return command.execute(model, history);
} finally {
history.add(commandText);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
Expand Down Expand Up @@ -46,7 +48,7 @@ public AddCommand(Person person) {
}

@Override
public CommandResult execute() throws CommandException {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static java.util.Objects.requireNonNull;

import seedu.address.logic.CommandHistory;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;

/**
* Clears the address book.
Expand All @@ -14,7 +16,7 @@ public class ClearCommand extends Command {


@Override
public CommandResult execute() {
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.resetData(new AddressBook());
model.commitAddressBook();
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/seedu/address/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@
* Represents a command with hidden internal logic and the ability to be executed.
*/
public abstract class Command {
protected Model model;
protected CommandHistory history;

/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @param history {@code CommandHistory} which the command should operate on.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
public abstract CommandResult execute() throws CommandException;
public abstract CommandResult execute(Model model, CommandHistory history) throws CommandException;

/**
* Provides any needed dependencies to the command.
* Commands making use of any of these should override this method to gain
* access to the dependencies.
*/
public void setData(Model model, CommandHistory history) {
this.model = model;
}
}
9 changes: 7 additions & 2 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
Expand All @@ -28,7 +32,8 @@ public DeleteCommand(Index targetIndex) {
}

@Override
public CommandResult execute() throws CommandException {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
Expand All @@ -45,6 +50,6 @@ public CommandResult execute() throws CommandException {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteCommand // instanceof handles nulls
&& this.targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check
&& targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check
}
}
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -65,7 +67,8 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
}

@Override
public CommandResult execute() throws CommandException {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
Expand Down Expand Up @@ -148,7 +151,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(this.name, this.phone, this.email, this.address, this.tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
}

public void setName(Name name) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.events.ui.ExitAppRequestEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Terminates the program.
Expand All @@ -13,7 +15,7 @@ public class ExitCommand extends Command {
public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";

@Override
public CommandResult execute() {
public CommandResult execute(Model model, CommandHistory history) {
EventsCenter.getInstance().post(new ExitAppRequestEvent());
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT);
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

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

/**
Expand All @@ -23,7 +27,8 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
}

@Override
public CommandResult execute() {
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
Expand All @@ -33,6 +38,6 @@ public CommandResult execute() {
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof FindCommand // instanceof handles nulls
&& this.predicate.equals(((FindCommand) other).predicate)); // state check
&& predicate.equals(((FindCommand) other).predicate)); // state check
}
}
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.events.ui.ShowHelpRequestEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Format full help instructions for every command for display.
Expand All @@ -16,7 +18,7 @@ public class HelpCommand extends Command {
public static final String SHOWING_HELP_MESSAGE = "Opened help window.";

@Override
public CommandResult execute() {
public CommandResult execute(Model model, CommandHistory history) {
EventsCenter.getInstance().post(new ShowHelpRequestEvent());
return new CommandResult(SHOWING_HELP_MESSAGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class HistoryCommand extends Command {
public static final String MESSAGE_NO_HISTORY = "You have not yet entered any commands.";

@Override
public CommandResult execute() {
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(history);
List<String> previousCommands = history.getHistory();

if (previousCommands.isEmpty()) {
Expand All @@ -29,9 +30,4 @@ public CommandResult execute() {
return new CommandResult(String.format(MESSAGE_SUCCESS, String.join("\n", previousCommands)));
}

@Override
public void setData(Model model, CommandHistory history) {
requireNonNull(history);
this.history = history;
}
}
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package seedu.address.logic.commands;

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

import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Lists all persons in the address book to the user.
*/
Expand All @@ -13,7 +17,8 @@ public class ListCommand extends Command {


@Override
public CommandResult execute() {
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(MESSAGE_SUCCESS);
}
Expand Down
Loading

0 comments on commit f1c3d39

Please sign in to comment.