diff --git a/src/main/java/unicash/logic/parser/FilterCommandParser.java b/src/main/java/unicash/logic/parser/FilterCommandParser.java index 094eb6feafc..7be0ae993d4 100644 --- a/src/main/java/unicash/logic/parser/FilterCommandParser.java +++ b/src/main/java/unicash/logic/parser/FilterCommandParser.java @@ -13,8 +13,13 @@ import unicash.logic.commands.FilterCommand; import unicash.logic.parser.exceptions.ParseException; +import unicash.model.category.Category; +import unicash.model.category.UniqueCategoryList; import unicash.model.commons.Amount; +import unicash.model.transaction.DateTime; +import unicash.model.transaction.Location; import unicash.model.transaction.Name; +import unicash.model.transaction.Type; import unicash.model.transaction.predicates.TransactionContainsAllKeywordsPredicate; /** @@ -22,10 +27,7 @@ */ public class FilterCommandParser implements Parser { - public static final String EMPTY_STRING = ""; - public static final List EMPTY_STRING_LIST = List.of(EMPTY_STRING); - - private static TransactionContainsAllKeywordsPredicate filterPredicate = + private TransactionContainsAllKeywordsPredicate filterPredicate = new TransactionContainsAllKeywordsPredicate(); /** @@ -46,19 +48,41 @@ public FilterCommand parse(String args) throws ParseException { String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_USAGE)); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TYPE, PREFIX_AMOUNT, PREFIX_DATETIME, - PREFIX_LOCATION); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_CATEGORY, PREFIX_TYPE, + PREFIX_AMOUNT, PREFIX_DATETIME, PREFIX_LOCATION); if (argMultimap.getValue(PREFIX_NAME).isPresent()) { Name transactionName = ParserUtil.parseTransactionName(argMultimap.getValue(PREFIX_NAME).get()); - filterPredicate.setName(transactionName.toString()); + filterPredicate.setNameKeyword(transactionName.toString()); } if (argMultimap.getValue(PREFIX_AMOUNT).isPresent()) { Amount transactionAmount = ParserUtil.parseAmount(argMultimap.getValue(PREFIX_AMOUNT).get()); - filterPredicate.setAmount(Amount.amountToDecimalString(transactionAmount)); + filterPredicate.setAmountKeyword(Amount.amountToDecimalString(transactionAmount)); + } + + if (argMultimap.getValue(PREFIX_CATEGORY).isPresent()) { + Category transactionCategory = ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).get()); + filterPredicate.setCategoryKeyword(transactionCategory.toString()); + } + + if (argMultimap.getValue(PREFIX_LOCATION).isPresent()) { + Location transactionLocation = ParserUtil.parseLocation( + argMultimap.getValue(PREFIX_LOCATION).get()); + filterPredicate.setLocationKeyword(transactionLocation.toString()); + } + + if (argMultimap.getValue(PREFIX_DATETIME).isPresent()) { + DateTime transactionDateTime = ParserUtil.parseDateTime( + argMultimap.getValue(PREFIX_DATETIME).get()); + filterPredicate.setDateTimeKeyword(transactionDateTime.toString()); + } + + if (argMultimap.getValue(PREFIX_TYPE).isPresent()) { + Type transactionType = ParserUtil.parseType(argMultimap.getValue(PREFIX_TYPE).get()); + filterPredicate.setTypeKeyword(transactionType.toString()); } return new FilterCommand(filterPredicate); diff --git a/src/main/java/unicash/model/transaction/predicates/TransactionContainsAllKeywordsPredicate.java b/src/main/java/unicash/model/transaction/predicates/TransactionContainsAllKeywordsPredicate.java index 028194d7e06..4119e26fa40 100644 --- a/src/main/java/unicash/model/transaction/predicates/TransactionContainsAllKeywordsPredicate.java +++ b/src/main/java/unicash/model/transaction/predicates/TransactionContainsAllKeywordsPredicate.java @@ -81,7 +81,7 @@ public Predicate composeAllActivePredicates() { return composedPredicate; } - public void setAmount(String amount) { + public void setAmountKeyword(String amount) { BooleanPredicatePair predicatePair = new BooleanPredicatePair(true, new TransactionAmountContainsValuePredicate( Collections.singletonList(amount))); @@ -89,7 +89,7 @@ public void setAmount(String amount) { predicatePairMap.put(TransactionProperty.AMOUNT, predicatePair); } - public void setName(String name) { + public void setNameKeyword(String name) { BooleanPredicatePair predicatePair = new BooleanPredicatePair(true, new TransactionNameContainsKeywordsPredicate( Collections.singletonList(name))); @@ -97,6 +97,40 @@ public void setName(String name) { predicatePairMap.put(TransactionProperty.NAME, predicatePair); } + public void setLocationKeyword(String location) { + BooleanPredicatePair predicatePair = new BooleanPredicatePair(true, + new TransactionLocationContainsKeywordsPredicate( + Collections.singletonList(location))); + + predicatePairMap.put(TransactionProperty.LOCATION, predicatePair); + } + + public void setDateTimeKeyword(String dateTime) { + BooleanPredicatePair predicatePair = new BooleanPredicatePair(true, + new TransactionDateTimeContainsValuePredicate( + Collections.singletonList(dateTime))); + + predicatePairMap.put(TransactionProperty.NAME, predicatePair); + } + + public void setTypeKeyword(String type) { + BooleanPredicatePair predicatePair = new BooleanPredicatePair(true, + new TransactionTypeContainsValuePredicate( + Collections.singletonList(type))); + + predicatePairMap.put(TransactionProperty.TYPE, predicatePair); + } + + public void setCategoryKeyword(String category) { + BooleanPredicatePair predicatePair = new BooleanPredicatePair(true, + new TransactionTypeContainsValuePredicate( + Collections.singletonList(category))); + + predicatePairMap.put(TransactionProperty.CATEGORY, predicatePair); + } + + + @Override public boolean equals(Object other) {