Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicax941 committed Nov 8, 2019
2 parents e8ba6ff + 5cb9715 commit ce7667b
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public final class GuiltTripCommandSuggester {
*/
public static String getSuggestionString(String textInput) {
try {
// Easter egg!!
if (textInput.equalsIgnoreCase("uwu")) {
return "uwu";
}

String commandWord = getCommandWord(textInput);

if (commandWord.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
throw new CommandException(MESSAGE_INVALID_CATEGORY);
}

if (entryToEdit.isSameEntry(editedEntry) && model.hasBudget(editedEntry)) {
if (entryToEdit.isSameBudget(editedEntry) && model.hasBudget(editedEntry)) {
throw new CommandException(MESSAGE_DUPLICATE_ENTRY);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.guilttrip.logic.parser.addcommandparsers;

import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -35,17 +34,16 @@ public class AddBudgetCommandParser implements Parser<AddBudgetCommand> {
/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public AddBudgetCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE,
PREFIX_PERIOD, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE, PREFIX_PERIOD)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddBudgetCommand.MESSAGE_USAGE));
}
ParserUtil.errorIfCompulsoryPrefixMissing(AddBudgetCommand.MESSAGE_USAGE, argMultimap, false,
PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE, PREFIX_PERIOD);

String categoryName = argMultimap.getValue(PREFIX_CATEGORY).get();
Description desc = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESC).get());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.guilttrip.logic.parser.addcommandparsers;

import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DESC;

Expand All @@ -10,6 +9,7 @@
import seedu.guilttrip.logic.parser.ArgumentMultimap;
import seedu.guilttrip.logic.parser.ArgumentTokenizer;
import seedu.guilttrip.logic.parser.Parser;
import seedu.guilttrip.logic.parser.ParserUtil;
import seedu.guilttrip.logic.parser.Prefix;
import seedu.guilttrip.logic.parser.exceptions.ParseException;
import seedu.guilttrip.model.entry.Category;
Expand All @@ -28,10 +28,8 @@ public AddCategoryCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_CATEGORY, PREFIX_DESC);

if (!arePrefixesPresent(argMultimap, PREFIX_CATEGORY, PREFIX_DESC)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCategoryCommand.MESSAGE_USAGE));
}
ParserUtil.errorIfCompulsoryPrefixMissing(AddCategoryCommand.MESSAGE_USAGE, argMultimap, false,
PREFIX_CATEGORY, PREFIX_DESC);

String categoryType = argMultimap.getValue(PREFIX_CATEGORY).get().toLowerCase();
String categoryName = argMultimap.getValue(PREFIX_DESC).get().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.guilttrip.logic.parser.addcommandparsers;

import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand All @@ -10,6 +9,7 @@
import java.util.Set;
import java.util.stream.Stream;

import seedu.guilttrip.logic.commands.addcommands.AddBudgetCommand;
import seedu.guilttrip.logic.commands.addcommands.AddExpenseCommand;
import seedu.guilttrip.logic.parser.ArgumentMultimap;
import seedu.guilttrip.logic.parser.ArgumentTokenizer;
Expand Down Expand Up @@ -40,10 +40,8 @@ public AddExpenseCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE,
PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddExpenseCommand.MESSAGE_USAGE));
}
ParserUtil.errorIfCompulsoryPrefixMissing(AddBudgetCommand.MESSAGE_USAGE, argMultimap, false,
PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE);

String categoryName = argMultimap.getValue(PREFIX_CATEGORY).get();
Description desc = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESC).get());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.guilttrip.logic.parser.addcommandparsers;

import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -40,10 +39,8 @@ public AddIncomeCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE,
PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddIncomeCommand.MESSAGE_USAGE));
}
ParserUtil.errorIfCompulsoryPrefixMissing(AddIncomeCommand.MESSAGE_USAGE, argMultimap, false,
PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE);

String categoryName = argMultimap.getValue(PREFIX_CATEGORY).get();
Description desc = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESC).get());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.guilttrip.logic.parser.addcommandparsers;

import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.guilttrip.logic.parser.CliSyntax.PREFIX_DATE;
Expand Down Expand Up @@ -40,10 +39,8 @@ public AddWishCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE,
PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddWishCommand.MESSAGE_USAGE));
}
ParserUtil.errorIfCompulsoryPrefixMissing(AddWishCommand.MESSAGE_USAGE, argMultimap, false,
PREFIX_CATEGORY, PREFIX_DESC, PREFIX_AMOUNT, PREFIX_DATE);

String categoryName = argMultimap.getValue(PREFIX_CATEGORY).get();
Description desc = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESC).get());
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/seedu/guilttrip/model/entry/Budget.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void setSpentAmount(Amount amount) {
}

public void setSpent(FilteredList<Expense> filteredExpenses) {
this.filteredExpenses = filteredExpenses;
this.filteredExpenses = new FilteredList<>(filteredExpenses);
expenseMatchesBudgetPredicate = new ExpenseMatchesBudgetPredicate(getCategory(), startDate, endDate);
this.filteredExpenses.setPredicate(expenseMatchesBudgetPredicate);
}
Expand All @@ -96,6 +96,24 @@ public Budget modifiedBudget(String newName) {
this.getAmount(), super.getTags(), this.spent);
}

/**
* Returns true if both entries of the same name have at least one other identity field that is the same.
* This defines a weaker notion of equality between two entries.
*/
public boolean isSameBudget(Budget otherEntry) {
if (otherEntry == this) {
return true;
}

return otherEntry != null
&& otherEntry.getCategory().equals(getCategory())
&& otherEntry.getDesc().equals(getDesc())
&& otherEntry.getAmount().equals(getAmount())
&& otherEntry.getTags().equals(getTags())
&& otherEntry.getDate().equals(getDate())
&& otherEntry.getPeriod().equals(getPeriod());
}

/**
* Returns true if both budgets have the same data fields.
* This defines a stronger notion of equality between two entries.
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/seedu/guilttrip/model/entry/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ public class Date {
.appendOptional(DateTimeFormatter.ofPattern("d-MM-uuuu"))
.appendOptional(DateTimeFormatter.ofPattern("dd-MM-uuuu"))
.appendOptional(DateTimeFormatter.ofPattern("dd.MM.uuuu"))
.appendOptional(DateTimeFormatter.ofPattern("d.MM.uuuu")).toFormatter();
.appendOptional(DateTimeFormatter.ofPattern("d.MM.uuuu"))
.appendOptional(DateTimeFormatter.ofPattern("d/M"))
.appendOptional(DateTimeFormatter.ofPattern("dd/M"))
.appendOptional(DateTimeFormatter.ofPattern("d/MM"))
.appendOptional(DateTimeFormatter.ofPattern("dd/MM"))
.parseDefaulting(ChronoField.YEAR, LocalDate.now().getYear())
.toFormatter();

private static final DateTimeFormatter INPUTFORMATTERWITHRESOLVER = INPUTFORMATTER
.withResolverStyle(ResolverStyle.STRICT);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/guilttrip/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class MainWindow extends UiPart<Stage> {
private StatisticsWindow statsListPanel;
private StatisticsPieChartHolder statsGraphics;
private StatisticsBarChart statsBar;
private BudgetPanel budgetsPanel;

private boolean isStatsWindow;
private boolean isStatsGraphicsWindow;
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/seedu/guilttrip/ui/budget/BudgetCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class BudgetCard extends UiPart<Region> {
@FXML
private Label date;
@FXML
private Label left;
private Label spent;
@FXML
private ProgressBar progressBar;
@FXML
Expand All @@ -55,13 +55,17 @@ public BudgetCard(Budget budget, int displayedIndex) {
String fullDesc = budget.getDesc().fullDesc;
desc.setText(fullDesc);
date.setText(budget.getDate().toString() + " - " + budget.getEndDate().toString());
double leftAmount = budget.getAmount().value - budget.getSpent().value;
double spentAmount = budget.getSpent().value;
double totalAmount = budget.getAmount().value;
//left.setText("left: $" + leftAmount + " out of: $" + budget.getAmount().value);
left.setText("$" + leftAmount);
spent.setText("$" + spentAmount);
total.setText("$" + totalAmount);

progressBar.setProgress(leftAmount / totalAmount);
progressBar.setProgress(spentAmount / totalAmount);
if (spentAmount / totalAmount >= 1) {
progressBar.setStyle("-fx-accent: IndianRed;");
} else {
progressBar.setStyle("-fx-accent: SteelBlue;");
}

category.setText(budget.getCategory().toString());

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/budget/BudgetListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</HBox>

<HBox GridPane.columnIndex="1" spacing="5">
<Label fx:id="left" styleClass="cell_big_label_amt" text="\$left" />
<Label fx:id="spent" styleClass="cell_big_label_amt" text="\$spent" />
<ProgressBar fx:id="progressBar" />
<Label fx:id="total" styleClass="cell_big_label_amt" text="\$total"/>
</HBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ public void parse_allFieldsPresent_success() {

@Test
public void parse_compulsoryFieldMissing_failure() {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT , AddCategoryCommand.MESSAGE_USAGE);
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCategoryCommand.MESSAGE_USAGE);

// missing category prefix
assertParseFailure(parser, VALID_CATEGORY_TYPE_EXPENSE + CATEGORY_NAME_EXPENSE, expectedMessage);
assertParseFailure(parser, VALID_CATEGORY_TYPE_EXPENSE + CATEGORY_NAME_EXPENSE);

// missing Category name prefix
assertParseFailure(parser, CATEGORY_TYPE_EXPENSE + VALID_CATEGORY_NAME_EXPENSE_FOOD, expectedMessage);
assertParseFailure(parser, CATEGORY_TYPE_EXPENSE + VALID_CATEGORY_NAME_EXPENSE_FOOD);

// all prefixes missing
assertParseFailure(parser, VALID_CATEGORY_TYPE_EXPENSE + VALID_CATEGORY_NAME_EXPENSE_FOOD,
expectedMessage);
assertParseFailure(parser, VALID_CATEGORY_TYPE_EXPENSE + VALID_CATEGORY_NAME_EXPENSE_FOOD);
}

@Test
Expand All @@ -59,7 +58,6 @@ public void parse_invalidValue_failure() {
Category.MESSAGE_CONSTRAINTS_TYPE);

// non-empty preamble
assertParseFailure(parser, PREAMBLE_NON_EMPTY + CATEGORY_TYPE_INCOME + CATEGORY_NAME_INCOME,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCategoryCommand.MESSAGE_USAGE));
assertParseFailure(parser, PREAMBLE_NON_EMPTY + CATEGORY_TYPE_INCOME + CATEGORY_NAME_INCOME);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.guilttrip.logic.parser;

import static seedu.guilttrip.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.guilttrip.logic.commands.CommandTestUtil.AMOUNT_CLOTHING_EXPENSE;
import static seedu.guilttrip.logic.commands.CommandTestUtil.AMOUNT_FOOD_EXPENSE;
import static seedu.guilttrip.logic.commands.CommandTestUtil.CATEGORY_CLOTHING_EXPENSE;
Expand Down Expand Up @@ -49,7 +48,7 @@ public void parse_allFieldsPresent_success() {

// whitespace only preamble
assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_FOOD_EXPENSE + AMOUNT_FOOD_EXPENSE
+ CATEGORY_FOOD_EXPENSE + DATE_FOOD_EXPENSE + TAG_DESC_FOOD,
+ CATEGORY_FOOD_EXPENSE + DATE_FOOD_EXPENSE + TAG_DESC_FOOD,
new AddExpenseCommand(expectedExpense));

// multiple tags - all accepted
Expand All @@ -73,39 +72,32 @@ public void parse_optionalFieldsMissing_success() {

@Test
public void parse_compulsoryFieldMissing_failure() {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT , AddExpenseCommand.MESSAGE_USAGE);

// missing name prefix
assertParseFailure(parser, VALID_DESC_CLOTHING_EXPENSE + AMOUNT_CLOTHING_EXPENSE
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
expectedMessage);
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT);

// missing amount prefix
assertParseFailure(parser, NAME_DESC_CLOTHING_EXPENSE + VALID_AMOUNT_CLOTHING_EXPENSE
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
expectedMessage);
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT);

// missing category prefix
assertParseFailure(parser, NAME_DESC_CLOTHING_EXPENSE + AMOUNT_CLOTHING_EXPENSE
+ VALID_CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
expectedMessage);
+ VALID_CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT);

// missing guilttrip prefix
assertParseFailure(parser, NAME_DESC_CLOTHING_EXPENSE + AMOUNT_CLOTHING_EXPENSE
+ CATEGORY_CLOTHING_EXPENSE + VALID_DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
expectedMessage);
+ CATEGORY_CLOTHING_EXPENSE + VALID_DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT);

// all prefixes missing
assertParseFailure(parser, NAME_DESC_CLOTHING_EXPENSE + VALID_AMOUNT_CLOTHING_EXPENSE
+ VALID_CATEGORY_CLOTHING_EXPENSE + VALID_DATE_CLOTHING_EXPENSE + VALID_TAG_CLOTHING_CLOTHES,
expectedMessage);
+ VALID_CATEGORY_CLOTHING_EXPENSE + VALID_DATE_CLOTHING_EXPENSE + VALID_TAG_CLOTHING_CLOTHES);
}

@Test
public void parse_invalidValue_failure() {
// invalid name
assertParseFailure(parser, INVALID_NAME_DESC + AMOUNT_CLOTHING_EXPENSE
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
Description.MESSAGE_CONSTRAINTS);

// invalid amount
Expand All @@ -130,8 +122,7 @@ public void parse_invalidValue_failure() {

// non-empty preamble
assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_CLOTHING_EXPENSE + AMOUNT_CLOTHING_EXPENSE
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddExpenseCommand.MESSAGE_USAGE));
+ CATEGORY_CLOTHING_EXPENSE + DATE_CLOTHING_EXPENSE + TAG_DESC_CLOTHING + TAG_DESC_WANT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ public static void assertParseFailure(Parser parser, String userInput, String ex
assertEquals(expectedMessage, ie.getMessage());
}
}

/**
* Asserts that the parsing of {@code userInput} by {@code parser} is unsuccessful and the error message
* equals to {@code expectedMessage}.
*/
public static void assertParseFailure(Parser parser, String userInput) {
try {
parser.parse(userInput);
throw new AssertionError("The expected ParseException was not thrown.");
} catch (Exception e) {
return;
}
}
}

0 comments on commit ce7667b

Please sign in to comment.