Archived
0

use ModelFabric class for unwrap models

This commit is contained in:
iMoHax
2015-11-12 15:14:21 +03:00
parent 0f91d20037
commit 0d278864b3
15 changed files with 89 additions and 60 deletions

View File

@@ -115,7 +115,7 @@ public class EDCE {
return false;
}
SystemModel sModel = world.get(system.getName());
boolean found = sModel != ModelFabric.NONE_SYSTEM;
boolean found = !ModelFabric.isFake(sModel);
if (!found){
LOG.warn("Not found system {}", system.getName());
sModel = world.add(system.getName(), 0,0,0);
@@ -131,7 +131,7 @@ public class EDCE {
}
SystemModel sModel = profile.getSystem();
StationModel station = sModel.get(starport.getName());
boolean found = station != ModelFabric.NONE_STATION;
boolean found = !ModelFabric.isFake(station);
if (!found){
LOG.info("Not found station {}, adding", starport.getName());
updater.create(sModel);

View File

@@ -133,7 +133,7 @@ public class FilterController {
private void save() {
SystemModel s = center.getValue();
LOG.trace("Old filter", filter);
filter.setCenter(ModelFabric.isFake(s) ? null : market.getModeler().get(s));
filter.setCenter(ModelFabric.isFake(s) ? null : ModelFabric.get(s));
filter.setRadius(radius.getValue().doubleValue());
filter.setDistance(distance.getValue().doubleValue());
if (cbMarket.isSelected()) filter.add(SERVICE_TYPE.MARKET); else filter.remove(SERVICE_TYPE.MARKET);
@@ -146,7 +146,7 @@ public class FilterController {
if (cbMediumLandpad.isSelected()) filter.add(SERVICE_TYPE.MEDIUM_LANDPAD); else filter.remove(SERVICE_TYPE.MEDIUM_LANDPAD);
if (cbLargeLandpad.isSelected()) filter.add(SERVICE_TYPE.LARGE_LANDPAD); else filter.remove(SERVICE_TYPE.LARGE_LANDPAD);
filter.clearExcludes();
excludes.getItems().forEach(st -> filter.addExclude(market.getModeler().get(st)));
excludes.getItems().forEach(st -> filter.addExclude(ModelFabric.get(st)));
LOG.trace("New filter", filter);
}

View File

@@ -32,7 +32,7 @@ public class MainController {
private final static Logger LOG = LoggerFactory.getLogger(MainController.class);
private static MarketModel world = new MarketModel(World.getMarket());
private static ProfileModel profile = new ProfileModel(Main.SETTINGS.getProfile(), world);
private static ProfileModel profile = world.getModeler().get(Main.SETTINGS.getProfile());
private static MarketModel market = world;
@FXML

View File

@@ -147,7 +147,7 @@ public class OffersController {
cbShipyard.setSelected(false);
cbMediumLandpad.setSelected(false);
cbLargeLandpad.setSelected(false);
if (station != ModelFabric.NONE_STATION){
if (!ModelFabric.isFake(station)){
faction.setText(FactionStringConverter.toLocalizationString(station.getFaction()));
government.setText(GovernmentStringConverter.toLocalizationString(station.getGovernment()));
distance.setText(String.valueOf(station.getDistance()));

View File

@@ -124,7 +124,7 @@ public class SearchController {
if (cbMediumLandpad.isSelected()) filter.add(SERVICE_TYPE.MEDIUM_LANDPAD); else filter.remove(SERVICE_TYPE.MEDIUM_LANDPAD);
if (cbLargeLandpad.isSelected()) filter.add(SERVICE_TYPE.LARGE_LANDPAD); else filter.remove(SERVICE_TYPE.LARGE_LANDPAD);
ItemModel item = items.getValue();
if (item == null || item == ModelFabric.NONE_ITEM){
if (ModelFabric.isFake(item)){
Collection<StationModel> stations = market.getStations(filter);
fill(stations);
} else {

View File

@@ -111,7 +111,7 @@ public class ItemStatModel {
private void refreshProp(ObjectProperty<OfferModel> prop, Offer offer){
if (prop!=null ){
OfferModel model = prop.getValue();
if (model==null || !model.getOffer().equals(offer)){
if (model==null || !ModelFabric.get(model).equals(offer)){
prop.setValue(asModel(offer));
}
}

View File

@@ -113,12 +113,12 @@ public class MarketModel {
LOG.info("Remove system {} from market {}", system, this);
notificator.sendRemove(system);
stationNames.removeAll(system.getStationFullNames());
market.remove(system.getSystem());
market.remove(ModelFabric.get(system));
systemNames.remove(system.getName());
}
StationModel addStation(SystemModel system, String name) {
StationModel station = modeler.get(system.getSystem().addVendor(name));
StationModel station = modeler.get(ModelFabric.get(system).addVendor(name));
LOG.info("Add station {} to system {}", station, system);
stationNames.add(station.getFullName());
notificator.sendAdd(station);
@@ -129,7 +129,7 @@ public class MarketModel {
LOG.info("Remove station {} from system {}", station, station.getSystem());
notificator.sendRemove(station);
stationNames.remove(station.getFullName());
station.getSystem().getSystem().remove(station.getStation());
ModelFabric.get(station.getSystem()).remove(ModelFabric.get(station));
}
public ReadOnlyListProperty<GroupModel> getGroups(){
@@ -152,7 +152,7 @@ public class MarketModel {
}
public ItemModel add(String name, GroupModel group) {
ItemModel item = modeler.get(market.addItem(name, group.getGroup()));
ItemModel item = modeler.get(market.addItem(name, ModelFabric.get(group)));
LOG.info("Add item {} to market {}", item, this);
notificator.sendAdd(item);
items.add(item);
@@ -164,7 +164,7 @@ public class MarketModel {
}
public ObservableList<OfferModel> getOffers(OFFER_TYPE offerType, ItemModel item, MarketFilter filter){
return BindingsHelper.observableList(analyzer.getOffers(offerType, item.getItem(), filter), modeler::get);
return BindingsHelper.observableList(analyzer.getOffers(offerType, ModelFabric.get(item), filter), modeler::get);
}
public ObservableList<StationModel> getStations(MarketFilter filter){
@@ -185,13 +185,10 @@ 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 = MainController.getProfile().getProfile().copy();
Profile profile = ModelFabric.get(MainController.getProfile()).copy();
profile.setBalance(balance);
OrdersSearchTask task = new OrdersSearchTask(this,
from == null || from == ModelFabric.NONE_SYSTEM ? null : from.getSystem(),
stationFrom == null || stationFrom == ModelFabric.NONE_STATION ? null : stationFrom.getStation(),
to == null || to == ModelFabric.NONE_SYSTEM ? null : to.getSystem(),
stationTo == null || stationTo == ModelFabric.NONE_STATION ? null : stationTo.getStation(),
ModelFabric.get(from), ModelFabric.get(stationFrom), ModelFabric.get(to), ModelFabric.get(stationTo),
profile
);
@@ -211,15 +208,11 @@ public class MarketModel {
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 = MainController.getProfile().getProfile().copy();
Profile profile = ModelFabric.get(MainController.getProfile()).copy();
profile.setBalance(balance);
RoutesSearchTask task = new RoutesSearchTask(this,
from == null || from == ModelFabric.NONE_SYSTEM ? null : from.getSystem(),
stationFrom == null || stationFrom == ModelFabric.NONE_STATION ? null : stationFrom.getStation(),
to == null || to == ModelFabric.NONE_SYSTEM ? null : to.getSystem(),
stationTo == null || stationTo == ModelFabric.NONE_STATION ? null : stationTo.getStation(),
profile,
specificator
ModelFabric.get(from), ModelFabric.get(stationFrom), ModelFabric.get(to), ModelFabric.get(stationTo),
profile, specificator
);
progress.run(task, route -> {
@@ -237,13 +230,13 @@ public class MarketModel {
}
public RouteModel getRoute(RouteModel path) {
Route r = analyzer.getRoute(path.getRoute().getVendors());
Route r = analyzer.getRoute(ModelFabric.get(path).getVendors());
if (r == null) return null;
return modeler.get(r);
}
Route _getPath(OrderModel order) {
return analyzer.getPath(order.getOrder());
return analyzer.getPath(ModelFabric.get(order));
}
private RouteModel getPath(Vendor from, Vendor to) {
@@ -252,19 +245,19 @@ public class MarketModel {
}
public RouteModel getPath(StationModel from, StationModel to) {
return getPath(from.getStation(), to.getStation());
return getPath(ModelFabric.get(from), ModelFabric.get(to));
}
public RouteModel getPath(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo){
if (ModelFabric.isFake(stationFrom)){
return getPath(from.getSystem().asTransit(), ModelFabric.isFake(stationTo) ? to.getSystem().asTransit() : stationTo.getStation());
return getPath(ModelFabric.get(from).asTransit(), ModelFabric.isFake(stationTo) ? ModelFabric.get(to).asTransit() : ModelFabric.get(stationTo));
} else {
return getPath(stationFrom.getStation(), ModelFabric.isFake(stationTo) ? to.getSystem().asTransit() : stationTo.getStation());
return getPath(ModelFabric.get(stationFrom), ModelFabric.isFake(stationTo) ? ModelFabric.get(to).asTransit() : ModelFabric.get(stationTo));
}
}
public RouteModel getPath(OrderModel order) {
Route p = analyzer.getPath(order.getOrder());
Route p = analyzer.getPath(ModelFabric.get(order));
return modeler.get(p);
}

View File

@@ -32,7 +32,7 @@ public class MissionModel {
this.count = count;
this.profit = profit;
if (item != null) {
offer = SimpleOffer.fakeBuy(target.getStation(), item.getItem(), profit / count, count);
offer = SimpleOffer.fakeBuy(ModelFabric.get(target), ModelFabric.get(item), profit / count, count);
need = count;
} else {
need = 0;
@@ -92,7 +92,7 @@ public class MissionModel {
specificator.buy(offer);
} else
if (isCourier() || isDelivery()){
specificator.add(target.getStation(), true);
specificator.add(ModelFabric.get(target), true);
}
}
@@ -114,7 +114,7 @@ public class MissionModel {
for (OrderModel order : orders) {
if (item.equals(order.getOffer().getItem()) && target.equals(order.getBuyer())){
for (RouteReserve reserve : reserves) {
if (order.getOffer().getOffer().equals(reserve.getOrder().getSell())){
if (ModelFabric.get(order.getOffer()).equals(reserve.getOrder().getSell())){
need -= order.getCount();
}
}

View File

@@ -30,10 +30,18 @@ public class ModelFabric {
return new OrderModel(get(order.getSell()), get(order.getBuy()), order.getCount());
}
public static Order get(OrderModel order){
return order.getOrder();
}
public RouteModel get(Route route) {
return new RouteModel(route, market);
}
public static Route get(RouteModel route){
return route.getRoute();
}
public SystemModel get(Place system){
if (system == null) return NONE_SYSTEM;
SystemModel res=null;
@@ -48,7 +56,8 @@ public class ModelFabric {
return res;
}
public Place get(SystemModel model){
public static Place get(SystemModel model){
if (isFake(model)) return null;
return model.getSystem();
}
@@ -66,7 +75,8 @@ public class ModelFabric {
return res;
}
public Vendor get(StationModel model){
public static Vendor get(StationModel model){
if (isFake(model)) return null;
return model.getStation();
}
@@ -75,6 +85,10 @@ public class ModelFabric {
return new GroupModel(group);
}
public static Group get(GroupModel group){
return group.getGroup();
}
public ItemModel get(Item item){
if (item == null) return null;
ItemModel res=null;
@@ -89,6 +103,11 @@ public class ModelFabric {
return res;
}
public static Item get(ItemModel item){
if (isFake(item)) return null;
return item.getItem();
}
public OfferModel get(Offer offer){
if (offer == null) return null;
OfferModel res = null;
@@ -103,6 +122,10 @@ public class ModelFabric {
return res;
}
public static Offer get(OfferModel offer){
return offer.getOffer();
}
public OfferModel get(Offer offer, ItemModel item){
if (offer == null) return null;
//always create new offer model
@@ -111,6 +134,14 @@ public class ModelFabric {
return res;
}
public ProfileModel get(Profile profile){
return new ProfileModel(profile, market);
}
public static Profile get(ProfileModel profile){
return profile.getProfile();
}
public void clear(){
items.clear();
systems.clear();
@@ -130,6 +161,10 @@ public class ModelFabric {
return system == null || system instanceof FAKE_SYSTEM_MODEL;
}
public static boolean isFake(ItemModel item) {
return item == null || item instanceof FAKE_ITEM_MODEL;
}
private static class FAKE_SYSTEM_MODEL extends SystemModel {
FAKE_SYSTEM_MODEL() {
super();

View File

@@ -45,11 +45,11 @@ public class OrderModel {
public OrderModel(OfferModel offer, double balance, long limit) {
this(offer);
this.max.setValue(Order.getMaxCount(offer.getOffer(), balance, limit));
this.max.setValue(Order.getMaxCount(ModelFabric.get(offer), balance, limit));
}
Order getOrder(){
return new Order(getOffer().getOffer(), getBuyOffer().getOffer(), getCount());
return new Order(ModelFabric.get(getOffer()), ModelFabric.get(getBuyOffer()), getCount());
}
public OfferModel getOffer() {
@@ -127,7 +127,7 @@ public class OrderModel {
}
public ObservableValue<Number> getProfit(OfferModel buyer) {
return Bindings.createDoubleBinding(() -> offer.getPrice() * Order.getMaxCount(offer.getOffer(), buyer.getOffer(), max.get()),
return Bindings.createDoubleBinding(() -> offer.getPrice() * Order.getMaxCount(ModelFabric.get(offer), ModelFabric.get(buyer), max.get()),
buyer.priceProperty(), offer.priceProperty(), max, buyer.countProperty());
}

View File

@@ -118,7 +118,7 @@ public class ProfileModel {
}
public void setSystem(SystemModel system) {
profile.setSystem(ModelFabric.isFake(system) ? null : system.getSystem());
profile.setSystem(ModelFabric.get(system));
this.system.set(system);
}
@@ -131,7 +131,7 @@ public class ProfileModel {
}
public void setStation(StationModel station) {
profile.setStation(ModelFabric.isFake(station) ? null : station.getStation());
profile.setStation(ModelFabric.get(station));
this.station.set(station);
}

View File

@@ -59,6 +59,10 @@ public class RouteModel {
}
}
Route getRoute() {
return _route;
}
private RouteModel getCopy(){
RouteModel res = new RouteModel(_route, market);
res.setCurrentEntry(getCurrentEntry());
@@ -95,10 +99,6 @@ public class RouteModel {
return _route.getTime();
}
public Route getRoute() {
return _route;
}
public boolean isLoop(){
return _route.isLoop();
}
@@ -156,12 +156,12 @@ public class RouteModel {
}
public RouteModel add(RouteModel route){
_route.join(route.getRoute());
_route.join(ModelFabric.get(route));
return getCopy();
}
public RouteModel remove(OrderModel order) {
_route.dropTo(order.getStation().getStation());
_route.dropTo(ModelFabric.get(order.getStation()));
return getCopy();
}
@@ -183,7 +183,7 @@ public class RouteModel {
}
} else
if (mission.isDelivery()){
RouteReserve reserve = RouteFiller.getReserves(_route, offset, mission.getTarget().getStation(), mission.getCount());
RouteReserve reserve = RouteFiller.getReserves(_route, offset, ModelFabric.get(mission.getTarget()), mission.getCount());
if (reserve != null) {
_route.reserve(reserve);
mission.setReserves(Collections.singleton(reserve));
@@ -194,7 +194,7 @@ public class RouteModel {
}
} else
if (mission.isCourier()){
completeIndex = _route.find(mission.getTarget().getStation(), offset+1);
completeIndex = _route.find(ModelFabric.get(mission.getTarget()), offset+1);
}
if (completeIndex != -1){
entries.get(completeIndex).add(mission);
@@ -215,7 +215,7 @@ public class RouteModel {
}
} else
if (mission.isDelivery()){
RouteReserve reserve = RouteFiller.getReserves(_route, offset, mission.getTarget().getStation(), mission.getCount());
RouteReserve reserve = RouteFiller.getReserves(_route, offset, ModelFabric.get(mission.getTarget()), mission.getCount());
if (reserve != null) {
_route.reserve(reserve);
mission.setReserves(Collections.singleton(reserve));
@@ -223,7 +223,7 @@ public class RouteModel {
}
} else
if (mission.isCourier()){
completeIndex = _route.find(mission.getTarget().getStation(), offset+1);
completeIndex = _route.find(ModelFabric.get(mission.getTarget()), offset+1);
}
if (completeIndex != -1){
if (completeIndex == 0 && _route.isLoop()) completeIndex = _route.getJumps()-1;
@@ -240,7 +240,7 @@ public class RouteModel {
entries.subList(startIndex, entries.size()).stream()
.filter(e -> !e.isTransit())
.map(RouteEntryModel::getStation)
.filter(station -> station != ModelFabric.NONE_STATION)
.filter(station -> !ModelFabric.isFake(station))
.forEach(res::add);
return res;
}
@@ -380,12 +380,12 @@ public class RouteModel {
}
public static RouteModel asRoute(SystemModel system){
Route route = Route.singletone(system.getSystem().asTransit());
Route route = Route.singletone(ModelFabric.get(system).asTransit());
return new RouteModel(route, system.getMarket());
}
public static RouteModel asRoute(StationModel station){
Route route = Route.singletone(station.getStation());
Route route = Route.singletone(ModelFabric.get(station));
return new RouteModel(route, station.getMarket());
}

View File

@@ -112,7 +112,7 @@ public class StationModel {
}
public OfferModel add(OFFER_TYPE type, ItemModel item, double price, long count){
OfferModel offer = asModel(station.addOffer(type, item.getItem(), price, count), item);
OfferModel offer = asModel(station.addOffer(type, ModelFabric.get(item), price, count), item);
LOG.info("Add offer {} to station {}", offer, station);
offer.refresh();
market.getNotificator().sendAdd(offer);
@@ -121,17 +121,17 @@ public class StationModel {
public void remove(OfferModel offer) {
LOG.info("Remove offer {} from station {}", offer, station);
station.remove(offer.getOffer());
station.remove(ModelFabric.get(offer));
offer.refresh();
market.getNotificator().sendRemove(offer);
}
public boolean hasSell(ItemModel item) {
return station.hasSell(item.getItem());
return station.hasSell(ModelFabric.get(item));
}
public boolean hasBuy(ItemModel item) {
return station.hasBuy(item.getItem());
return station.hasBuy(ModelFabric.get(item));
}
public double getDistance(StationModel other){

View File

@@ -94,7 +94,7 @@ public class SystemModel {
}
public double getDistance(SystemModel other){
return system.getDistance(other.getSystem());
return system.getDistance(ModelFabric.get(other));
}
public double getDistance(double x, double y, double z){

View File

@@ -9,6 +9,7 @@ import org.controlsfx.glyphfont.Glyph;
import ru.trader.analysis.Route;
import ru.trader.analysis.RouteEntry;
import ru.trader.core.Vendor;
import ru.trader.model.ModelFabric;
import ru.trader.model.RouteModel;
public class RouteNode {
@@ -25,7 +26,7 @@ public class RouteNode {
private final HBox node = new HBox();
public RouteNode(RouteModel route) {
this.route = route.getRoute();
this.route = ModelFabric.get(route);
node.getStyleClass().add(CSS_PATH);
build();
}