
Hi Leute und zwar möchte ich diese verschachtelte Hashmap konfigurieren. Der Grund für die Hashmap ist der, dass der Schlüssel immer ein Produkttyp sein soll, der eine Arrayliste mit den geaddeten Zutaten aufruft. Ich habe die Klasse vorher mit einer Arrayliste geschrieben und bin folgender maßen voran gekommen:
Code:
package de.miguel.frozzenlist.frozzenbetaa;
import java.util.ArrayList;
import java.util.HashMap;
public class Tray {
private int trayID;
public HashMap<String,ArrayList<Product>>producttype= new HashMap<>();
//private ArrayList<Product> productList= new ArrayList<Product>();
public Tray(int trayID, int userID,HashMap<String,ArrayList<Product>>producttype) {
this.trayID = trayID;
this.producttype=producttype;
}
public void showTray() {
toStringForListInformation();
}
public void addProduct(ArrayList<Product>productList, Product product){
productList.add(product);
}
public void removeProduct(int input,ArrayList<Product>productlist) {
toStringForListInformation();
toStringQuestionWhichIndexRemove();
productlist.remove(input);
}
public int getTrayID() {
return trayID;
}
public void setTrayID(int trayID) {
this.trayID = trayID;
}
public ArrayList<Product> getProductList() {
return productList;
}
public void addProduct(String name,String typ,int productID) {
Product product =new Product();
product.setName(name);
product.setTyp(typ);
product.setProductID(productID);
productList.add(product);
}
public void removeProduct(int input) {
for(int i=0;i<productList.size();i++) {
while(input==i) {
productList.remove(i);
}toStringMessageOutOfBons();
}
}
public void changeProduct(int input,String name,String typ,int productID) {
for(int i=0;i<productList.size();i++) {
while(input==i) {
productList.get(i);
Product product =new Product();
product.setName(name);
product.setTyp(typ);
product.setProductID(productID);
productList.add(i, product);
}toStringMessageOutOfBons();
}
}
@Override
public String toString() {
return "Tray [trayID=" + trayID + ", productList=" + productList + "]";
}
@SuppressWarnings("unused")
public String toStringForListInformation() {
for(int i=0;i<productList.size();i++) {
return "Listung des Faches: "+trayID+"\n "+productList.get(i);
}
return "Keine Liste vorhanden";
}
public static String toStringQuestionWhichIndexRemove() {
return "Welchen Index wollen Sie löschen?";
}
public static String toStringMessageOutOfBons() {
return "Falsche Eingabe. Deine Eingabe ist außerhalb der Indexreichweite!\nVersuche es nochmal";
}
}
Meine Frage ist jetzt, wie ich das jetzt mit der Hashmap machen kann. Ich denke nicht das es wichtig ist, möchte es denoch erwähnen, dass dies eine Android App wird.