refactoring clone/copy methods
This commit is contained in:
@@ -185,7 +185,7 @@ public class MarketModel {
|
||||
|
||||
public void getOrders(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance, Consumer<ObservableList<OrderModel>> result) {
|
||||
ProgressController progress = new ProgressController(Screeners.getMainScreen(), Localization.getString("analyzer.orders.title"));
|
||||
Profile profile = ModelFabric.get(MainController.getProfile()).copy();
|
||||
Profile profile = Profile.clone(ModelFabric.get(MainController.getProfile()));
|
||||
profile.setBalance(balance);
|
||||
OrdersSearchTask task = new OrdersSearchTask(this,
|
||||
ModelFabric.get(from), ModelFabric.get(stationFrom), ModelFabric.get(to), ModelFabric.get(stationTo),
|
||||
@@ -206,9 +206,13 @@ public class MarketModel {
|
||||
getOrders(ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
|
||||
}
|
||||
|
||||
public void getRoutes(StationModel stationFrom, StationModel stationTo, double balance, CrawlerSpecificator specificator, Consumer<ObservableList<RouteModel>> result) {
|
||||
getRoutes(stationFrom.getSystem(), stationFrom, stationTo.getSystem(), stationTo, balance, specificator, result);
|
||||
}
|
||||
|
||||
public void getRoutes(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance, CrawlerSpecificator specificator, Consumer<ObservableList<RouteModel>> result) {
|
||||
ProgressController progress = new ProgressController(Screeners.getMainScreen(), Localization.getString("analyzer.routes.title"));
|
||||
Profile profile = ModelFabric.get(MainController.getProfile()).copy();
|
||||
Profile profile = Profile.clone(ModelFabric.get(MainController.getProfile()));
|
||||
profile.setBalance(balance);
|
||||
RoutesSearchTask task = new RoutesSearchTask(this,
|
||||
ModelFabric.get(from), ModelFabric.get(stationFrom), ModelFabric.get(to), ModelFabric.get(stationTo),
|
||||
|
||||
@@ -40,6 +40,16 @@ public class MissionModel {
|
||||
}
|
||||
}
|
||||
|
||||
protected MissionModel(MissionModel mission, boolean includeReserves){
|
||||
this.target = mission.target;
|
||||
this.item = mission.item;
|
||||
this.count = mission.count;
|
||||
this.profit = mission.profit;
|
||||
this.offer = mission.offer;
|
||||
this.need = mission.need;
|
||||
this.reserves = includeReserves ? mission.reserves : null;
|
||||
}
|
||||
|
||||
public StationModel getTarget() {
|
||||
return target;
|
||||
}
|
||||
@@ -89,7 +99,11 @@ public class MissionModel {
|
||||
|
||||
public void toSpecification(CrawlerSpecificator specificator){
|
||||
if (isSupply()){
|
||||
specificator.buy(offer);
|
||||
if (isCompleted()){
|
||||
specificator.add(ModelFabric.get(target), true);
|
||||
} else {
|
||||
specificator.buy(offer);
|
||||
}
|
||||
} else
|
||||
if (isCourier() || isDelivery()){
|
||||
specificator.add(ModelFabric.get(target), true);
|
||||
@@ -143,9 +157,11 @@ public class MissionModel {
|
||||
return Objects.hash(target, item, count);
|
||||
}
|
||||
|
||||
public static MissionModel copy(MissionModel mission){
|
||||
return new MissionModel(mission, false);
|
||||
}
|
||||
|
||||
|
||||
public MissionModel getCopy(){
|
||||
return new MissionModel(target, item, count, profit);
|
||||
public static MissionModel clone(MissionModel mission){
|
||||
return mission != null ? new MissionModel(mission, true) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,4 +134,17 @@ public class RouteEntryModel {
|
||||
orders.clear();
|
||||
orders.addAll(BindingsHelper.observableList(entry.getOrders(), market.getModeler()::get));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof RouteEntryModel)) return false;
|
||||
RouteEntryModel that = (RouteEntryModel) o;
|
||||
return entry.equals(that.entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return entry.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,20 @@ public class Route implements Comparable<Route> {
|
||||
updateStats();
|
||||
}
|
||||
|
||||
protected Route(Route route) {
|
||||
this.profit = route.profit;
|
||||
this.balance = route.balance;
|
||||
this.distance = route.distance;
|
||||
this.fuel = route.fuel;
|
||||
this.time = route.time;
|
||||
this.lands = route.lands;
|
||||
this.refills = route.refills;
|
||||
this.cargo = route.cargo;
|
||||
this.entries = new ArrayList<>(route.entries.size());
|
||||
route.entries.forEach(e -> this.entries.add(RouteEntry.clone(e)));
|
||||
}
|
||||
|
||||
|
||||
public List<RouteEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
@@ -195,6 +209,18 @@ public class Route implements Comparable<Route> {
|
||||
}
|
||||
iterator.remove();
|
||||
}
|
||||
updateStats();
|
||||
}
|
||||
|
||||
public void dropTo(int index){
|
||||
for (ListIterator<RouteEntry> iterator = entries.listIterator(entries.size()); iterator.hasPrevious(); ) {
|
||||
if (iterator.previousIndex() == index){
|
||||
break;
|
||||
}
|
||||
iterator.previous();
|
||||
iterator.remove();
|
||||
}
|
||||
updateStats();
|
||||
}
|
||||
|
||||
void updateStats(){
|
||||
@@ -295,5 +321,8 @@ public class Route implements Comparable<Route> {
|
||||
return new Route(entry);
|
||||
}
|
||||
|
||||
public static Route clone(Route route){
|
||||
return route != null ? new Route(route) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,19 @@ public class RouteEntry {
|
||||
reserved = 0;
|
||||
}
|
||||
|
||||
protected RouteEntry(RouteEntry entry){
|
||||
this.vendor = entry.vendor;
|
||||
this.fuel = entry.fuel;
|
||||
this.land = entry.land;
|
||||
this.refill = entry.refill;
|
||||
this.profit = entry.profit;
|
||||
this.time = entry.time;
|
||||
this.fulltime = entry.fulltime;
|
||||
this.reserved = entry.reserved;
|
||||
this.orders = new ArrayList<>(entry.orders.size());
|
||||
entry.orders.forEach(o -> this.orders.add(new OrderWrapper(o)));
|
||||
}
|
||||
|
||||
public Vendor getVendor() {
|
||||
return vendor;
|
||||
}
|
||||
@@ -224,8 +237,18 @@ public class RouteEntry {
|
||||
this.max = order.getCount();
|
||||
}
|
||||
|
||||
private OrderWrapper(OrderWrapper orderWrapper){
|
||||
super(orderWrapper);
|
||||
this.fixed = orderWrapper.fixed;
|
||||
this.max = orderWrapper.max;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
setCount(max);
|
||||
}
|
||||
}
|
||||
|
||||
public static RouteEntry clone(RouteEntry entry){
|
||||
return entry != null ? new RouteEntry(entry) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Order implements Comparable<Order> {
|
||||
private Offer sell;
|
||||
private Offer buy;
|
||||
private final Offer sell;
|
||||
private final Offer buy;
|
||||
private double profit;
|
||||
private long count;
|
||||
|
||||
@@ -27,6 +27,12 @@ public class Order implements Comparable<Order> {
|
||||
this.profit = (buy.getPrice() - sell.getPrice()) * count;
|
||||
}
|
||||
|
||||
protected Order(Order order){
|
||||
this(order.sell, order.buy);
|
||||
this.profit = order.profit;
|
||||
this.count = order.count;
|
||||
}
|
||||
|
||||
public Offer getSell() {
|
||||
return sell;
|
||||
}
|
||||
@@ -143,4 +149,8 @@ public class Order implements Comparable<Order> {
|
||||
if (Double.isInfinite(balance)) return Math.min(limit, Math.min(supply, demand));
|
||||
return (long) Math.min(limit, Math.min(Math.min(supply, demand), Math.floor(balance/sell.getPrice())));
|
||||
}
|
||||
|
||||
public static Order clone(Order order){
|
||||
return order != null ? new Order(order) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,26 @@ public class Profile {
|
||||
pathPriority = PATH_PRIORITY.FAST;
|
||||
}
|
||||
|
||||
protected Profile(Profile profile){
|
||||
this.name = profile.name;
|
||||
this.balance = profile.balance;
|
||||
this.docked = profile.docked;
|
||||
this.jumps = profile.jumps;
|
||||
this.lands = profile.lands;
|
||||
this.refill = profile.refill;
|
||||
this.routesCount = profile.routesCount;
|
||||
this.distanceTime = profile.distanceTime;
|
||||
this.jumpTime = profile.jumpTime;
|
||||
this.landingTime = profile.landingTime;
|
||||
this.takeoffTime = profile.takeoffTime;
|
||||
this.rechargeTime = profile.rechargeTime;
|
||||
this.fuelPrice = profile.fuelPrice;
|
||||
this.pathPriority = profile.pathPriority;
|
||||
this.system = profile.system;
|
||||
this.station = profile.station;
|
||||
this.ship = Ship.clone(profile.ship);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -226,25 +246,8 @@ public class Profile {
|
||||
values.setProperty("profile.search.times.recharge", String.valueOf(rechargeTime));
|
||||
ship.writeTo(values);
|
||||
}
|
||||
|
||||
public Profile copy(){
|
||||
Profile res = new Profile(ship);
|
||||
res.name = this.name;
|
||||
res.balance = this.balance;
|
||||
res.system = this.system;
|
||||
res.station = this.station;
|
||||
res.docked = this.docked;
|
||||
res.jumps = this.jumps;
|
||||
res.lands = this.lands;
|
||||
res.refill = this.refill;
|
||||
res.routesCount = this.routesCount;
|
||||
res.distanceTime = this.distanceTime;
|
||||
res.jumpTime = this.jumpTime;
|
||||
res.landingTime = this.landingTime;
|
||||
res.takeoffTime = this.takeoffTime;
|
||||
res.rechargeTime = this.rechargeTime;
|
||||
res.fuelPrice = this.fuelPrice;
|
||||
res.pathPriority = this.pathPriority;
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Profile clone(Profile profile){
|
||||
return profile != null ? new Profile(profile) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,16 @@ public class Ship {
|
||||
this.engine = new Engine(2, 'E');
|
||||
}
|
||||
|
||||
public static Ship copyOf(Ship other){
|
||||
Ship copy = new Ship();
|
||||
copy.mass = other.mass;
|
||||
copy.cargo = other.cargo;
|
||||
copy.tank = other.tank;
|
||||
copy.engine = other.getEngine();
|
||||
return copy;
|
||||
protected Ship(Ship ship){
|
||||
this.mass = ship.mass;
|
||||
this.cargo = ship.cargo;
|
||||
this.tank = ship.tank;
|
||||
this.engine = ship.getEngine();
|
||||
|
||||
}
|
||||
|
||||
public static Ship clone(Ship ship){
|
||||
return ship != null ? new Ship(ship) : ship;
|
||||
}
|
||||
|
||||
public int getCargo() {
|
||||
|
||||
Reference in New Issue
Block a user