commit 67de8513eaa38e6dedb52f4f3c403b3565ff6cc6 Author: FyloZ Date: Thu May 26 16:04:07 2022 -0400 Add model classes diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6065565 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..86df60a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/model/Building.java b/src/model/Building.java new file mode 100644 index 0000000..6cfd0c3 --- /dev/null +++ b/src/model/Building.java @@ -0,0 +1,42 @@ +package model; + +public abstract class Building { + private final int id; + private final String type; + private final int x; + private final int y; + private BuildingState state = BuildingState.EMPTY; + + protected Building(int id, String type, int x, int y) { + this.id = id; + this.type = type; + this.x = x; + this.y = y; + } + + public abstract void processInput(Component input); + + public int getId() { + return id; + } + + public String getType() { + return type; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public BuildingState getState() { + return state; + } + + public void setState(BuildingState state) { + this.state = state; + } +} diff --git a/src/model/BuildingState.java b/src/model/BuildingState.java new file mode 100644 index 0000000..8be4de4 --- /dev/null +++ b/src/model/BuildingState.java @@ -0,0 +1,8 @@ +package model; + +public enum BuildingState { + EMPTY, + ONE_THIRD, + TWO_THIRD, + FULL +} diff --git a/src/model/Component.java b/src/model/Component.java new file mode 100644 index 0000000..33d1571 --- /dev/null +++ b/src/model/Component.java @@ -0,0 +1,37 @@ +package model; + +import java.util.Objects; + +// TODO WN: Check if we can use records + +public class Component { + private final ComponentType type; + + public Component(ComponentType type) { + this.type = type; + } + + public ComponentType getType() { + return type; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Component component = (Component) o; + return type == component.type; + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public String toString() { + return "Component{" + + "type=" + type + + '}'; + } +} diff --git a/src/model/ComponentRoute.java b/src/model/ComponentRoute.java new file mode 100644 index 0000000..1dff189 --- /dev/null +++ b/src/model/ComponentRoute.java @@ -0,0 +1,16 @@ +package model; + +public class ComponentRoute { + private final Building outputBuilding; + + public ComponentRoute(Building outputBuilding) { + this.outputBuilding = outputBuilding; + } + + public void sendComponent(Component component) { + } + + private void outputComponent(Component component) { + outputBuilding.processInput(component); + } +} diff --git a/src/model/ComponentType.java b/src/model/ComponentType.java new file mode 100644 index 0000000..18f77e5 --- /dev/null +++ b/src/model/ComponentType.java @@ -0,0 +1,8 @@ +package model; + +public enum ComponentType { + METAL, + MOTOR, + PLANE, + WING +} diff --git a/src/model/Factory.java b/src/model/Factory.java new file mode 100644 index 0000000..ef38d61 --- /dev/null +++ b/src/model/Factory.java @@ -0,0 +1,14 @@ +package model; + +public class Factory extends Building { + public Factory(int id, String type, int x, int y) { + super(id, type, x, y); + } + + @Override + public void processInput(Component input) { + } + + private void buildComponent() { + } +} diff --git a/src/model/Route.java b/src/model/Route.java new file mode 100644 index 0000000..6e9bdfd --- /dev/null +++ b/src/model/Route.java @@ -0,0 +1,42 @@ +package model; + +import java.util.Objects; + +public class Route { + private final int from; + private final int to; + + public Route(int from, int to) { + this.from = from; + this.to = to; + } + + public int getFrom() { + return from; + } + + public int getTo() { + return to; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Route route = (Route) o; + return from == route.from && to == route.to; + } + + @Override + public int hashCode() { + return Objects.hash(from, to); + } + + @Override + public String toString() { + return "Route{" + + "from=" + from + + ", to=" + to + + '}'; + } +} diff --git a/src/model/Warehouse.java b/src/model/Warehouse.java new file mode 100644 index 0000000..be3ad39 --- /dev/null +++ b/src/model/Warehouse.java @@ -0,0 +1,14 @@ +package model; + +public class Warehouse extends Building { + protected Warehouse(int id, String type, int x, int y) { + super(id, type, x, y); + } + + @Override + public void processInput(Component input) { + } + + private void sellComponent() { + } +} diff --git a/src/model/metadata/BuildingMetadata.java b/src/model/metadata/BuildingMetadata.java new file mode 100644 index 0000000..417373a --- /dev/null +++ b/src/model/metadata/BuildingMetadata.java @@ -0,0 +1,44 @@ +package model.metadata; + +import model.BuildingState; + +import java.util.Map; +import java.util.Objects; + +public abstract class BuildingMetadata { + private final String type; + private final Map iconsPaths; + + public BuildingMetadata(String type, Map iconsPaths) { + this.type = type; + this.iconsPaths = iconsPaths; + } + + public String getType() { + return type; + } + + public Map getIconsPaths() { + return iconsPaths; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BuildingMetadata that = (BuildingMetadata) o; + return type.equals(that.type); + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public String toString() { + return "BuildingMetadata{" + + "type='" + type + '\'' + + '}'; + } +} diff --git a/src/model/metadata/FactoryInput.java b/src/model/metadata/FactoryInput.java new file mode 100644 index 0000000..3a25cdd --- /dev/null +++ b/src/model/metadata/FactoryInput.java @@ -0,0 +1,44 @@ +package model.metadata; + +import model.ComponentType; + +import java.util.Objects; + +public class FactoryInput { + private final ComponentType type; + private final int quantity; + + public FactoryInput(ComponentType type, int quantity) { + this.type = type; + this.quantity = quantity; + } + + public ComponentType getType() { + return type; + } + + public int getQuantity() { + return quantity; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FactoryInput that = (FactoryInput) o; + return quantity == that.quantity && type == that.type; + } + + @Override + public int hashCode() { + return Objects.hash(type, quantity); + } + + @Override + public String toString() { + return "FactoryInput{" + + "type=" + type + + ", quantity=" + quantity + + '}'; + } +} diff --git a/src/model/metadata/FactoryMetadata.java b/src/model/metadata/FactoryMetadata.java new file mode 100644 index 0000000..ac121bb --- /dev/null +++ b/src/model/metadata/FactoryMetadata.java @@ -0,0 +1,55 @@ +package model.metadata; + +import model.BuildingState; + +import java.util.Collection; +import java.util.Map; +import java.util.Objects; + +public class FactoryMetadata extends BuildingMetadata { + private final int productionInterval; + private final Collection inputs; + private final FactoryOutput output; + + public FactoryMetadata(String type, Map iconsPaths, int productionInterval, Collection inputs, FactoryOutput output) { + super(type, iconsPaths); + this.productionInterval = productionInterval; + this.inputs = inputs; + this.output = output; + } + + public int getProductionInterval() { + return productionInterval; + } + + public Collection getInputs() { + return inputs; + } + + public FactoryOutput getOutput() { + return output; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + FactoryMetadata that = (FactoryMetadata) o; + return productionInterval == that.productionInterval && inputs.equals(that.inputs) && output.equals(that.output); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), productionInterval, inputs, output); + } + + @Override + public String toString() { + return "FactoryMetadata{" + + "productionInterval=" + productionInterval + + ", inputs=" + inputs + + ", output=" + output + + "} " + super.toString(); + } +} diff --git a/src/model/metadata/FactoryOutput.java b/src/model/metadata/FactoryOutput.java new file mode 100644 index 0000000..e5f6cbc --- /dev/null +++ b/src/model/metadata/FactoryOutput.java @@ -0,0 +1,37 @@ +package model.metadata; + +import model.ComponentType; + +import java.util.Objects; + +public class FactoryOutput { + private final ComponentType type; + + public FactoryOutput(ComponentType type) { + this.type = type; + } + + public ComponentType getType() { + return type; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FactoryOutput that = (FactoryOutput) o; + return type == that.type; + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public String toString() { + return "FactoryOutput{" + + "type=" + type + + '}'; + } +} diff --git a/src/model/metadata/WarehouseInput.java b/src/model/metadata/WarehouseInput.java new file mode 100644 index 0000000..e6a4b73 --- /dev/null +++ b/src/model/metadata/WarehouseInput.java @@ -0,0 +1,44 @@ +package model.metadata; + +import model.ComponentType; + +import java.util.Objects; + +public class WarehouseInput { + private final ComponentType type; + private final int capacity; + + public WarehouseInput(ComponentType type, int capacity) { + this.type = type; + this.capacity = capacity; + } + + public ComponentType getType() { + return type; + } + + public int getCapacity() { + return capacity; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + WarehouseInput that = (WarehouseInput) o; + return capacity == that.capacity && type == that.type; + } + + @Override + public int hashCode() { + return Objects.hash(type, capacity); + } + + @Override + public String toString() { + return "WarehouseInput{" + + "type=" + type + + ", capacity=" + capacity + + '}'; + } +} diff --git a/src/model/metadata/WarehouseMetadata.java b/src/model/metadata/WarehouseMetadata.java new file mode 100644 index 0000000..fbd803d --- /dev/null +++ b/src/model/metadata/WarehouseMetadata.java @@ -0,0 +1,36 @@ +package model.metadata; + +import model.BuildingState; + +import java.util.Map; +import java.util.Objects; + +public class WarehouseMetadata extends BuildingMetadata { + private final WarehouseInput input; + + public WarehouseMetadata(String type, Map iconsPaths, WarehouseInput input) { + super(type, iconsPaths); + this.input = input; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + WarehouseMetadata that = (WarehouseMetadata) o; + return input.equals(that.input); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), input); + } + + @Override + public String toString() { + return "WarehouseMetadata{" + + "input=" + input + + "} " + super.toString(); + } +} diff --git a/tp01.iml b/tp01.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/tp01.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file