forked from nus-cs2103-AY2021S1/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-AY2021S1#70 from yyutong/view-expense-c…
…ommand Add view command and parser
- Loading branch information
Showing
12 changed files
with
145 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
4 changes: 4 additions & 0 deletions
4
src/main/java/seedu/address/logic/commands/ViewCategoryCommand.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,4 @@ | ||
package seedu.address.logic.commands; | ||
|
||
public class ViewCategoryCommand { | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/seedu/address/logic/commands/ViewCommand.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,52 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Expense; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class ViewCommand extends Command { | ||
public static final String COMMAND_WORD = "view"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Views the expense identified by the index number used in the displayed expense list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_VIEW_EXPENSE_SUCCESS = "View Expense: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public ViewCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Expense> lastShownList = model.getFilteredExpenseList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Expense expenseToView = lastShownList.get(targetIndex.getZeroBased()); | ||
String message = targetIndex.toString() + "\n" + expenseToView.toString(); | ||
// model.viewExpense(targetIndex); | ||
return new CommandResult(String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, message)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ViewCommand // instanceof handles nulls | ||
&& targetIndex.equals(((ViewCommand) other).targetIndex)); // 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
4 changes: 4 additions & 0 deletions
4
src/main/java/seedu/address/logic/parser/ViewCategoryCommandParser.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,4 @@ | ||
package seedu.address.logic.parser; | ||
|
||
public class ViewCategoryCommandParser { | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/seedu/address/logic/parser/ViewCommandParser.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,32 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteCommand; | ||
import seedu.address.logic.commands.ViewCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
public class ViewCommandParser { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ViewCommand | ||
* and returns a ViewCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ViewCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
try{ | ||
Index index = ParserUtil.parseIndex(args); | ||
return new ViewCommand(index); | ||
} catch(ParseException e) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
ViewCommand.MESSAGE_USAGE)); | ||
} | ||
} | ||
} |
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
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