forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from AY1920S1-CS2103T-F12-2/master
chore: sync with team repo
- Loading branch information
Showing
21 changed files
with
503 additions
and
24 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/seedu/address/logic/commands/AliasCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_VALUE; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Defines an alias. | ||
*/ | ||
public class AliasCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "alias"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Alias added: %1$s -> %2$s"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": defines an alias. " | ||
+ "Parameters: " | ||
+ PREFIX_ALIAS_NAME + "ALIAS_NAME " | ||
+ PREFIX_ALIAS_VALUE + "ALIAS_VALUE " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_ALIAS_NAME + "h " | ||
+ PREFIX_ALIAS_VALUE + "help"; | ||
|
||
private final String alias; | ||
private final String aliasTo; | ||
|
||
/** | ||
* Creates an AliasCommand to define an alias. | ||
*/ | ||
public AliasCommand(String alias, String aliasTo) { | ||
requireNonNull(alias); | ||
requireNonNull(aliasTo); | ||
this.alias = alias.trim(); | ||
this.aliasTo = aliasTo.trim(); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
model.getUserPrefs().getAliasTable().addAlias(alias, aliasTo); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, alias, aliasTo)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/address/logic/commands/ProfileCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Changes the visitList of an existing person in the address book. | ||
*/ | ||
public class ProfileCommand extends Command { | ||
public static final String COMMAND_WORD = "profile"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Opens the detailed profile of the patient identified" | ||
+ "by the index number used in the last person listing. " | ||
+ "The profile can be generated into a log file subsequently.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "Example: " + COMMAND_WORD + " 1 "; | ||
|
||
// public static final String MESSAGE_VIEW_PROFILE_SUCCESS = "Generated profile view of : %1$s"; | ||
public static final String MESSAGE_VIEW_PROFILE_SUCCESS = "Profile Command Recognized! Target: %1$s"; | ||
|
||
private final Index index; | ||
|
||
/** | ||
* @param index of the person in the last listing whose profile is to be viewed | ||
*/ | ||
public ProfileCommand(Index index) { | ||
requireAllNonNull(index); | ||
|
||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
|
||
return new CommandResult(String.format(MESSAGE_VIEW_PROFILE_SUCCESS, personToEdit), index.getOneBased()); | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof ProfileCommand)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
ProfileCommand e = (ProfileCommand) other; | ||
return index.equals(e.index); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/seedu/address/logic/commands/ReminderCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAYS; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.Reminder; | ||
|
||
/** | ||
* Adds a reminder to VISIT. | ||
*/ | ||
public class ReminderCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "reminder"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Creates a new reminder to show up when the program is launched. " | ||
+ "Parameters: " | ||
+ "[" + PREFIX_DAYS + "EXPIRY IN DAYS]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ "Two Point Hospital closed " | ||
+ PREFIX_DAYS + "7"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New reminder added: %s"; | ||
|
||
private final Reminder toAdd; | ||
|
||
/** | ||
* Creates an ReminderCommand to add the specified {@code Reminder} | ||
*/ | ||
public ReminderCommand(Reminder reminder) { | ||
requireNonNull(reminder); | ||
toAdd = reminder; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
model.addReminder(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.getDescription())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ReminderCommand // instanceof handles nulls | ||
&& toAdd.equals(((ReminderCommand) other).toAdd)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/address/logic/parser/AliasCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_VALUE; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.AliasCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new AliasCommand object | ||
*/ | ||
public class AliasCommandParser implements Parser<AliasCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AliasCommand | ||
* and returns an AliasCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AliasCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_ALIAS_NAME, PREFIX_ALIAS_VALUE); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_ALIAS_NAME, PREFIX_ALIAS_VALUE) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AliasCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
String name = argMultimap.getValue(PREFIX_ALIAS_NAME).get(); | ||
String value = argMultimap.getValue(PREFIX_ALIAS_VALUE).get(); | ||
|
||
return new AliasCommand(name, value); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/address/logic/parser/ProfileCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.ProfileCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new {@code RemarkCommand} object | ||
*/ | ||
public class ProfileCommandParser implements Parser<ProfileCommand> { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the {@code RemarkCommand} | ||
* and returns a {@code RemarkCommand} object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ProfileCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args); | ||
|
||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ProfileCommand.MESSAGE_USAGE), ive); | ||
} | ||
|
||
return new ProfileCommand(index); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/seedu/address/logic/parser/ReminderCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAYS; | ||
|
||
import seedu.address.logic.commands.ReminderCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.Reminder; | ||
|
||
/** | ||
* Parses input arguments and creates a new {@code RemindCommand} object | ||
*/ | ||
public class ReminderCommandParser implements Parser<ReminderCommand> { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the {@code RemindCommand} | ||
* and returns a {@code RemindCommand} object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ReminderCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DAYS); | ||
|
||
String description; | ||
int days; | ||
try { | ||
description = argMultimap.getPreamble(); | ||
days = Integer.parseInt(argMultimap.getValue(PREFIX_DAYS).orElse("1")); | ||
} catch (Exception ex) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderCommand.MESSAGE_USAGE), ex); | ||
} | ||
|
||
return new ReminderCommand(new Reminder(description, days)); | ||
} | ||
} |
Oops, something went wrong.