@Override
public Collection<Dish> getDishesContaining(Collection<Ingredient> ingredients) throws DatabaseException {
Collection<Dish> result = new ArrayList<>();
for (Dish currentDish : this.getAll()) {
if (currentDish.containsIngredient(ingredients)!=0) {
result.add(currentDish);
}
}
return result;
}
Overview:
Dish -> Param:
ArrayList<Ingredient> ingredients
Dish -> Funct:
containsIngredient(Collection<Ingredient> ingredients) : int
(returns int percentage howmany ingredients the given collection has with the dish)
Example:
For given Ingrediënt Collection= [X,Y,Z]
Dish A = [Ingredients:[X,Y,Z]], ->
dishA.containsIngredient(ingredientCollection)
=1Dish B = [Ingredients:[W,X,Y,Z]], ->
dishB.containsIngredient(ingredientCollection)
= 0,75Dish C = [Ingredients:[U,V,W]]; ->
dishC.containsIngredient(ingredientCollection)
= 0
Question
I want to return a Collection of all the dishes that contain the given ingredients orderd with the ones that have the highest percentage of common ingredients first. i was thinking of writing a Collection class of wich i add an extra param to the 'add' funct of the percentage. But this seems abit far fetched. Am i missing on something ?