2023-01-02 19:51:04 +01:00
|
|
|
package domain;
|
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.Collection;
|
2023-01-02 19:51:04 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
public class Factory implements Serializable {
|
2023-01-07 16:34:36 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
private HashMap<Integer, Robot> robots = new HashMap<>();
|
2023-01-02 19:51:04 +01:00
|
|
|
private int c3poID = 0;
|
2023-01-06 22:55:33 +01:00
|
|
|
private int r2d2ID = 10000;
|
2023-01-03 01:18:57 +01:00
|
|
|
|
|
|
|
public Factory(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Has to return Collection<Robot>
|
2023-01-07 16:34:36 +01:00
|
|
|
public Collection<Robot> robotListToCollection(){
|
2023-01-03 01:18:57 +01:00
|
|
|
return robots.values();
|
|
|
|
}
|
|
|
|
|
2023-01-07 16:34:36 +01:00
|
|
|
public String[] getRobotList() {
|
|
|
|
Collection<Robot> collect = robotListToCollection();
|
|
|
|
String[] list = new String[collect.size()];
|
|
|
|
int i = 0;
|
|
|
|
for(Robot r: collect){
|
|
|
|
list[i++] = r.toString();
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2023-01-03 01:18:57 +01:00
|
|
|
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;
|
|
|
|
}
|
2023-01-06 22:55:33 +01:00
|
|
|
|
|
|
|
public Robot getRobotOfList(int id){
|
|
|
|
return robots.get(id);
|
|
|
|
}
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
|
|
|
|