2023-01-02 19:51:04 +01:00
|
|
|
package facade;
|
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
import java.util.Collection;
|
2023-01-02 19:51:04 +01:00
|
|
|
import domain.*;
|
|
|
|
import infrastructure.Persistenz;
|
|
|
|
|
|
|
|
public class FactorySystem {
|
2023-01-03 01:18:57 +01:00
|
|
|
private Factory factory;
|
|
|
|
|
|
|
|
private String factoryName;
|
|
|
|
|
|
|
|
public FactorySystem(String factoryName){
|
|
|
|
this.factoryName = factoryName;
|
|
|
|
if(Persistenz.existsSavedData(factoryName)){
|
|
|
|
try{
|
|
|
|
this.factory = (Factory) Persistenz.loadFactoryData(factoryName);
|
2023-01-06 22:55:33 +01:00
|
|
|
System.out.println("Loading of old factory successful");
|
2023-01-03 01:18:57 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("Loading of old factory not possible");
|
2023-01-06 22:55:33 +01:00
|
|
|
System.out.println(e.getMessage());
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.factory = new Factory();
|
|
|
|
}
|
2023-01-02 19:51:04 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
2023-01-02 19:51:04 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
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();
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|
2023-01-03 01:18:57 +01:00
|
|
|
return list;
|
|
|
|
}
|
2023-01-02 19:51:04 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
public boolean buildNewRobot(String name, int type){
|
|
|
|
boolean check = factory.buildNewRobot(name, type);
|
|
|
|
if(check) {
|
2023-01-06 22:55:33 +01:00
|
|
|
try {
|
|
|
|
Persistenz.saveFactoryData(factory, factoryName);
|
|
|
|
}catch(Exception e){
|
|
|
|
System.out.println(e.getCause());
|
|
|
|
}
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
|
|
|
return check;
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|
|
|
|
|
2023-01-06 22:55:33 +01:00
|
|
|
public Robot searchForRobot(int id){
|
|
|
|
return factory.getRobotOfList(id);
|
|
|
|
}
|
|
|
|
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|