forked from AY2324S1-CS2103-T16-3/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 branch 'master' into branch-Code/FilterCommandFinal
- Loading branch information
Showing
29 changed files
with
761 additions
and
43 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
73 changes: 73 additions & 0 deletions
73
src/main/java/unicash/logic/commands/AddBudgetCommand.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,73 @@ | ||
package unicash.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import unicash.commons.util.ToStringBuilder; | ||
import unicash.logic.UniCashMessages; | ||
import unicash.logic.commands.exceptions.CommandException; | ||
import unicash.logic.parser.CliSyntax; | ||
import unicash.model.Model; | ||
import unicash.model.budget.Budget; | ||
|
||
/** | ||
* Adds a budget to UniCash. | ||
*/ | ||
public class AddBudgetCommand extends Command { | ||
public static final String COMMAND_WORD = "add_budget"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a budget to UniCa$h. \n" | ||
+ "\n" | ||
+ "Parameters: " | ||
+ CliSyntax.PREFIX_AMOUNT + "AMOUNT " | ||
+ CliSyntax.PREFIX_INTERVAL + "TYPE " | ||
+ "\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ CliSyntax.PREFIX_AMOUNT + "300 " | ||
+ CliSyntax.PREFIX_INTERVAL + "month "; | ||
|
||
public static final String MESSAGE_SUCCESS = "New budget added: \n\n%1$s"; | ||
|
||
private final Budget budget; | ||
|
||
/** | ||
* Creates an AddBudgetCommand to add the specified {@code Budget} | ||
*/ | ||
public AddBudgetCommand(Budget budget) { | ||
requireNonNull(budget); | ||
this.budget = budget; | ||
} | ||
/** | ||
* Executes the command and returns the result message. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return feedback message of the operation result for display | ||
* @throws CommandException If an error occurs during command execution. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.setBudget(budget); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, UniCashMessages.formatBudget(budget))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof AddBudgetCommand)) { | ||
return false; | ||
} | ||
|
||
AddBudgetCommand otherCommand = (AddBudgetCommand) other; | ||
return budget.equals(otherCommand.budget); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("budget", budget) | ||
.toString(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/unicash/logic/commands/EditBudgetCommand.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,76 @@ | ||
package unicash.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import unicash.commons.util.ToStringBuilder; | ||
import unicash.logic.commands.exceptions.CommandException; | ||
import unicash.logic.parser.CliSyntax; | ||
import unicash.model.Model; | ||
import unicash.model.budget.Budget; | ||
|
||
/** | ||
* Edits the budget of the specified interval. | ||
*/ | ||
public class EditBudgetCommand extends Command { | ||
public static final String COMMAND_WORD = "edit_budget"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the budget of the specified interval. " | ||
+ "Existing values will be overwritten by the input values." | ||
+ "\n" | ||
+ "Parameters: " | ||
+ CliSyntax.PREFIX_AMOUNT + "AMOUNT " | ||
+ CliSyntax.PREFIX_INTERVAL + "TYPE " | ||
+ "\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ CliSyntax.PREFIX_AMOUNT + "300 " | ||
+ CliSyntax.PREFIX_INTERVAL + "month "; | ||
|
||
public static final String MESSAGE_EDIT_BUDGET_SUCCESS = "Edited Budget: \n\n%1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
|
||
public final Budget budget; | ||
|
||
/** | ||
* Creates an EditBudgetCommand to edit the specified {@code Budget} | ||
*/ | ||
public EditBudgetCommand(Budget budget) { | ||
requireNonNull(budget); | ||
this.budget = budget; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof EditBudgetCommand)) { | ||
return false; | ||
} | ||
|
||
EditBudgetCommand e = (EditBudgetCommand) other; | ||
return budget.equals(e.budget); | ||
} | ||
|
||
/** | ||
* Executes the command and returns the result message. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return feedback message of the operation result for display | ||
* @throws CommandException If an error occurs during command execution. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
//TODO: Edit budget command | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("budget", budget) | ||
.toString(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/unicash/logic/parser/AddBudgetCommandParser.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,50 @@ | ||
package unicash.logic.parser; | ||
|
||
import static unicash.logic.UniCashMessages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static unicash.logic.parser.CliSyntax.PREFIX_AMOUNT; | ||
import static unicash.logic.parser.CliSyntax.PREFIX_INTERVAL; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import unicash.logic.commands.AddBudgetCommand; | ||
import unicash.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddBudgetCommand object | ||
*/ | ||
public class AddBudgetCommandParser implements Parser<AddBudgetCommand> { | ||
/** | ||
* Parses {@code userInput} into a command and returns it. | ||
* | ||
* @throws ParseException if {@code userInput} does not conform the expected format | ||
*/ | ||
@Override | ||
public AddBudgetCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_AMOUNT, PREFIX_INTERVAL); | ||
|
||
//check if mandatory fields (type, amt) are present | ||
if (!arePrefixesPresent(argMultimap, PREFIX_AMOUNT, PREFIX_INTERVAL) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddBudgetCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
//check for duplicates | ||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_AMOUNT, PREFIX_INTERVAL); | ||
|
||
//TODO: Parse amount and interval, and create new budget object | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values | ||
* @param argumentMultimap | ||
* @param prefixes | ||
* @return | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
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
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
Oops, something went wrong.