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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,45 +26,45 @@ public static Supplier[] getSampleSuppliers() { | |
return new Supplier[] { | ||
new Supplier(new Name("Alex Yeoh Ltd"), new Phone("87438807"), new Email("[email protected]"), | ||
new Remark("long term partner"), | ||
getProductSet(Map.of("Panadol", new String[]{"fever"}))), | ||
getProductSet(new HashSet<Product>(), Map.of("Panadol", new String[]{"fever"}))), | ||
new Supplier(new Name("Bernice Yu Pte Ltd"), new Phone("99272758"), new Email("[email protected]"), | ||
new Remark("long term partner"), | ||
getProductSet(Map.of("Panadol", new String[]{"fever"}))), | ||
getProductSet(new HashSet<Product>(), Map.of("Panadol", new String[]{"fever"}))), | ||
new Supplier(new Name("Charlotte Oliveiro Ltd"), new Phone("93210283"), new Email("[email protected]"), | ||
new Remark("long term partner"), | ||
getProductSet(Map.of("Panadol", new String[]{"fever"}))), | ||
getProductSet(new HashSet<Product>(), Map.of("Panadol", new String[]{"fever"}))), | ||
new Supplier(new Name("David Li Pte Ltd"), new Phone("91031282"), new Email("[email protected]"), | ||
new Remark("long term partner"), | ||
getProductSet(Map.of("Panadol", new String[]{"fever"}))), | ||
getProductSet(new HashSet<Product>(), Map.of("Panadol", new String[]{"fever"}))), | ||
new Supplier(new Name("Irfan Ibrahim Pte Ltd"), new Phone("92492021"), new Email("[email protected]"), | ||
new Remark("long term partner"), | ||
getProductSet(Map.of("Panadol", new String[]{"fever"}))), | ||
getProductSet(new HashSet<Product>(), Map.of("Panadol", new String[]{"fever"}))), | ||
new Supplier(new Name("Roy Balakrishnan Pte Ltd"), new Phone("92624417"), new Email("[email protected]"), | ||
new Remark("long term partner"), | ||
getProductSet(Map.of("Panadol", new String[]{"fever"}))), | ||
getProductSet(new HashSet<Product>(), Map.of("Panadol", new String[]{"fever"}))), | ||
}; | ||
} | ||
|
||
public static Warehouse[] getSampleWarehouses() { | ||
return new Warehouse[] { | ||
new Warehouse(new Name("Alex Yeoh warehouse"), new Phone("87438807"), | ||
new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), | ||
getProductSetForWarehouse(Map.of("Panadol", 10))), | ||
getProductSetForWarehouse(new HashSet<Product>(), Map.of("Panadol", 10))), | ||
new Warehouse(new Name("Bernice Yu warehouse"), new Phone("99272758"), | ||
new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), | ||
getProductSetForWarehouse(Map.of("Panadol", 20))), | ||
getProductSetForWarehouse(new HashSet<Product>(), Map.of("Panadol", 20))), | ||
new Warehouse(new Name("Charlotte Oliveiro warehouse"), new Phone("93210283"), | ||
new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), | ||
getProductSetForWarehouse(Map.of("Panadol", 30))), | ||
getProductSetForWarehouse(new HashSet<Product>(), Map.of("Panadol", 30))), | ||
new Warehouse(new Name("David Li warehouse"), new Phone("91031282"), | ||
new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), | ||
getProductSetForWarehouse(Map.of("Panadol", 100))), | ||
getProductSetForWarehouse(new HashSet<Product>(), Map.of("Panadol", 100))), | ||
new Warehouse(new Name("Irfan Ibrahim warehouse"), new Phone("92492021"), | ||
new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), | ||
getProductSetForWarehouse(Map.of("Panadol", 50))), | ||
getProductSetForWarehouse(new HashSet<Product>(), Map.of("Panadol", 50))), | ||
new Warehouse(new Name("Roy Balakrishnan warehouse"), new Phone("92624417"), | ||
new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), | ||
getProductSetForWarehouse(Map.of("Panadol", 70))), | ||
getProductSetForWarehouse(new HashSet<Product>(), Map.of("Panadol", 70))), | ||
}; | ||
} | ||
|
||
|
@@ -93,8 +93,7 @@ public static Set<Tag> getTagSet(String... strings) { | |
/** | ||
* Returns a product set containing the hashmap of strings given. | ||
*/ | ||
public static Set<Product> getProductSet(Map<String, String[]> productMap) { | ||
Set<Product> productSet = new HashSet<>(); | ||
public static Set<Product> getProductSet(Set<Product> productSet, Map<String, String[]> productMap) { | ||
for (String productName:productMap.keySet()) { | ||
Set<Tag> productTags = getTagSet(productMap.get(productName)); | ||
Product product = new Product(new Name(productName), productTags); | ||
|
@@ -106,8 +105,7 @@ public static Set<Product> getProductSet(Map<String, String[]> productMap) { | |
/** | ||
* Returns a product set containing the hashmap of strings given. | ||
*/ | ||
public static Set<Product> getProductSetForWarehouse(Map<String, Integer> productMap) { | ||
Set<Product> productSet = new HashSet<>(); | ||
public static Set<Product> getProductSetForWarehouse(Set<Product> productSet, Map<String, Integer> productMap) { | ||
for (String productName:productMap.keySet()) { | ||
Product product = new Product(new Name(productName), productMap.get(productName)); | ||
productSet.add(product); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"name": "Supplier with invalid name field: Ha!ns Mu@ster", | ||
"phone": "9482424", | ||
"email": "[email protected]", | ||
"remark": "Trusted company" | ||
"remark": "Trusted seller" | ||
} ], | ||
"warehouse": [ ] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,13 @@ | |
"phone" : "95352563", | ||
"email" : "[email protected]", | ||
"remark" : "nearby", | ||
"products" : [ ] | ||
"products" : [{ | ||
"name": "Mask", | ||
"tagged": ["black"] | ||
}, { | ||
"name": "Thermometer", | ||
"tagged": ["digital"] | ||
}] | ||
}, { | ||
"name" : "Daniel Meier Ltd", | ||
"phone" : "87652533", | ||
|
@@ -38,13 +44,28 @@ | |
"phone" : "9482224", | ||
"email" : "[email protected]", | ||
"remark" : "industry leader", | ||
"products" : [ ] | ||
"products" : [{ | ||
"name": "Mask", | ||
"tagged": ["black"] | ||
}, { | ||
"name": "Medical Glove", | ||
"tagged": ["rubber"] | ||
}] | ||
}, { | ||
"name" : "Fiona Kunz Ltd", | ||
"phone" : "9482427", | ||
"email" : "[email protected]", | ||
"remark" : "specialises in antibiotics", | ||
"products" : [ ] | ||
"products" : [{ | ||
"name": "Mask", | ||
"tagged": ["black"] | ||
}, { | ||
"name": "Needle", | ||
"tagged": ["1mm"] | ||
}, { | ||
"name": "Cough Syrup", | ||
"tagged": ["cough"] | ||
}] | ||
}, { | ||
"name" : "George Best Ltd", | ||
"phone" : "9482442", | ||
|
Oops, something went wrong.