i would like to have in my class a nested hastable to set the amount of ingredients. Please consider the following scenario.
Scenario:
One recipe has several ingredients:
public class Ingredient {
private static int id;
String name;
public Ingredient(String name) {
this.name = name;
}
}
public class Recipe {
public static enum uom{
ml,gr, unit, teaspoon, tablespoon,cup,coffeespoon
};
public String name;
public Hashtable<Ingredient,Hashtable<uom,Integer>> ingredients;
public String description;
public Recipe(String name, String description, Hashtable<Ingredient,Hashtable<uom,Integer>> ingredients) {
this.name = name;
this.description = description;
this.ingredients = ingredients;
}
public static void main (String [] args) {
Ingredient lemon = new Ingredient("lemon");
Hashtable<Ingredient,Hashtable<Recipe.uom,Integer>> ingredient = null;
ingredient.put(new Ingredient("Lemon"),new Hashtable(uom.unit,1));
Recipe LemonPie = new Recipe("Lemon pie","blabla",ingredients);
}
}
Here in this scenario i want to include inside recipe the amount of each ingredients for that i believe hash table is the best approach. But how can i set a hashtable inside another (something like this):
{new Ingredient("Lemon") : {"unit":1}}
where unit is a enum of class Recipe.
Hashtable<Ingredient,Hashtable<Recipe.uom,Integer>> ingredient = null;
ingredient.put(new Ingredient("Lemon"),new Hashtable(uom.unit,1));
It says that Hashtable (int,float) in Hashtable cannot be applied to (Recipe.uom,int)
Question: Taking this scenarion in consideration. How can i set a hashtable inside another taking as key a enum?