Add model classes

This commit is contained in:
FyloZ 2022-05-26 16:04:07 -04:00
commit 67de8513ea
Signed by: william
GPG Key ID: 835378AE9AF4AE97
20 changed files with 509 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -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

8
.idea/.gitignore vendored Normal file
View File

@ -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

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/tp01.iml" filepath="$PROJECT_DIR$/tp01.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

42
src/model/Building.java Normal file
View File

@ -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;
}
}

View File

@ -0,0 +1,8 @@
package model;
public enum BuildingState {
EMPTY,
ONE_THIRD,
TWO_THIRD,
FULL
}

37
src/model/Component.java Normal file
View File

@ -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 +
'}';
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,8 @@
package model;
public enum ComponentType {
METAL,
MOTOR,
PLANE,
WING
}

14
src/model/Factory.java Normal file
View File

@ -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() {
}
}

42
src/model/Route.java Normal file
View File

@ -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 +
'}';
}
}

14
src/model/Warehouse.java Normal file
View File

@ -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() {
}
}

View File

@ -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<BuildingState, String> iconsPaths;
public BuildingMetadata(String type, Map<BuildingState, String> iconsPaths) {
this.type = type;
this.iconsPaths = iconsPaths;
}
public String getType() {
return type;
}
public Map<BuildingState, String> 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 + '\'' +
'}';
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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<FactoryInput> inputs;
private final FactoryOutput output;
public FactoryMetadata(String type, Map<BuildingState, String> iconsPaths, int productionInterval, Collection<FactoryInput> inputs, FactoryOutput output) {
super(type, iconsPaths);
this.productionInterval = productionInterval;
this.inputs = inputs;
this.output = output;
}
public int getProductionInterval() {
return productionInterval;
}
public Collection<FactoryInput> 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();
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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<BuildingState, String> 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();
}
}

11
tp01.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>