Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
burnflare committed Nov 6, 2016
2 parents df90680 + ceff169 commit c509576
Show file tree
Hide file tree
Showing 25 changed files with 390 additions and 269 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
//@@author A0133367E
package seedu.agendum.commons.events.logic;

import seedu.agendum.commons.events.BaseEvent;
import java.util.Hashtable;

import java.util.*;
import seedu.agendum.commons.events.BaseEvent;

/**
* Indicate the alias table in Logic's command library has changed
* Indicate the alias table in {@link seedu.agendum.logic.commands.CommandLibrary} has changed
*/
public class AliasTableChangedEvent extends BaseEvent {

public final String aliasedKeyChanged;
public final Hashtable<String, String> aliasTable;
private String message_;

public AliasTableChangedEvent(String aliasedKeyChanged, Hashtable<String, String> aliasTable) {
this.aliasedKeyChanged = aliasedKeyChanged;
public AliasTableChangedEvent(String message, Hashtable<String, String> aliasTable) {
this.aliasTable = aliasTable;
this.message_ = message;
}

@Override
public String toString() {
return aliasedKeyChanged;
return message_;
}
}
8 changes: 3 additions & 5 deletions src/main/java/seedu/agendum/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ public class AddCommand extends Command {
+ "add <name> by <deadline> \n"
+ "add <name> from <start-time> to <end-time>";
public static final String COMMAND_DESCRIPTION = "adds a task to Agendum";

public static final String MESSAGE_SUCCESS = "Task added: %1$s";
public static final String MESSAGE_DUPLICATE_TASK = "Hey, the task already exists";
public static final String MESSAGE_USAGE = COMMAND_WORD + " - "
+ COMMAND_DESCRIPTION + "\n"
+ COMMAND_FORMAT + "\n"
+ "Example: " + COMMAND_WORD + " Watch Star Wars\n"
+ "from 7pm to 9pm";

public static final String MESSAGE_SUCCESS = "Task added: %1$s";
public static final String MESSAGE_DUPLICATE_TASK = "Hey, the task already exists";

private Task toAdd = null;

//@@author A0003878Y
//@@author A0003878Y
/**
* Convenience constructor using name
*
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/seedu/agendum/logic/commands/AliasCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//@@author A0133367E
package seedu.agendum.logic.commands;

import seedu.agendum.model.Model;

//@@author A0133367E
/**
* Create an alias for a reserved command keyword
* Creates an alias for a reserved command keyword
*/
public class AliasCommand extends Command {

// COMMAND_WORD, COMMAND_FORMAT, COMMAND_DESCRIPTION are for display in help window
public static final String COMMAND_WORD = "alias";
public static final String COMMAND_FORMAT = "alias <original-command> <your-command>";
public static final String COMMAND_DESCRIPTION = "create your shorthand command";
Expand Down Expand Up @@ -38,9 +37,9 @@ public void setData(Model model, CommandLibrary commandLibrary) {

@Override
public CommandResult execute() {
if (!commandLibrary.isReservedCommandKeyword(aliasValue)) {
if (commandLibrary.isReservedCommandKeyword(aliasKey)) {
return new CommandResult(String.format(
MESSAGE_FAILURE_NON_ORIGINAL_COMMAND, aliasValue));
MESSAGE_FAILURE_UNAVAILABLE_ALIAS, aliasKey));
}

if (commandLibrary.isExistingAliasKey(aliasKey)) {
Expand All @@ -49,9 +48,9 @@ public CommandResult execute() {
MESSAGE_FAILURE_ALIAS_IN_USE, aliasKey, associatedValue));
}

if (commandLibrary.isReservedCommandKeyword(aliasKey)) {
if (!commandLibrary.isReservedCommandKeyword(aliasValue)) {
return new CommandResult(String.format(
MESSAGE_FAILURE_UNAVAILABLE_ALIAS, aliasKey));
MESSAGE_FAILURE_NON_ORIGINAL_COMMAND, aliasValue));
}

commandLibrary.addNewAlias(aliasKey, aliasValue);
Expand Down
60 changes: 42 additions & 18 deletions src/main/java/seedu/agendum/logic/commands/CommandLibrary.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@@author A0133367E

package seedu.agendum.logic.commands;

import java.util.ArrayList;
Expand All @@ -19,13 +17,15 @@
public class CommandLibrary {

private static final Logger logger = LogsCenter.getLogger(CommandLibrary.class);
private static CommandLibrary commandLibrary = new CommandLibrary();

private List<String> allCommandWords = new ArrayList<String>();

// The keys of the hash table are user-defined aliases
// The values of the has table are Agendum's reserved command keywords
private Hashtable<String, String> aliasTable = new Hashtable<String, String>();

private static CommandLibrary commandLibrary = new CommandLibrary();


//@@author A0003878Y
private CommandLibrary() {
Expand All @@ -49,9 +49,13 @@ public static CommandLibrary getInstance() {
return commandLibrary;
}

public Hashtable<String, String> getAliasTable() {
return aliasTable;
}

//@@author A0133367E
/**
* Replace the current commandLibrary's aliasTable with the aliasTable provided
* Replace the current commandLibrary's aliasTable with the new aliasTable provided
*/
public void loadAliasTable(Hashtable<String, String> aliasTable) {
this.aliasTable = aliasTable;
Expand All @@ -68,8 +72,10 @@ public boolean isExistingAliasKey(String key) {
}

/**
* Precondition: key is an existing alias.
* Returns the reserved command keyword that is aliased by key
*
* @param key An existing user-defined alias for a reserved command keyword
* @return The associated reserved command keyword
*/
public String getAliasedValue(String key) {
assert isExistingAliasKey(key);
Expand All @@ -88,9 +94,12 @@ public boolean isReservedCommandKeyword(String value) {
}

/**
* Precondition: key is a new unique alias and not a command keyword;
* Pre-condition: key is a new unique alias and not a command keyword;
* value is a reserved command keyword.
* Saves the new alias relationship (key can be used in place of value)
* Saves the new alias relationship between key and value.
*
* @param key A valid and unique user-defined alias for a reserved command word
* @param value The target reserved command word
*/
public void addNewAlias(String key, String value) {
assert !isExistingAliasKey(key);
Expand All @@ -99,29 +108,44 @@ public void addNewAlias(String key, String value) {

aliasTable.put(key, value);

indicateAliasTableChanged(key + " aliased");
indicateAliasAdded(key, value);
}

/**
* Precondition: key is aliased to a command keyword.
* Destroy the alias relationship (key can no longer be used in place of command keyword)
* Destroy the alias relationship (key can no longer be used in place of command word)
*
* @param key An existing user-defined alias for a reserved command word
*/
public void removeExistingAlias(String key) {
assert isExistingAliasKey(key);

aliasTable.remove(key);
String value = aliasTable.remove(key);

indicateAliasTableChanged(key + " unaliased");
indicateAliasRemoved(key, value);
}

/** Raises an event to indicate that the aliasTable in the command library has changed */
private void indicateAliasTableChanged(String keyChanged) {
/**
* Raises an event to indicate that an alias has been added to aliasTable in the command library
*
* @param key The new user-defined alias key
* @param value The target reserved command word
*/
private void indicateAliasAdded(String key, String value) {
String message = "Added alias " + key + " for " + value;
EventsCenter eventCenter = EventsCenter.getInstance();
eventCenter.post(new AliasTableChangedEvent(keyChanged, aliasTable));
eventCenter.post(new AliasTableChangedEvent(message, aliasTable));
}

public Hashtable<String, String> getAliasTable() {
return aliasTable;

/**
* Raises an event to indicate that an alias has been removed from aliasTable in the command library
*
* @param key The alias key to be removed
* @param value The associated reserved command word
*/
private void indicateAliasRemoved(String key, String value) {
String message = "Removed alias " + key + " for " + value;
EventsCenter eventCenter = EventsCenter.getInstance();
eventCenter.post(new AliasTableChangedEvent(message, aliasTable));
}

}
4 changes: 4 additions & 0 deletions src/main/java/seedu/agendum/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public CommandResult(String feedbackToUser) {
* Pre-condition: tasks and originalIndices must be of the same size.
* Returns a string containing each task in tasks
* with the corresponding number in originalIndices prepended
*
* @param tasks List of tasks where each task is be prepended by an index
* @param originalIndices List of corresponding index for each task
* @return String containing all tasks labeled with their corresponding index
*/
public static String tasksToString(List<ReadOnlyTask> tasks, List<Integer> originalIndices) {
final StringBuilder builder = new StringBuilder();
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/seedu/agendum/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,30 @@
import seedu.agendum.model.task.ReadOnlyTask;
import seedu.agendum.model.task.UniqueTaskList.TaskNotFoundException;

//@@author A0133367E
/**
* Deletes task(s) identified using their last displayed indices from the task listing.
*/
public class DeleteCommand extends Command {

// COMMAND_WORD, COMMAND_FORMAT, COMMAND_DESCRIPTION are for display in help window
public static final String COMMAND_WORD = "delete";
public static final String COMMAND_FORMAT = "delete <id> <more-ids>";
public static final String COMMAND_DESCRIPTION = "delete task(s) from Agendum";
public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task(s): %1$s";
public static final String MESSAGE_USAGE = COMMAND_WORD + " - "
+ COMMAND_DESCRIPTION + "\n"
+ COMMAND_FORMAT + "\n"
+ "(The id must be a positive number)\n"
+ "Example: " + COMMAND_WORD + " 7 10-11";

public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task(s): %1$s";

public ArrayList<Integer> targetIndexes;
private ArrayList<Integer> targetIndexes;
private ArrayList<ReadOnlyTask> tasksToDelete;

public ArrayList<ReadOnlyTask> tasksToDelete;

//@@author A0133367E
public DeleteCommand(Set<Integer> targetIndexes) {
this.targetIndexes = new ArrayList<>(targetIndexes);
this.targetIndexes = new ArrayList<Integer>(targetIndexes);
Collections.sort(this.targetIndexes);
this.tasksToDelete = new ArrayList<>();
this.tasksToDelete = new ArrayList<ReadOnlyTask>();
}

@Override
Expand Down Expand Up @@ -66,7 +64,6 @@ private boolean isAnyIndexInvalid(UnmodifiableObservableList<ReadOnlyTask> lastS
return targetIndexes.stream().anyMatch(index -> index > lastShownList.size());
}

//@@author
public static String getName() {
return COMMAND_WORD;
}
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/seedu/agendum/logic/commands/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,32 @@
import seedu.agendum.model.task.UniqueTaskList.DuplicateTaskException;
import seedu.agendum.model.task.UniqueTaskList.TaskNotFoundException;

//@@author A0133367E
/**
* Mark task(s) identified using their last displayed indices in the task listing.
*/
public class MarkCommand extends Command {

// COMMAND_WORD, COMMAND_FORMAT, COMMAND_DESCRIPTION are for display in help window
public static final String COMMAND_WORD = "mark";
public static final String COMMAND_FORMAT = "mark <id> <more-ids>";
public static final String COMMAND_DESCRIPTION = "mark task(s) as completed";

public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked Task(s)!";
public static final String MESSAGE_DUPLICATE = "Hey, the task already exists";
public static final String MESSAGE_USAGE = COMMAND_WORD + " - "
+ COMMAND_DESCRIPTION + "\n"
+ COMMAND_FORMAT + "\n"
+ "(The id must be a positive number)\n"
+ "Example: " + COMMAND_WORD + " 1 3 5-6";

public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked Task(s)!";
public static final String MESSAGE_DUPLICATE = "Hey, the task already exists";

public ArrayList<Integer> targetIndexes;
private ArrayList<Integer> targetIndexes;
private ArrayList<ReadOnlyTask> tasksToMark;

public ArrayList<ReadOnlyTask> tasksToMark;

//@@author A0133367E
public MarkCommand(Set<Integer> targetIndexes) {
this.targetIndexes = new ArrayList<>(targetIndexes);
this.targetIndexes = new ArrayList<Integer>(targetIndexes);
Collections.sort(this.targetIndexes);
this.tasksToMark = new ArrayList<>();
this.tasksToMark = new ArrayList<ReadOnlyTask>();
}

@Override
Expand All @@ -59,7 +58,7 @@ public CommandResult execute() {
} catch (TaskNotFoundException pnfe) {
assert false : "The target task cannot be missing";
} catch (DuplicateTaskException pnfe) {
model.restoreCurrentToDoListClone();
model.resetDataToLastSavedList();
return new CommandResult(MESSAGE_DUPLICATE);
}

Expand All @@ -70,7 +69,6 @@ private boolean isAnyIndexInvalid(UnmodifiableObservableList<ReadOnlyTask> lastS
return targetIndexes.stream().anyMatch(index -> index > lastShownList.size());
}

//@@author
public static String getName() {
return COMMAND_WORD;
}
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/seedu/agendum/logic/commands/RenameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,30 @@
import seedu.agendum.model.task.*;
import seedu.agendum.model.task.UniqueTaskList.TaskNotFoundException;


//@@author A0133367E
/**
* Renames a task in the task listing.
* Renames the target task in the task listing.
*/
public class RenameCommand extends Command {

// COMMAND_WORD, COMMAND_FORMAT, COMMAND_DESCRIPTION are for display in help window
public static final String COMMAND_WORD = "rename";
public static final String COMMAND_FORMAT = "rename <id> <new-name>";
public static final String COMMAND_DESCRIPTION = "update the name of a task";
public static final String MESSAGE_SUCCESS = "Task renamed: %1$s";
public static final String MESSAGE_DUPLICATE_TASK = "Hey, the task already exists";
public static final String MESSAGE_USAGE = COMMAND_WORD + " - "
+ COMMAND_DESCRIPTION + "\n"
+ COMMAND_FORMAT + "\n"
+ "Example: " + COMMAND_WORD + " 2 Watch Star Trek";

public static final String MESSAGE_SUCCESS = "Task renamed: %1$s";
public static final String MESSAGE_DUPLICATE_TASK = "Hey, the task already exists";

public int targetIndex = -1;
public Name newTaskName = null;
private int targetIndex;
private Name newTaskName;

//@@author A0133367E
/**
* Constructor for rename command
* @throws IllegalValueException only if the name is invalid
* @throws IllegalValueException if the name is invalid
*/
public RenameCommand(int targetIndex, String name)
throws IllegalValueException {
public RenameCommand(int targetIndex, String name) throws IllegalValueException {
this.targetIndex = targetIndex;
this.newTaskName = new Name(name);
}
Expand Down Expand Up @@ -64,7 +60,6 @@ public CommandResult execute() {

}

//@@author
public static String getName() {
return COMMAND_WORD;
}
Expand Down

0 comments on commit c509576

Please sign in to comment.