Skip to content

Commit

Permalink
Identation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yichen-D committed Oct 29, 2016
1 parent 8e4bf08 commit 4bd89fd
Show file tree
Hide file tree
Showing 25 changed files with 1,275 additions and 1,212 deletions.
27 changes: 15 additions & 12 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public class MainApp extends Application {
protected Config config;
protected UserPrefs userPrefs;

public MainApp() {}
public MainApp() {
}

@Override
public void init() throws Exception {

logger.info("=============================[ Initializing TaskList ]===========================");
super.init();

Expand All @@ -68,7 +69,7 @@ public void init() throws Exception {
initEventsCenter();
}

private String getApplicationParameter(String parameterName){
private String getApplicationParameter(String parameterName) {
Map<String, String> applicationParameters = getParameters().getNamed();
return applicationParameters.get(parameterName);
}
Expand All @@ -78,7 +79,7 @@ private Model initModelManager(Storage storage, UserPrefs userPrefs) {
ReadOnlyTaskMaster initialData;
try {
taskListOptional = storage.readTaskList();
if(!taskListOptional.isPresent()){
if (!taskListOptional.isPresent()) {
logger.info("Data file not found. Will be starting with an empty TaskList");
}
initialData = taskListOptional.orElse(new TaskMaster());
Expand All @@ -103,7 +104,7 @@ protected Config initConfig(String configFilePath) {

configFilePathUsed = Config.DEFAULT_CONFIG_FILE;

if(configFilePath != null) {
if (configFilePath != null) {
logger.info("Custom Config file specified " + configFilePath);
configFilePathUsed = configFilePath;
}
Expand All @@ -114,12 +115,13 @@ protected Config initConfig(String configFilePath) {
Optional<Config> configOptional = ConfigUtil.readConfig(configFilePathUsed);
initializedConfig = configOptional.orElse(new Config());
} catch (DataConversionException e) {
logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. " +
"Using default config properties");
logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. "
+ "Using default config properties");
initializedConfig = new Config();
}

//Update config file in case it was missing to begin with or there are new/unused fields
// Update config file in case it was missing to begin with or there are
// new/unused fields
try {
ConfigUtil.saveConfig(initializedConfig, configFilePathUsed);
} catch (IOException e) {
Expand All @@ -139,15 +141,16 @@ protected UserPrefs initPrefs(Config config) {
Optional<UserPrefs> prefsOptional = storage.readUserPrefs();
initializedPrefs = prefsOptional.orElse(new UserPrefs());
} catch (DataConversionException e) {
logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct format. " +
"Using default user prefs");
logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct format. "
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. . Will be starting with an empty TaskList");
initializedPrefs = new UserPrefs();
}

//Update prefs file in case it was missing to begin with or there are new/unused fields
// Update prefs file in case it was missing to begin with or there are
// new/unused fields
try {
storage.saveUserPrefs(initializedPrefs);
} catch (IOException e) {
Expand Down Expand Up @@ -187,7 +190,7 @@ public void handleExitAppRequestEvent(ExitAppRequestEvent event) {
}

public static void main(String[] args) {
StatusLogger.getLogger().setLevel(Level.OFF);
StatusLogger.getLogger().setLevel(Level.OFF);
launch(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import seedu.address.commons.events.BaseEvent;

//@@author A0147967J
/** Indicates the file path of the task master should change.*/
/** Indicates the file path of the task master should change. */
public class FilePathChangeEvent extends BaseEvent {

public final String newFilePath;

public FilePathChangeEvent(String newFilePath){
public FilePathChangeEvent(String newFilePath) {
this.newFilePath = newFilePath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
*/
public class AgendaTimeRangeChangedEvent extends BaseEvent {


private final TaskDate inputDate;
private final List<TaskComponent> taskComponentList;

public AgendaTimeRangeChangedEvent(TaskDate inputDate, List<TaskComponent> list){
public AgendaTimeRangeChangedEvent(TaskDate inputDate, List<TaskComponent> list) {
this.inputDate = inputDate;
this.taskComponentList = list;
}
Expand All @@ -29,7 +28,7 @@ public String toString() {
public TaskDate getInputDate() {
return inputDate;
}

public List<TaskComponent> getData() {
return taskComponentList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
* Indicates an attempt to execute a failed command
*/
public class FailedCommandAttemptedEvent extends BaseEvent {


public FailedCommandAttemptedEvent(Command command) {
}


@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
*/
public class NavigationSelectionChangedEvent extends BaseEvent {


private final String newSelection;

public NavigationSelectionChangedEvent(String newSelection){
public NavigationSelectionChangedEvent(String newSelection) {
this.newSelection = newSelection;
}

Expand Down
239 changes: 123 additions & 116 deletions src/main/java/seedu/address/logic/URManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,120 +13,127 @@
* Stores and provides context for undo/redo operations.
*/
public class URManager {

private ArrayDeque<Context> undoQueue;
private ArrayDeque<Context> redoQueue;

/** Arbitrarily chosen number to ensure overall performance. */
private final int MAX_TIMES = 3;

public URManager(){
undoQueue = new ArrayDeque<Context>();
redoQueue = new ArrayDeque<Context>();
}

/**
* Adds the command to undo queue for LogicManager.
*/
public void addToUndoQueue(Model model, Command command){
if(!isUndoable(command)){
//Stop here to wait for result.
}else{
if(!isIgnored(command)){
if(undoQueue.size() == MAX_TIMES) undoQueue.removeFirst();
undoQueue.addLast(new Context(model, command));
redoQueue.clear();
}
}
}

/**
* Pops the failed or incorrect (but not detected during parsing) command from undo queue
*/
public void popFromUndoQueue(){
undoQueue.removeLast();
}

/**
* Change Directory command succeeds, clear all undo and redo queue.
*/
public void resetQueue(){
undoQueue.clear();
redoQueue.clear();
}

/**
* Adds the command to undo queue for redo command.
*/
public void addToUndoQueueUsedByRedo(Model model, Command command){
if(!isUndoable(command)){
undoQueue.clear();
redoQueue.clear();
}else{
if(!isIgnored(command)){
if(undoQueue.size() == MAX_TIMES) undoQueue.removeFirst();
undoQueue.addLast(new Context(model, command));
}
}
}

public Context getContextToUndo() throws NoAvailableCommandException{
try{
Context contextToUndo = undoQueue.removeLast();
redoQueue.addLast(contextToUndo);
return contextToUndo;
} catch (Exception e){
throw new NoAvailableCommandException();
}
}

public Context getContextToRedo() throws NoAvailableCommandException{
try{
Context contextToRedo = redoQueue.removeLast();
undoQueue.addLast(contextToRedo);
return contextToRedo;
} catch (Exception e){
throw new NoAvailableCommandException();
}
}

/**
* Returns true if the command does not need to be added in undo/redo queue.
* Exclusion for view command is just tentative and needs further consideration.
*/
public Boolean isIgnored(Command command){
return command instanceof RedoCommand ||
command instanceof UndoCommand ||
command instanceof ViewCommand ||
command instanceof IncorrectCommand;
}

/**
* Returns true if the command is undoable.
* Currently, only ChangeDirectoryCommand is undoable.
*/
public Boolean isUndoable(Command command){
return !(command instanceof ChangeDirectoryCommand);
}
//=================================================================
public class NoAvailableCommandException extends Exception{}

/**
* Inner class for backup previous data and commands.
*/
public class Context{

private ReadOnlyTaskMaster taskList;
private Command command;
Context(Model model, Command command){
this.command = command;
this.taskList = new TaskMaster(model.getTaskMaster());
}
public Command getCommand(){
return command;
}
public ReadOnlyTaskMaster getData(){
return taskList;
}
}

private ArrayDeque<Context> undoQueue;
private ArrayDeque<Context> redoQueue;

/** Arbitrarily chosen number to ensure overall performance. */
private final int MAX_TIMES = 3;

public URManager() {
undoQueue = new ArrayDeque<Context>();
redoQueue = new ArrayDeque<Context>();
}

/**
* Adds the command to undo queue for LogicManager.
*/
public void addToUndoQueue(Model model, Command command) {
if (!isUndoable(command)) {
// Stop here to wait for result.
} else {
if (!isIgnored(command)) {
if (undoQueue.size() == MAX_TIMES)
undoQueue.removeFirst();
undoQueue.addLast(new Context(model, command));
redoQueue.clear();
}
}
}

/**
* Pops the failed or incorrect (but not detected during parsing) command
* from undo queue
*/
public void popFromUndoQueue() {
undoQueue.removeLast();
}

/**
* Change Directory command succeeds, clear all undo and redo queue.
*/
public void resetQueue() {
undoQueue.clear();
redoQueue.clear();
}

/**
* Adds the command to undo queue for redo command.
*/
public void addToUndoQueueUsedByRedo(Model model, Command command) {
if (!isUndoable(command)) {
undoQueue.clear();
redoQueue.clear();
} else {
if (!isIgnored(command)) {
if (undoQueue.size() == MAX_TIMES)
undoQueue.removeFirst();
undoQueue.addLast(new Context(model, command));
}
}
}

public Context getContextToUndo() throws NoAvailableCommandException {
try {
Context contextToUndo = undoQueue.removeLast();
redoQueue.addLast(contextToUndo);
return contextToUndo;
} catch (Exception e) {
throw new NoAvailableCommandException();
}
}

public Context getContextToRedo() throws NoAvailableCommandException {
try {
Context contextToRedo = redoQueue.removeLast();
undoQueue.addLast(contextToRedo);
return contextToRedo;
} catch (Exception e) {
throw new NoAvailableCommandException();
}
}

/**
* Returns true if the command does not need to be added in undo/redo queue.
* Exclusion for view command is just tentative and needs further
* consideration.
*/
public Boolean isIgnored(Command command) {
return command instanceof RedoCommand || command instanceof UndoCommand || command instanceof ViewCommand
|| command instanceof IncorrectCommand;
}

/**
* Returns true if the command is undoable. Currently, only
* ChangeDirectoryCommand is undoable.
*/
public Boolean isUndoable(Command command) {
return !(command instanceof ChangeDirectoryCommand);
}

// =================================================================
public class NoAvailableCommandException extends Exception {
}

/**
* Inner class for backup previous data and commands.
*/
public class Context {

private ReadOnlyTaskMaster taskList;
private Command command;

Context(Model model, Command command) {
this.command = command;
this.taskList = new TaskMaster(model.getTaskMaster());
}

public Command getCommand() {
return command;
}

public ReadOnlyTaskMaster getData() {
return taskList;
}
}
}

0 comments on commit 4bd89fd

Please sign in to comment.