Skip to content

Commit

Permalink
Merge branch 'master' into active-participants
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnNzj committed Oct 27, 2019
2 parents f4cf141 + 5031faa commit f39c98d
Show file tree
Hide file tree
Showing 52 changed files with 908 additions and 321 deletions.
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/logic/CommandSubType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package seedu.address.logic;

/**
* Represents the different command sub-types for GUI-related commands.
*/
public enum CommandSubType {
ACTIVITY,
CONTACT
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.activity.Activity;
import seedu.address.model.person.Person;

/**
Expand All @@ -33,6 +34,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of activities */
ObservableList<Activity> getFilteredActivityList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.activity.Activity;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -67,6 +68,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Activity> getFilteredActivityList() {
return model.getFilteredActivityList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
/**
* Command to create a new Activity.
*/

public class ActivityCommand extends Command {

public static final String COMMAND_WORD = "activity";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Creates a new Activity.\n"
+ "Parameters: "
+ PREFIX_TITLE + "TITLE "
+ "[" + PREFIX_PARTICIPANT + "PARTICIPANT]...\n"
+ "Example: activity t/Mala dinner p/Kaedoon p/Giak Lhee p/Veken";

public static final String MESSAGE_SUCCESS =
"%s successfully created with following participants:\n%s\nWarnings:\n%s";
"%s successfully created with following participants:\n%s\nWarnings:\n%s";
public static final String WARNING_SEARCH_RESULTS =
"Unable to add person with search term \"%s\", as there were %d matches found.\n";
public static final String WARNING_DUPLICATE_PERSON =
"Person with name %s already added.\n";
public static final String MESSAGE_ARGUMENTS = "Title: %s";

private final Title title;
private final List<String> participants;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import seedu.address.model.person.Person;

/**
* Adds a person to the address book.
* Adds a new contact to SplitWiser.
*/
public class AddCommand extends Command {

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 @@ -6,13 +6,13 @@
import seedu.address.model.Model;

/**
* Clears the address book.
* Clears all contacts from SplitWiser.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";

public static final String MESSAGE_SUCCESS = "All contacts have been cleared!";

@Override
public CommandResult execute(Model model) {
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import static java.util.Objects.requireNonNull;

import java.util.Objects;
import java.util.Optional;

import seedu.address.model.ContextType;

/**
* Represents the result of a command execution.
Expand All @@ -17,18 +20,37 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

/** Type of updated context - empty if context was not changed by executing this command. */
private final Optional<ContextType> newContext;

/**
* Constructs a {@code CommandResult} with the specified fields.
* Constructs a {@code CommandResult} with the specified fields, for commands that does not change
* the current {@code Context}.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.newContext = Optional.empty();
}

/**
* Constructs a new {@code CommandResult} with the specified fields, for commands that change the
* current {@code Context} of the application. All other fields are set to their default values.
* @param feedbackToUser {@code String} output from executing the command
* @param newContext the new {@code ContextType} after executing the command
*/
public CommandResult(String feedbackToUser, ContextType newContext) {
requireNonNull(newContext);
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = false;
this.exit = false;
this.newContext = Optional.of(newContext);
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* and other fields set to their default value.
* and other fields set to their default values.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false);
Expand All @@ -46,6 +68,10 @@ public boolean isExit() {
return exit;
}

public Optional<ContextType> getUpdatedContext() {
return newContext;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -60,12 +86,13 @@ public boolean equals(Object other) {
CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit;
&& exit == otherCommandResult.exit
&& newContext.equals(otherCommandResult.getUpdatedContext());
}

@Override
public int hashCode() {
return Objects.hash(feedbackToUser, showHelp, exit);
return Objects.hash(feedbackToUser, showHelp, exit, newContext);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import seedu.address.model.person.Person;

/**
* Deletes a person identified using it's displayed index from the address book.
* Deletes the contact identified by its display index from SplitWiser.
*/
public class DeleteCommand extends Command {

Expand Down
6 changes: 3 additions & 3 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_ENTRIES;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -27,7 +27,7 @@
import seedu.address.model.tag.Tag;

/**
* Edits the details of an existing person in the address book.
* Edits the details of an existing contact in SplitWiser.
*/
public class EditCommand extends Command {

Expand Down Expand Up @@ -82,7 +82,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_ENTRIES);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ExitCommand extends Command {

public static final String COMMAND_WORD = "exit";

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";
public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting SplitWiser! Goodbye...";

@Override
public CommandResult execute(Model model) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/seedu/address/logic/commands/ExpenseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.stream.Collectors;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Context;
import seedu.address.model.ContextType;
import seedu.address.model.Model;
import seedu.address.model.activity.Activity;
import seedu.address.model.activity.Amount;
Expand Down Expand Up @@ -69,13 +69,12 @@ public CommandResult execute(Model model) throws CommandException {
Activity activity;

// Contextual behaviour
if (model.getContext().getType() != Context.Type.VIEW_ACTIVITY) {
if (model.getContext().getType() != ContextType.VIEW_ACTIVITY) {
if (!Title.isValidTitle(description)) {
throw new CommandException(MESSAGE_MISSING_DESCRIPTION);
}
activity = new Activity(new Title(description));
// TODO: Use the new view thingy in Activity class.
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_ENTRIES);
} else {
activity = model.getContext().getActivity().get();
// TODO: Use the new view thingy in Activity class.
Expand Down Expand Up @@ -113,7 +112,7 @@ public CommandResult execute(Model model) throws CommandException {
successMessage.append(String.format(MESSAGE_EXPENSE, person.getName(), amount, description));

// Contextual behaviour
if (model.getContext().getType() != Context.Type.VIEW_ACTIVITY) {
if (model.getContext().getType() != ContextType.VIEW_ACTIVITY) {
if (!activity.hasPerson(person.getPrimaryKey())) {
activity.invite(person.getPrimaryKey());
}
Expand All @@ -127,7 +126,7 @@ public CommandResult execute(Model model) throws CommandException {
}

// Contextual behaviour
if (model.getContext().getType() != Context.Type.VIEW_ACTIVITY) {
if (model.getContext().getType() != ContextType.VIEW_ACTIVITY) {
model.addActivity(activity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seedu.address.model.person.NameContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Finds and lists all contacts in SplitWiser whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class FindCommand extends Command {
Expand Down
49 changes: 43 additions & 6 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
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.logic.parser.CliSyntax.PREFIX_ACTIVITY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONTACT;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ENTRIES;

import seedu.address.logic.CommandSubType;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Context;
import seedu.address.model.ContextType;
import seedu.address.model.Model;

/**
* Lists all persons in the address book to the user.
* Updates the GUI to list all entries of a specified type to the user.
*/
public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_SUCCESS = "Listed all persons";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Switches the current view to list all contacts or activities. "
+ "If an argument is supplied with a parameter, it is ignored.\n"
+ "Parameters: " + PREFIX_CONTACT + " OR " + PREFIX_ACTIVITY + "\n"
+ "Example: list " + PREFIX_CONTACT;

public static final String MESSAGE_SUCCESS = "Listed all %s";
public static final String MESSAGE_UNKNOWN_LIST_TYPE = "List command has unknown type!";

private final CommandSubType type;

public ListCommand(CommandSubType type) {
requireNonNull(type);
this.type = type;
}

@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(MESSAGE_SUCCESS);

switch (this.type) {
case CONTACT:
model.setContext(Context.newListContactContext());
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_ENTRIES);
return new CommandResult(String.format(MESSAGE_SUCCESS, "contacts"), ContextType.LIST_CONTACT);
case ACTIVITY:
model.setContext(Context.newListActivityContext());
model.updateFilteredActivityList(PREDICATE_SHOW_ALL_ENTRIES);
return new CommandResult(String.format(MESSAGE_SUCCESS, "activities"), ContextType.LIST_ACTIVITY);
default:
throw new CommandException(MESSAGE_UNKNOWN_LIST_TYPE);
}
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ListCommand // instanceof handles nulls
&& type.equals(((ListCommand) other).type)); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import seedu.address.model.activity.Title;

/**
* Parses input arguments and creates a new {@code RemarkCommand} object
* Parses input arguments and creates a new {@code ActivityCommand} object
*/
public class ActivityCommandParser implements Parser<ActivityCommand> {

/**
* Parses the given {@code String} of arguments in the context of the {@code ActivityCommand}
* and returns a {@code ActivityCommand} object for execution.
* Parses the given {@code String} of arguments in the context of an {@code ActivityCommand}
* and returns an {@code ActivityCommand} object for execution.
* @throws ParseException if the user input does not conform the expected format,
* or has missing compulsory arguments.
*/

public ActivityCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_TITLE, PREFIX_PARTICIPANT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import seedu.address.model.tag.Tag;

/**
* Parses input arguments and creates a new AddCommand object
* Parses input arguments and creates a new {@code AddCommand} object
*/
public class AddCommandParser implements Parser<AddCommand> {

/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
* Parses the given {@code String} of arguments in the context of the {@code AddCommand}
* and returns an {@code AddCommand} object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Command parseCommand(String userInput) throws ParseException {
return new FindCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
return new ListCommand();
return new ListCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class CliSyntax {
public static final Prefix PREFIX_EXPENSE = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

public static final Prefix PREFIX_CONTACT = new Prefix("c/");
public static final Prefix PREFIX_ACTIVITY = new Prefix("a/");

public static final Prefix PREFIX_TITLE = new Prefix("t/");
public static final Prefix PREFIX_PARTICIPANT = new Prefix("p/");
public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/");
Expand Down

0 comments on commit f39c98d

Please sign in to comment.