ArrayList<Ret> lis = /*...*/;
// ...
class Lis {
long id;
String name, cat;
long station_id;
short com_id;
int buy_price, supply, sell_price, demand;
long updated;
@Override
public String toString() {
return "Lis{" + "id=" + id + ", name=" + name + ", cat=" + cat + ", station_id=" + station_id + ", com_id="
+ com_id + ", buy_price=" + buy_price + ", supply=" + supply + ", sell_price=" + sell_price
+ ", demand=" + demand + ", updated=" + Main.getHours(updated) + "h}";
}
}
class Ret {
Lis[] lises;
boolean isPlanetary = false;
int profit1 = 0;
float profit2 = 0;
int maxDis1 = 0;
int minDisToSol = Integer.MAX_VALUE;
public Ret(Lis[] l, Data data) {
this.lises = l;
for (int i = 0; i < lises.length - 1; i += 2) {
Sta sa1 = data.stations.get(l[i + 0].station_id);
Sta sa2 = data.stations.get(l[i + 1].station_id);
Sys sy1 = data.systems.get(sa1.system_id);
Sys sy2 = data.systems.get(sa2.system_id);
if (sa1.isPlanetary || sa2.isPlanetary)
isPlanetary = true;
profit1 += l[i + 1].sell_price - l[i + 0].buy_price;
if (maxDis1 < data.getDis(sy1, sy2))
maxDis1 = (int) data.getDis(sy1, sy2);
if (minDisToSol > data.getDisToSol(sy1))
minDisToSol = (int) data.getDisToSol(sy1);
if (minDisToSol > data.getDisToSol(sy2))
minDisToSol = (int) data.getDisToSol(sy2);
}
profit2 = profit1 / (lises.length / 2);
}
public String getString(boolean noPlanets, boolean hideDetails, int maxDis, Data data) {
if (noPlanets && isPlanetary)
return "";
if (maxDis < maxDis1)
return "";
StringJoiner j = new StringJoiner("\n");
for (int i = 0; i < lises.length - 1; i += 2) {
Lis[] l = lises;
Sta sa1 = data.stations.get(l[i + 0].station_id);
Sta sa2 = data.stations.get(l[i + 1].station_id);
Sys sy1 = data.systems.get(sa1.system_id);
Sys sy2 = data.systems.get(sa2.system_id);
if (!hideDetails) {
j.add(sy1.toString());
j.add(sa1.toString());
j.add(l[i + 0].toString());
j.add(sy2.toString());
j.add(sa2.toString());
j.add(l[i + 1].toString());
}
j.add(sy1.name + "/" + sa1.name + "/" + l[i + 0].name + "/" + l[i + 0].buy_price + " -> " + sy2.name + "/"
+ sa2.name + "/" + l[i + 1].name + "/" + l[i + 1].buy_price + " ("
+ (l[i + 1].sell_price - l[i + 0].buy_price) + ")");
}
j.add("Pro1: " + profit1 + " - Pro2: " + profit2 + " - maxDis1: " + maxDis1 + " - minDisToSol: "
+ minDisToSol + " - planets: " + isPlanetary);
return j.toString();
}
}
Wie kann ich lis
/Ret
am einfachsten persistentieren? Leider hab ich mir da vorher keine Gedanken zu gemacht… Wünschenswerte wäre ein SQLite-File.