Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix move command and list calorie bugs #213

Merged
merged 18 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/seedu/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import seedu.duke.model.DayMap;

import java.util.logging.Logger;

/**
* Execute command.
*/
public class Command {
protected DayMap dayMap;
protected boolean canBeChained = false;
protected static Logger commandLogger = Logger.getLogger("Command");

/**
* This method is to be override by the specific commands.
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/duke/command/FindAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public FindAllCommand(String userInput) {
public void execute() {
try {
dayMap.listActivitiesContainingAll(userInput);
FindDrawer findDrawer = new FindDrawer(dayMap.getLastSeenList());
findDrawer.printList();
dayMap.drawListAfterFindCommand();
} catch (KeywordNotFoundException e) {
System.out.println("No results were found!");
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/duke/command/FindCalorieCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public FindCalorieCommand(String calorie) {
public void execute() {
try {
dayMap.listActivitiesContainingCalorie(calorie);
dayMap.drawListAfterFindCommand();
} catch (KeywordNotFoundException e) {
System.out.println("No results were found!");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/duke/command/FindDescriptionCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public FindDescriptionCommand(String description) {
public void execute() {
try {
dayMap.listActivitiesContainingDescription(description);
FindDrawer findDrawer = new FindDrawer(dayMap.getLastSeenList());
findDrawer.printList();
dayMap.drawListAfterFindCommand();
} catch (KeywordNotFoundException e) {
System.out.println("No results were found!");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/duke/command/FindEitherCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public FindEitherCommand(String userInput) {
public void execute() {
try {
dayMap.listActivitiesContainingEither(userInput);
FindDrawer findDrawer = new FindDrawer(dayMap.getLastSeenList());
findDrawer.printList();
dayMap.drawListAfterFindCommand();
} catch (KeywordNotFoundException e) {
System.out.println("No results were found!");
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seedu/duke/command/InvalidCommand.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package seedu.duke.command;

import static seedu.duke.ui.ExceptionMessages.displayInvalidInputErrorMessage;
import static seedu.duke.ui.ExceptionMessages.print;

/**
* Represents an invalid command.
*/
public class InvalidCommand extends Command {
public InvalidCommand() {

String invalidCommandMessage;

public InvalidCommand(String invalidCommandMessage) {
this.invalidCommandMessage = invalidCommandMessage;
}


@Override
public void execute() {
displayInvalidInputErrorMessage();
print(invalidCommandMessage);
}
}
3 changes: 2 additions & 1 deletion src/main/java/seedu/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.logging.Level;

/**
* Prints the list of activities for the given day.
Expand Down Expand Up @@ -31,11 +32,11 @@ public ListCommand() {
public void execute() {
try {
dayMap.setLastSeenList(dayMap.getActivityList(date.atStartOfDay()));

dayMap.drawListAfterListCommand(date);

} catch (NullPointerException e) {
System.out.println("There is no data for " + date.toString());
commandLogger.log(Level.WARNING,"Accessing a list without any data");
}

}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/duke/command/MoveActivityCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

import seedu.duke.exception.ListNotFoundException;

import java.util.logging.Level;

import static seedu.duke.ui.ExceptionMessages.displayListNotFoundExceptionMessage;
import static seedu.duke.ui.ExceptionMessages.displayStringIndexOutOfBoundsExceptionMessage;
import static seedu.duke.ui.ExceptionMessages.print;

/**
* This command moves an activity from one index to another.
Expand All @@ -23,10 +26,13 @@ public MoveActivityCommand(int indexToBeChanged, int indexToBeInsertedBelow) {
public void execute() {
try {
dayMap.move(indexToBeMovedFrom, indexToBeInsertedBelow);
print("Activity has been successfully moved!");
} catch (IndexOutOfBoundsException e) {
displayStringIndexOutOfBoundsExceptionMessage();
commandLogger.log(Level.WARNING, "Accessing an index that is out of bounds");
} catch (ListNotFoundException e) {
displayListNotFoundExceptionMessage();
commandLogger.log(Level.WARNING, "Accessing a list that does not exist");
}

}
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/seedu/duke/logic/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static seedu.duke.ui.ExceptionMessages.displayEmptyEditActivityErrorMessage;
import static seedu.duke.ui.ExceptionMessages.displayEmptyInput;
import static seedu.duke.ui.ExceptionMessages.displayFindErrorMessage;
import static seedu.duke.ui.ExceptionMessages.displayInvalidInputErrorMessage;
import static seedu.duke.ui.ExceptionMessages.displayIoExceptionMessage;
import static seedu.duke.ui.ExceptionMessages.displayStringIndexOutOfBoundsExceptionMessage;
import static seedu.duke.ui.ExceptionMessages.displayIncorrectDateTimeFormatEnteredMessage;
Expand Down Expand Up @@ -128,7 +129,8 @@ public Command parseCommand() {
case "graph":
return prepareGraphCommand(arguments);
default:
return new InvalidCommand();
return new InvalidCommand(displayAddCommandErrorMessage());

}
} catch (StringIndexOutOfBoundsException e) {
displayStringIndexOutOfBoundsExceptionMessage();
Expand Down Expand Up @@ -354,9 +356,19 @@ private Command prepareMoveIndexCommand(String userInput) throws IndexOutOfBound
String firstIndexKey = "from/";
String secondIndexKey = "below/";


int firstIndex = after.indexOf(firstIndexKey) + firstIndexKey.length(); //index after first keyword
int secondIndex = after.indexOf(secondIndexKey) + secondIndexKey.length(); //index after second keyword

if (!after.contains(firstIndexKey) && !after.contains(secondIndexKey)) {
return new InvalidCommand("'from/' and 'below/' keyword is missing!");
} else if (!after.contains(firstIndexKey)) {
return new InvalidCommand("'from/' keyword is missing!");
} else if (!after.contains(secondIndexKey)) {
return new InvalidCommand("'below/' keyword is missing!");
}


String firstIndexString = after.substring(firstIndex).trim().split(" ")[0];
String secondIndexString = after.substring(secondIndex).trim().split(" ")[0];
int indexToBeChanged = 0;
Expand Down Expand Up @@ -490,4 +502,5 @@ private Command prepareUserProfileListCommand() {
return new ListUserProfileCommand();
}


}
13 changes: 9 additions & 4 deletions src/main/java/seedu/duke/model/ActivityList.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ public void insertActivity(int index, Activity activity) throws IndexOutOfBounds
public void moveActivity(int indexToBeMovedFrom, int indexToBeInsertedBelow) throws IndexOutOfBoundsException {

if (isValidIndex(indexToBeMovedFrom) && isValidIndex(indexToBeInsertedBelow)) {
Activity activity = getActivity(indexToBeMovedFrom);
activities.remove(indexToBeMovedFrom);
activities.add(indexToBeInsertedBelow, activity);
//displaySavedMessage();
if (indexToBeMovedFrom > indexToBeInsertedBelow) {
Activity activity = getActivity(indexToBeMovedFrom);
activities.remove(indexToBeMovedFrom);
activities.add(indexToBeInsertedBelow, activity);
} else {
Activity activity = getActivity(indexToBeMovedFrom);
activities.remove(indexToBeMovedFrom);
activities.add(indexToBeInsertedBelow - 1, activity);
}
} else {
throw new IndexOutOfBoundsException();
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/duke/model/DayMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ public ActivityList getLastSeenList() {
}

/**
* Displays the list using the drawer classes.
* Displays the list using the listDrawer class.
* @param date is the date of the list to be drawn.
*/
public void drawListAfterListCommand(LocalDate date) {
ListDrawer listDrawer = new ListDrawer(date, lastSeenList);
listDrawer.printList();
}

/**
* Displays the list using the findDrawer class.
*/
public void drawListAfterFindCommand() {
FindDrawer findDrawer = new FindDrawer(lastSeenList);
findDrawer.printList();
}

/**
* Adds activity into activityList under the corresponding dateTime.
* Creates a new activityList if there are none under the specified date.
Expand Down Expand Up @@ -192,7 +200,6 @@ public void listActivitiesContainingCalorie(String calorie) throws KeywordNotFou
int calorieStartIndex = currentLine.lastIndexOf(' ');
String calorieToCheck = currentLine.substring(calorieStartIndex).trim();
if (calorieToCheck.equals(calorie)) {
System.out.println((activityFindCounter + 1) + ". " + date + " " + currentLine);
lastSeenList.addActivity(activities.getActivity(i));
activityFindCounter++;
}
Expand Down
Loading