Pr_robot_factory/facade/FactorySystem.java

57 lines
1.5 KiB
Java

package facade;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.HashMap;
import domain.*;
import infrastructure.Persistenz;
public class FactorySystem {
private Factory factory;
private String factoryName;
public FactorySystem(String factoryName){
this.factoryName = factoryName;
if(Persistenz.existsSavedData(factoryName)){
try{
this.factory = (Factory) Persistenz.loadFactoryData(factoryName);
System.out.println("Loading of old factory successful");
} catch (Exception e) {
System.out.println("Loading of old factory not possible");
System.out.println(e.getMessage());
}
}else{
this.factory = new Factory();
}
}
public String[] getAllRobots(){
Collection<Robot> robots = factory.getRobotList();
String[] list = new String[robots.size()];
int i = 0;
for(Robot r: robots){
list[i++] = r.toString();
}
return list;
}
public boolean buildNewRobot(String name, int type){
boolean check = factory.buildNewRobot(name, type);
if(check) {
try {
Persistenz.saveFactoryData(factory, factoryName);
}catch(Exception e){
System.out.println(e.getCause());
}
}
return check;
}
public Robot searchForRobot(int id){
return factory.getRobotOfList(id);
}
}