Commit ba46bb65 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Парсер и toString() для нового формата.

parent cace9b38
......@@ -4,12 +4,13 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
*/
public class LoadingEquipment extends MovingObject{
public LoadingEquipment() {
super();
......@@ -21,11 +22,19 @@ public class LoadingEquipment extends MovingObject{
@Override
public String toString() {
return getId() + ";" + getName();
String res = getId() + ";" + getName();
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
}
public LoadingEquipment(String s) {
super(s);
super(s);
String[] tokens = s.split(";");
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
}
}
......@@ -6,6 +6,7 @@ package inport;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
/**
*
......@@ -14,12 +15,21 @@ import java.util.List;
public class LoadingTemplate extends OperationTemplate {
private TransportShip loader;
private OptionalInt loaderType = OptionalInt.empty();
private Storage storage;
private List<LoadingEquipment> resources;
private List<Integer> resourcesTypes;
private double intensity;
private boolean withMooring;
private Cargo cargo;
public OptionalInt getLoaderType() {
return loaderType;
}
public void setLoaderType(OptionalInt loaderType) {
this.loaderType = loaderType;
}
/**
* Get the value of resources
*
......@@ -37,7 +47,14 @@ public class LoadingTemplate extends OperationTemplate {
public void setResources(List<LoadingEquipment> resources) {
this.resources = resources;
}
public List<Integer> getResourcesTypes() {
return resourcesTypes;
}
public void setResourcesTypes(List<Integer> resourcesTypes) {
this.resourcesTypes = resourcesTypes;
}
public TransportShip getLoader() {
return loader;
}
......@@ -83,32 +100,47 @@ public class LoadingTemplate extends OperationTemplate {
this.loader = loader;
this.storage = storage;
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
this.intensity = intensity;
}
public LoadingTemplate() {
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
}
@Override
public String toString() {
String res = "";
boolean first = true;
for(LoadingEquipment eq : resources)
{
for(LoadingEquipment eq : resources) {
if (!first)
res += "," + eq.getId();
else
res += eq.getId();
first = false;
}
int source = loader.getId();
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
int startId;
if (loaderType.isPresent()) {
startId = loaderType.getAsInt();
} else {
startId = loader.getId();
}
int source = startId;
if (intensity>0)
source = storage.getId();
int target = loader.getId();
int target = startId;
if (intensity<=0)
target = storage.getId();
return getId() + ";" + "loa;" + twtoString() + ";" + source + ";" + cargo.getId() + ";" + target + ";"
+ getStartLocation().getId() + ";[" + res +"];" + Math.abs(intensity) + ";" + (withMooring ? "M" : "U");
return getId() + "; " + "loa; " + twtoString() + "; " + source + "; " + cargo.getId() + "; " + target + "; "
+ getStartLocation().getId() + "; [" + res +"]; " + Math.abs(intensity) + "; " + (withMooring ? "M" : "U");
}
}
......@@ -118,6 +118,19 @@ public class Main {
}
break;
}
case "debug" : {
String fileName = args[1];
String output = args[2];
TaskCase task = new TaskCase();
try {
task.deserialize(fileName);
task.serialize(output);
} catch (IOException e) {
System.out.println(e.getMessage());
}
break;
}
default:
System.out.println("Unknown type \"" + type + "\"");
}
......
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -11,8 +13,16 @@ package inport;
public class MooringTemplate extends TowUsingTemplate {
private TransportShip moorer;
private OptionalInt moorerType = OptionalInt.empty();
private boolean direct;
public OptionalInt getMoorerType() {
return moorerType;
}
public void setMoorerType(OptionalInt moorerType) {
this.moorerType = moorerType;
}
/**
* Get the value of direction
*
......@@ -63,18 +73,31 @@ public class MooringTemplate extends TowUsingTemplate {
public String toString() {
String res = "";
boolean first = true;
for(Tow eq : getResources())
{
for(Tow eq : getResources()) {
if (!first)
res += "," + eq.getId();
else
res += eq.getId();
first = false;
}
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
String code = "mrn";
if (!direct)
code = "unm";
return getId() + ";" + code + ";" + twtoString() + ";" + moorer.getId() + ";" + getStartLocation().getId() + ";[" + res +"];"+getDuration();
String result = getId() + "; " + code + "; " + twtoString() + "; ";
if (moorerType.isPresent()) {
result += moorerType.getAsInt();
} else {
result += moorer.getId();
}
return result + "; " + getStartLocation().getId() + "; [" + res +"]; "+getDuration();
}
}
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -12,6 +14,7 @@ public class MovingObject {
private int id;
private String name;
private OptionalInt type;
/**
* Get the value of name
......@@ -49,18 +52,34 @@ public class MovingObject {
this.id = id;
}
public OptionalInt getType() {
return type;
}
public void setType(OptionalInt type) {
this.type = type;
}
public MovingObject(int id, String name) {
this.id = id;
this.name = name;
this.type = OptionalInt.empty();
}
public MovingObject(int id, String name, int typeId) {
this.id = id;
this.name = name;
this.type = OptionalInt.of(typeId);
}
public MovingObject() {
type = OptionalInt.empty();
}
public MovingObject(String s) {
String[] tokens = s.split(";");
id = Integer.parseInt(tokens[0].trim());
name = tokens[1].trim();
name = tokens[1].trim();
type = OptionalInt.empty();
}
}
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -11,6 +13,7 @@ package inport;
public class MovingTemplate extends TowUsingTemplate {
private MovingObject mover;
private OptionalInt moverType;
private Berth destination;
......@@ -50,6 +53,13 @@ public class MovingTemplate extends TowUsingTemplate {
this.mover = mover;
}
public OptionalInt getMoverType() {
return moverType;
}
public void setMoverType(OptionalInt moverType) {
this.moverType = moverType;
}
public MovingTemplate(MovingObject mover, Berth source, Berth destination, double duration, int id) {
super(duration, id, source);
this.mover = mover;
......@@ -64,15 +74,28 @@ public class MovingTemplate extends TowUsingTemplate {
public String toString() {
String res = "";
boolean first = true;
for(Tow eq : getResources())
{
for(Tow eq : getResources()) {
if (!first)
res += "," + eq.getId();
else
res += eq.getId();
first = false;
}
return getId() + ";" + "mov;" + twtoString() + ";" + mover.getId() + ";" + getStartLocation().getId() + ";" + destination.getId() + ";[" + res +"];"+getDuration();
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
String result = getId() + "; " + "mov; " + twtoString() + "; ";
if (getMoverType().isPresent()) {
result += getMoverType().getAsInt();
} else {
result += mover.getId();
}
return result + "; " + getStartLocation().getId() + "; " + destination.getId() + "; [" + res +"]; "+getDuration();
}
......
This diff is collapsed.
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -19,12 +21,18 @@ public class Tow extends MovingObject {
@Override
public String toString() {
return getId() + ";" + getName() + ";1000000";
String res = getId() + ";" + getName() + ";1000000";
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
}
public Tow(String s) {
super(s);
String[] tokens = s.split(";");
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
}
}
......@@ -12,11 +12,10 @@ import java.util.List;
* @author topazh_ag
*/
public abstract class TowUsingTemplate extends OperationTemplate {
private List<Tow> resources;
private List<Integer> resourcesTypes;
private double duration;
/**
* Get the value of resources
......@@ -36,6 +35,13 @@ public abstract class TowUsingTemplate extends OperationTemplate {
this.resources = resources;
}
public List<Integer> getResourcesTypes() {
return resourcesTypes;
}
public void setResourcesTypes(List<Integer> resourcesTypes) {
this.resourcesTypes = resourcesTypes;
}
/**
* Get the value of duration
*
......@@ -59,11 +65,13 @@ public abstract class TowUsingTemplate extends OperationTemplate {
public TowUsingTemplate(double duration, int id, Berth startLocation) {
super(id, startLocation);
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
this.duration = duration;
}
public TowUsingTemplate() {
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
}
@Override
......@@ -80,6 +88,4 @@ public abstract class TowUsingTemplate extends OperationTemplate {
}
return getId() + ";" + "tut" + ";" + ";[" + res +"];"+duration;
}
}
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -30,13 +32,20 @@ public class TransportShip extends MovingObject {
@Override
public String toString() {
return getId() + ";" + getName() + ";" + cargoMax;
String res = getId() + ";" + getName() + ";" + cargoMax;
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
}
public TransportShip(String s) {
super(s);
String[] tokens = s.split(";");
cargoMax = Double.parseDouble(tokens[2].trim());
cargoMax = Double.parseDouble(tokens[2].trim());
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment