Archived
0

refactoring clone/copy methods

This commit is contained in:
iMoHax
2015-11-19 15:36:58 +03:00
parent a9e80ec693
commit 5d7ffaca6a
8 changed files with 137 additions and 36 deletions

View File

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

View File

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

View File

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