forked from nus-cs2103-AY2324S1/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-AY2324S1#108 from Chrainx/Match-Feature
add Match feature
- Loading branch information
Showing
21 changed files
with
746 additions
and
17 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
88 changes: 88 additions & 0 deletions
88
src/main/java/seedu/address/logic/commands/MatchCustomerCommand.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,88 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.customer.Budget; | ||
import seedu.address.model.customer.Customer; | ||
import seedu.address.model.property.Price; | ||
import seedu.address.model.property.PriceAndTagsInRangePredicate; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Match all properties in the property book to the user based on specific tags | ||
* and/or budget satisfy the customer criteria. | ||
*/ | ||
public class MatchCustomerCommand extends Command { | ||
public static final String COMMAND_WORD = "matchcust"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Match customers from the address book. \n" | ||
+ "Parameters: " | ||
+ "Index" + "\n" | ||
+ "Example: " + COMMAND_WORD + " 2"; | ||
|
||
public static final String MESSAGE_FAIL = "There is no customer with index "; | ||
private Index targetIndex; | ||
|
||
/** | ||
* Creates a MatchCustomerCommand to get all the specified {@code Property} | ||
*/ | ||
public MatchCustomerCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Customer> lastShownList = model.getFilteredCustomerList(); | ||
|
||
try { | ||
Customer targetCustomer = lastShownList.get(targetIndex.getZeroBased()); | ||
Budget budget = targetCustomer.getBudget(); | ||
Set<Tag> tags = targetCustomer.getTags(); | ||
|
||
Price maxPrice = budget.convertToPrice(); | ||
PriceAndTagsInRangePredicate predicate = new PriceAndTagsInRangePredicate(maxPrice, tags); | ||
|
||
model.updateMatchedCustomerList(targetCustomer, predicate); | ||
|
||
return new CommandResult( | ||
String.format( | ||
Messages.MESSAGE_CUSTOMERS_MATCH_OVERVIEW + targetIndex.getOneBased(), | ||
model.getFilteredPropertyList().size() | ||
) | ||
); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new CommandException(MESSAGE_FAIL + targetIndex.getOneBased()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MatchCustomerCommand)) { | ||
return false; | ||
} | ||
|
||
MatchCustomerCommand otherMatchCustomerCommand = (MatchCustomerCommand) other; | ||
return targetIndex.equals(otherMatchCustomerCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("Index", targetIndex) | ||
.toString(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/seedu/address/logic/commands/MatchPropertyCommand.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,89 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.customer.Budget; | ||
import seedu.address.model.customer.BudgetAndTagsInRangePredicate; | ||
import seedu.address.model.property.Price; | ||
import seedu.address.model.property.Property; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Match all properties in the property book to the user based on specific tags | ||
* and/or budget satisfy the customer criteria. | ||
*/ | ||
public class MatchPropertyCommand extends Command { | ||
public static final String COMMAND_WORD = "matchprop"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Match properties from the property book. \n" | ||
+ "Parameters: " | ||
+ "Index" + "\n" | ||
+ "Example: " + COMMAND_WORD + " 2"; | ||
|
||
public static final String MESSAGE_FAIL = "There is no property with index "; | ||
private Index targetIndex; | ||
|
||
/** | ||
* Creates a MatchPropertyCommand to get all the specified {@code Customer} | ||
*/ | ||
public MatchPropertyCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Property> lastShownList = model.getFilteredPropertyList(); | ||
|
||
try { | ||
Property targetProperty = lastShownList.get(targetIndex.getZeroBased()); | ||
|
||
Price price = targetProperty.getPrice(); | ||
Set<Tag> tags = targetProperty.getTags(); | ||
|
||
Budget minBudget = price.convertToBudget(); | ||
BudgetAndTagsInRangePredicate predicate = new BudgetAndTagsInRangePredicate(minBudget, tags); | ||
|
||
model.updateMatchedPropertyList(targetProperty, predicate); | ||
|
||
return new CommandResult( | ||
String.format( | ||
Messages.MESSAGE_PROPERTIES_MATCH_OVERVIEW + targetIndex.getOneBased(), | ||
model.getFilteredCustomerList().size() | ||
) | ||
); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new CommandException(MESSAGE_FAIL + targetIndex.getOneBased()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MatchPropertyCommand)) { | ||
return false; | ||
} | ||
|
||
MatchPropertyCommand otherMatchPropertyCommand = (MatchPropertyCommand) other; | ||
return targetIndex.equals(otherMatchPropertyCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("Index", targetIndex) | ||
.toString(); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/seedu/address/logic/parser/MatchCustomerCommandParser.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,37 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.MatchCustomerCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Filters and lists all customers in address book whose budget and/or tags are selected. | ||
*/ | ||
public class MatchCustomerCommandParser implements Parser<MatchCustomerCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the FilterCommand | ||
* and returns a FilterCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public MatchCustomerCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
Index index; | ||
|
||
try { | ||
index = ParserUtil.parseIndex(args); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MatchCustomerCommand.MESSAGE_USAGE), | ||
pe | ||
); | ||
} | ||
|
||
return new MatchCustomerCommand(index); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/seedu/address/logic/parser/MatchPropertyCommandParser.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,37 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.MatchPropertyCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Match and lists all customers in address book whose budget and/or tags satisfy with the property. | ||
*/ | ||
public class MatchPropertyCommandParser implements Parser<MatchPropertyCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the MatchPropertyCommand | ||
* and returns a MatchPropertyCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public MatchPropertyCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
Index index; | ||
|
||
try { | ||
index = ParserUtil.parseIndex(args); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MatchPropertyCommand.MESSAGE_USAGE), | ||
pe | ||
); | ||
} | ||
|
||
return new MatchPropertyCommand(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
Oops, something went wrong.