forked from nus-cs2103-AY2223S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 nus-cs2103-AY2223S1#87 from seox123/add-unplan-com…
…mand Add unplan command
- Loading branch information
Showing
8 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/seedu/waddle/logic/commands/UnplanCommand.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,63 @@ | ||
package seedu.waddle.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.waddle.commons.core.index.MultiIndex; | ||
import seedu.waddle.logic.StageManager; | ||
import seedu.waddle.logic.commands.exceptions.CommandException; | ||
import seedu.waddle.model.Model; | ||
import seedu.waddle.model.item.Item; | ||
import seedu.waddle.model.itinerary.Itinerary; | ||
|
||
/** | ||
* Unplans an item in the itinerary day list. | ||
*/ | ||
public class UnplanCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "unplan"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Unschedules an item identified " | ||
+ "by the index number used in the day list.\n" | ||
+ "Parameters: DAY_INDEX.TASK_INDEX (must be an existing index) " | ||
+ "Example: " + COMMAND_WORD + " 1.2 "; | ||
|
||
public static final String MESSAGE_SUCCESS = "Item unscheduled: %1$s"; | ||
public static final String MESSAGE_INVALID_INDEX_NUMBER = "The index you have selected does not exist"; | ||
|
||
private final MultiIndex multiIndex; | ||
|
||
/** | ||
* Creates an UnplanCommand to add the specified {@code Item} | ||
*/ | ||
public UnplanCommand(MultiIndex multiIndex) { | ||
requireNonNull(multiIndex); | ||
|
||
this.multiIndex = multiIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
StageManager stageManager = StageManager.getInstance(); | ||
|
||
Itinerary itinerary = stageManager.getSelectedItinerary(); | ||
|
||
Item unplannedItem; | ||
try { | ||
System.out.println(multiIndex.toString()); | ||
unplannedItem = itinerary.unplanItem(multiIndex); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new CommandException(MESSAGE_INVALID_INDEX_NUMBER); | ||
} | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, unplannedItem.getDescription())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof UnplanCommand // instanceof handles nulls | ||
&& multiIndex.equals(((UnplanCommand) other).multiIndex)); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/seedu/waddle/logic/parser/UnplanCommandParser.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,27 @@ | ||
package seedu.waddle.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.waddle.commons.core.index.MultiIndex; | ||
import seedu.waddle.logic.commands.UnplanCommand; | ||
import seedu.waddle.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new UnplanCommand object | ||
*/ | ||
public class UnplanCommandParser { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the UnplanCommand | ||
* and returns an UnplanCommand object for execution. | ||
* @throws ParseException if the user input does not conform to the expected format | ||
*/ | ||
public UnplanCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args); | ||
|
||
MultiIndex multiIndex = ParserUtil.parseMultiIndex(argMultimap.getPreamble()); | ||
|
||
return new UnplanCommand(multiIndex); | ||
} | ||
} |
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
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
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