Archived
0

implement export/import to properties

This commit is contained in:
iMoHax
2015-07-16 15:41:16 +03:00
parent 8807357d62
commit e6ebd09167
2 changed files with 54 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
package ru.trader.core; package ru.trader.core;
import java.util.Properties;
public class Profile { public class Profile {
public static enum PATH_PRIORITY {FAST, ECO} public static enum PATH_PRIORITY {FAST, ECO}
@@ -10,7 +12,6 @@ public class Profile {
private boolean refill; private boolean refill;
private int routesCount; private int routesCount;
//Scorer multipliers //Scorer multipliers
private int scoreOrdersCount;
private double distanceMult; private double distanceMult;
private double jumpMult; private double jumpMult;
private double landMult; private double landMult;
@@ -23,7 +24,6 @@ public class Profile {
jumps = 6; jumps = 6;
lands = 4; lands = 4;
routesCount = 30; routesCount = 30;
scoreOrdersCount = 5;
distanceMult = 0.8; distanceMult = 0.8;
landMult = 0.95; landMult = 0.95;
fuelPrice = 100; fuelPrice = 100;
@@ -79,14 +79,6 @@ public class Profile {
this.routesCount = routesCount; this.routesCount = routesCount;
} }
public int getScoreOrdersCount() {
return scoreOrdersCount;
}
public void setScoreOrdersCount(int scoreOrdersCount) {
this.scoreOrdersCount = scoreOrdersCount;
}
public double getDistanceMult() { public double getDistanceMult() {
return distanceMult; return distanceMult;
} }
@@ -126,4 +118,33 @@ public class Profile {
public void setPathPriority(PATH_PRIORITY pathPriority) { public void setPathPriority(PATH_PRIORITY pathPriority) {
this.pathPriority = pathPriority; this.pathPriority = pathPriority;
} }
public static Profile readFrom(Properties values){
Ship ship = Ship.readFrom(values);
Profile profile = new Profile(ship);
profile.setBalance(Double.valueOf(values.getProperty("profile.balance","1000")));
profile.setJumps(Integer.valueOf(values.getProperty("profile.jumps", "6")));
profile.setLands(Integer.valueOf(values.getProperty("profile.lands","4")));
profile.setPathPriority(PATH_PRIORITY.valueOf(values.getProperty("profile.search.priority","FAST")));
profile.setRoutesCount(Integer.valueOf(values.getProperty("profile.search.routes","100")));
profile.setFuelPrice(Double.valueOf(values.getProperty("profile.search.fuel.price","100")));
profile.setDistanceMult(Double.valueOf(values.getProperty("profile.search.mult.distance","0.8")));
profile.setLandMult(Double.valueOf(values.getProperty("profile.search.mult.land","0.95")));
profile.setJumpMult(Double.valueOf(values.getProperty("profile.search.mult.jump","0.5")));
return profile;
}
public void writeTo(Properties values){
values.setProperty("profile.balance", String.valueOf(balance));
values.setProperty("profile.jumps", String.valueOf(jumps));
values.setProperty("profile.lands", String.valueOf(lands));
values.setProperty("profile.search.priority", String.valueOf(pathPriority));
values.setProperty("profile.search.routes", String.valueOf(routesCount));
values.setProperty("profile.search.fuel.price", String.valueOf(fuelPrice));
values.setProperty("profile.search.mult.distance", String.valueOf(distanceMult));
values.setProperty("profile.search.mult.land", String.valueOf(landMult));
values.setProperty("profile.search.mult.jump", String.valueOf(jumpMult));
ship.writeTo(values);
}
} }

View File

@@ -1,5 +1,9 @@
package ru.trader.core; package ru.trader.core;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ship { public class Ship {
private final static int REFILL_FUEL_STEP = 10; private final static int REFILL_FUEL_STEP = 10;
@@ -281,5 +285,24 @@ public class Ship {
} }
} }
private final static Pattern ENGINE_REGEXP = Pattern.compile("(\\d)(\\w)");
public static Ship readFrom(Properties values){
Ship ship = new Ship();
ship.setMass(Double.valueOf(values.getProperty("ship.mass", "44.9")));
ship.setCargo(Integer.valueOf(values.getProperty("ship.cargo","4")));
ship.setTank(Double.valueOf(values.getProperty("ship.tank", "2")));
String e = values.getProperty("ship.engine","2E");
Matcher matcher = ENGINE_REGEXP.matcher(e);
if (matcher.find()){
ship.setEngine(Integer.valueOf(matcher.group(1)), matcher.group(2).charAt(0));
}
return ship;
}
public void writeTo(Properties values){
values.setProperty("ship.mass", String.valueOf(mass));
values.setProperty("ship.cargo", String.valueOf(cargo));
values.setProperty("ship.tank", String.valueOf(tank));
values.setProperty("ship.engine", String.valueOf(engine.getClazz()) + engine.getRating());
}
} }