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#85 from seox123/add-plan-command
Add plan command
- Loading branch information
Showing
11 changed files
with
232 additions
and
26 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
79 changes: 79 additions & 0 deletions
79
src/main/java/seedu/waddle/logic/commands/PlanCommand.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,79 @@ | ||
package seedu.waddle.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.waddle.logic.parser.CliSyntax.PREFIX_DAY_NUMBER; | ||
import static seedu.waddle.logic.parser.CliSyntax.PREFIX_START_TIME; | ||
|
||
import java.time.LocalTime; | ||
|
||
import seedu.waddle.commons.core.index.Index; | ||
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.DayNumber; | ||
import seedu.waddle.model.itinerary.Itinerary; | ||
|
||
/** | ||
* Plans an item in the itinerary wish list. | ||
*/ | ||
public class PlanCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "plan"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Schedules an item identified " | ||
+ "by the index number used in the item list.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_DAY_NUMBER + "DAY NUMBER] " | ||
+ "[" + PREFIX_START_TIME + "START TIME] " | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_DAY_NUMBER + "1 " | ||
+ PREFIX_START_TIME + "12:00 "; | ||
|
||
public static final String MESSAGE_SUCCESS = "Item scheduled: %1$s"; | ||
public static final String MESSAGE_INVALID_DAY_NUMBER = "The day you have selected does not exist"; | ||
|
||
private final Index itemIndex; | ||
private final DayNumber dayNumber; | ||
private final LocalTime startTime; | ||
|
||
/** | ||
* Creates an AddItemCommand to add the specified {@code Item} | ||
*/ | ||
public PlanCommand(Index itemIndex, DayNumber dayNumber, LocalTime startTime) { | ||
requireNonNull(itemIndex); | ||
requireNonNull(dayNumber); | ||
requireNonNull(startTime); | ||
|
||
this.itemIndex = itemIndex; | ||
this.dayNumber = dayNumber; | ||
this.startTime = startTime; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
StageManager stageManager = StageManager.getInstance(); | ||
|
||
Itinerary itinerary = stageManager.getSelectedItinerary(); | ||
|
||
Item plannedItem; | ||
try { | ||
plannedItem = itinerary.planItem(itemIndex, dayNumber, startTime); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new CommandException(MESSAGE_INVALID_DAY_NUMBER); | ||
} | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, plannedItem.getDescription())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof PlanCommand // instanceof handles nulls | ||
&& itemIndex.equals(((PlanCommand) other).itemIndex) | ||
&& dayNumber == ((PlanCommand) other).dayNumber | ||
&& startTime.equals(((PlanCommand) other).startTime)); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/seedu/waddle/logic/parser/SelectCommandParser.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,38 @@ | ||
package seedu.waddle.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.waddle.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.waddle.commons.core.index.Index; | ||
import seedu.waddle.commons.exceptions.IllegalValueException; | ||
import seedu.waddle.logic.commands.SelectCommand; | ||
import seedu.waddle.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new SelectCommand object | ||
*/ | ||
public class SelectCommandParser { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the SelectCommand | ||
* and returns a SelectCommand object for execution. | ||
* | ||
* @param args Arguments | ||
* @return SelectCommand | ||
* @throws ParseException If the user input does not conform to the expected format | ||
*/ | ||
public SelectCommand 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, | ||
SelectCommand.MESSAGE_USAGE), ive); | ||
} | ||
|
||
return new SelectCommand(index); | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package seedu.waddle.model.itinerary; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.waddle.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents an Itinerary's day number element. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidDayNumber(String)} | ||
*/ | ||
public class DayNumber { | ||
public static final String MESSAGE_CONSTRAINTS = | ||
"Day number should only contain positive numbers"; | ||
public static final String VALIDATION_REGEX = "\\d+"; | ||
|
||
public final int dayNumber; | ||
|
||
/** | ||
* Constructs a {@code DayNumber}. | ||
* | ||
* @param dayNumber A valid value. | ||
*/ | ||
public DayNumber(String dayNumber) { | ||
requireNonNull(dayNumber); | ||
checkArgument(isValidDayNumber(dayNumber), MESSAGE_CONSTRAINTS); | ||
this.dayNumber = Integer.parseInt(dayNumber); | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid day number. | ||
*/ | ||
public static boolean isValidDayNumber(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(dayNumber); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof seedu.waddle.model.itinerary.DayNumber // instanceof handles nulls | ||
&& dayNumber == ((seedu.waddle.model.itinerary.DayNumber) other).dayNumber); // state check | ||
} | ||
} |
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