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#119 from Chrainx/Adjust-match
Adjust Match Predicate
- Loading branch information
Showing
5 changed files
with
117 additions
and
5 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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/seedu/address/model/customer/BudgetAndOneTagsPredicate.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,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(); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/seedu/address/model/property/PriceAndOneTagsPredicate.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,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(); | ||
} | ||
} |