forked from nus-cs2103-AY2021S1/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-AY2021S1#107 from zhengweii/find-wareho…
…use-command Find warehouse command
- Loading branch information
Showing
25 changed files
with
381 additions
and
108 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
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
42 changes: 42 additions & 0 deletions
42
src/main/java/seedu/clinic/model/supplier/SupplierProductsContainKeywordsPredicate.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,42 @@ | ||
package seedu.clinic.model.supplier; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.clinic.commons.util.StringUtil; | ||
import seedu.clinic.model.product.Product; | ||
|
||
/** | ||
* Tests that any of the {@code Product} sold by {@code Supplier} matches any of the keywords given. | ||
*/ | ||
public class SupplierProductsContainKeywordsPredicate implements Predicate<Supplier> { | ||
private final List<String> keywords; | ||
|
||
public SupplierProductsContainKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
@Override | ||
public boolean test(Supplier supplier) { | ||
Product[] products = supplier.getProducts().toArray(Product[]::new); | ||
for (int i = 0; i < products.length; i++) { | ||
String productName = products[i].getProductName().fullName; | ||
boolean match = keywords.stream() | ||
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(productName, keyword)); | ||
|
||
if (match) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof SupplierProductsContainKeywordsPredicate // instanceof handles nulls | ||
&& keywords.equals(((SupplierProductsContainKeywordsPredicate) other).keywords)); // state check | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/seedu/clinic/model/warehouse/WarehouseProductsContainKeywordsPredicate.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,42 @@ | ||
package seedu.clinic.model.warehouse; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.clinic.commons.util.StringUtil; | ||
import seedu.clinic.model.product.Product; | ||
|
||
/** | ||
* Tests that any of the {@code Product} stored in a {@code Warehouse} matches any of the keywords given. | ||
*/ | ||
public class WarehouseProductsContainKeywordsPredicate implements Predicate<Warehouse> { | ||
private final List<String> keywords; | ||
|
||
public WarehouseProductsContainKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
@Override | ||
public boolean test(Warehouse warehouse) { | ||
Product[] products = warehouse.getProducts().toArray(Product[]::new); | ||
for (int i = 0; i < products.length; i++) { | ||
String productName = products[i].getProductName().fullName; | ||
boolean match = keywords.stream() | ||
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(productName, keyword)); | ||
|
||
if (match) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof WarehouseProductsContainKeywordsPredicate // instanceof handles nulls | ||
&& keywords.equals(((WarehouseProductsContainKeywordsPredicate) other).keywords)); // state check | ||
} | ||
|
||
} |
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
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.