I have a Product model
class Product {
String name;
ArrayList<ProductFeature> productFeatures;
}
I have a ProductFeature model
class ProductFeature {
String name;
String value;
}
Product Features name-value pairs
- For name "Color", value can be [black, red, yellow, etc]
- For name "Size", value can be [34, 38, 42, 46, 47, etc]
- For name "Weight", value can be [10K, 20K, 40K, 41K, etc]
For one name, there will be only one value. A Product can't have two ProductFeatures with same name.
I have many products, stored in an ArrayList of Product e.g. For Product (feature, feature, feature), I have following data :-
e.g. (color, size, weight)
#1 Product ( black, 34, 10.12 )
#2 Product ( yellow, 39, 20.00 )
#3 Product ( black, 67, 22.97 )
#4 Product ( red, 12, 48.21 )
#5 Product ( red, 52, 12.13 )
#6 Product ( blue, 85, 10.00 )*
#7 Product ( blue, 10, 80.00 )
#8 Product ( fire, 87, 40.52 )
Back-end says that a product with these features is selected
[color=blue, size=85, weight=10.00]
I store these features in a HashMap<String, String>
[
(color, blue),
(size, 85),
(weight, 10.00)
]
I have to find this selected product with these features from my list of products
for (Product product : products) {
ArrayList<ProductFeature> productFeatures = product.getProductFeatures();
// I am stuck here
}
How do I compare this list productFeatures
with my HashMap<String, String>
to find out which product from products
has all the features from HashMap?
If more information is needed, please ask.