Remove hardcoded warehouse metadata type
This commit is contained in:
parent
704b40ecc9
commit
be21c33755
|
@ -76,7 +76,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
|
|||
private BuildingMetadata parseBuildingMetadata(Element buildingElement) {
|
||||
String type = buildingElement.getAttribute(ATTRIBUTE_TYPE);
|
||||
|
||||
return type.equals("entrepot") ?
|
||||
return type.equals(BuildingMetadata.TYPE_WAREHOUSE) ?
|
||||
parseWarehouseMetadata(buildingElement, type) :
|
||||
parseFactoryMetadata(buildingElement, type);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
|
|||
int x = Integer.parseInt(buildingElement.getAttribute(ATTRIBUTE_X));
|
||||
int y = Integer.parseInt(buildingElement.getAttribute(ATTRIBUTE_Y));
|
||||
|
||||
return type.equals("entrepot") ?
|
||||
return type.equals(BuildingMetadata.TYPE_WAREHOUSE) ?
|
||||
new Warehouse(id, type, x, y) :
|
||||
new Factory(id, type, x, y);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
|
||||
public abstract class BuildingMetadata {
|
||||
public static final String TYPE_WAREHOUSE = "entrepot";
|
||||
|
||||
protected final String type;
|
||||
protected final Map<BuildingState, String> iconsPaths;
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package simulation;
|
||||
|
||||
import configuration.SimulationConfiguration;
|
||||
import configuration.SimulationConfigurationSingleton;
|
||||
import metadata.BuildingMetadata;
|
||||
import metadata.WarehouseMetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -9,9 +11,6 @@ import java.util.Collection;
|
|||
public class Warehouse extends Building implements WarehouseSubject {
|
||||
private final Collection<Component> planes = new ArrayList<>();
|
||||
private final Collection<WarehouseObserver> observers = new ArrayList<>();
|
||||
private final int capacity = ((WarehouseMetadata) SimulationConfigurationSingleton.getInstance()
|
||||
.getConfiguration().getMetadata().get(getType()))
|
||||
.getInput().getCapacity();
|
||||
|
||||
public Warehouse(int id, String type, int x, int y) {
|
||||
super(id, type, x, y);
|
||||
|
@ -29,12 +28,19 @@ public class Warehouse extends Building implements WarehouseSubject {
|
|||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void dettach(WarehouseObserver observer) {
|
||||
public void detach(WarehouseObserver observer) {
|
||||
observers.remove(observer);
|
||||
}
|
||||
|
||||
public void notifyObservers() {
|
||||
boolean isFull = planes.size() >= capacity;
|
||||
boolean isFull = planes.size() >= getCapacity();
|
||||
observers.forEach(o -> o.update(isFull));
|
||||
}
|
||||
|
||||
private static int getCapacity() {
|
||||
SimulationConfiguration configuration = SimulationConfigurationSingleton.getInstance().getConfiguration();
|
||||
WarehouseMetadata metadata = (WarehouseMetadata) configuration.getMetadata().get(BuildingMetadata.TYPE_WAREHOUSE);
|
||||
|
||||
return metadata.getInput().getCapacity();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ package simulation;
|
|||
|
||||
public interface WarehouseSubject {
|
||||
void attach(WarehouseObserver observer);
|
||||
void dettach(WarehouseObserver observer);
|
||||
void detach(WarehouseObserver observer);
|
||||
void notifyObservers();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue