52 lines
1.2 KiB
Java
52 lines
1.2 KiB
Java
package domain;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
|
|
public class Factory implements Serializable {
|
|
|
|
private HashMap<Integer, Robot> robots = new HashMap<>();
|
|
private int c3poID = 0;
|
|
private int r2d2ID = 10000;
|
|
|
|
public Factory(){
|
|
|
|
}
|
|
|
|
//Has to return Collection<Robot>
|
|
public Collection<Robot> robotListToCollection(){
|
|
return robots.values();
|
|
}
|
|
|
|
//return a String arr with robot attributes
|
|
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;
|
|
}
|
|
//creates a new robot
|
|
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;
|
|
}
|
|
//returns a specific robot via id
|
|
public Robot getRobotOfList(int id){
|
|
return robots.get(id);
|
|
}
|
|
}
|
|
|