package domain; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; public class Factory implements Serializable { private HashMap robots = new HashMap<>(); private int c3poID = 0; private int r2d2ID = 10000; public Factory(){ } //Has to return Collection public Collection robotListToCollection(){ return robots.values(); } public String[] getRobotList() { Collection collect = robotListToCollection(); String[] list = new String[collect.size()]; int i = 0; for(Robot r: collect){ list[i++] = r.toString(); } return list; } public boolean buildNewRobot(String name, int type){ Robot r ; if(type == 0){ r = new R2D2(r2d2ID++, name); }else if(type == 1){ r = new C3PO(c3poID++, name); }else{ return false; } robots.put(r.getId(), r); return true; } public Robot getRobotOfList(int id){ return robots.get(id); } }