Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2324S1#119 from Chrainx/Adjust-match
Browse files Browse the repository at this point in the history
Adjust Match Predicate
  • Loading branch information
Chrainx authored Nov 1, 2023
2 parents 37c8238 + 4282c60 commit b1b9327
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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.property.PriceAndOneTagsPredicate;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ public CommandResult execute(Model model) throws CommandException {
Set<Tag> tags = targetCustomer.getTags();

Price maxPrice = budget.convertToPrice();
PriceAndTagsInRangePredicate predicate = new PriceAndTagsInRangePredicate(maxPrice, tags);
PriceAndOneTagsPredicate predicate = new PriceAndOneTagsPredicate(maxPrice, tags);

model.updateMatchedCustomerList(targetCustomer, predicate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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.customer.BudgetAndOneTagsPredicate;
import seedu.address.model.property.Price;
import seedu.address.model.property.Property;
import seedu.address.model.tag.Tag;
Expand Down Expand Up @@ -50,7 +50,7 @@ public CommandResult execute(Model model) throws CommandException {
Set<Tag> tags = targetProperty.getTags();

Budget minBudget = price.convertToBudget();
BudgetAndTagsInRangePredicate predicate = new BudgetAndTagsInRangePredicate(minBudget, tags);
BudgetAndOneTagsPredicate predicate = new BudgetAndOneTagsPredicate(minBudget, tags);

model.updateMatchedPropertyList(targetProperty, predicate);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.address.model.customer;

import java.util.Set;
import java.util.function.Predicate;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.tag.Tag;

/**
* Tests that a {@code Customer}'s {@code Budget} and/or {@code Tags} are in range of the specified budget and/or tags.
*/
public class BudgetAndOneTagsPredicate implements Predicate<Customer> {
private final Budget budget;
private final Set<Tag> tags;

/**
* Constructs a {@code BudgetAndOneTagsPredicate}.
*
* @param budget the specified budget if any
* @param tags the specified tags if any
*/
public BudgetAndOneTagsPredicate(Budget budget, Set<Tag> tags) {
this.budget = budget;
this.tags = tags;
}

@Override
public boolean test(Customer customer) {
return tags.stream().anyMatch(tag -> customer.getTags().contains(tag))
&& customer.getBudget().isInRangeBudget(budget);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof BudgetAndTagsInRangePredicate)) {
return false;
}

BudgetAndOneTagsPredicate otherBudgetAndOneTagsPredicate = (BudgetAndOneTagsPredicate) other;
return budget.equals(otherBudgetAndOneTagsPredicate.budget)
&& tags.equals(otherBudgetAndOneTagsPredicate.tags);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("budget", budget)
.add("tags", tags).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import seedu.address.model.tag.Tag;

/**
* Tests that a {@code Customer}'s {@code Budget} and/or {@code Tags} are in range of the specified budget and/or tags.
* Tests that a {@code Customer}'s {@code Budget}
* and/or minimum one {@code Tags} are in range of the specified budget and/or tags.
*/
public class BudgetAndTagsInRangePredicate implements Predicate<Customer> {
private final Budget budget;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.address.model.property;

import java.util.Set;
import java.util.function.Predicate;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.tag.Tag;

/**
* Tests that a {@code Property}'s {@code Price}
* and/or minimal one {@code Tags} are in range of the specified price and/or tags.
*/
public class PriceAndOneTagsPredicate implements Predicate<Property> {
private final Price price;
private final Set<Tag> tags;

/**
* Constructs a {@code PriceAndOneTagsPredicate}.
*
* @param price the specified price if any
* @param tags the specified tags if any
*/
public PriceAndOneTagsPredicate(Price price, Set<Tag> tags) {
this.price = price;
this.tags = tags;
}

@Override
public boolean test(Property property) {
return tags.stream().anyMatch(tag -> property.getTags().contains(tag))
&& property.getPrice().isInRangePrice(price);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof PriceAndTagsInRangePredicate)) {
return false;
}

PriceAndOneTagsPredicate otherBudgetAndOneTagsPredicate = (PriceAndOneTagsPredicate) other;
return price.equals(otherBudgetAndOneTagsPredicate.price)
&& tags.equals(otherBudgetAndOneTagsPredicate.tags);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("price", price)
.add("tags", tags).toString();
}
}

0 comments on commit b1b9327

Please sign in to comment.