implement clear, export, import market
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package ru.trader;
|
package ru.trader;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import ru.trader.core.Market;
|
import ru.trader.core.Market;
|
||||||
import ru.trader.core.MarketAnalyzer;
|
import ru.trader.core.MarketAnalyzer;
|
||||||
@@ -17,6 +19,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
public class World {
|
public class World {
|
||||||
private static Market world;
|
private static Market world;
|
||||||
private static final String STORE_FILE="world.xml";
|
private static final String STORE_FILE="world.xml";
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(World.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@@ -33,11 +36,24 @@ public class World {
|
|||||||
world.commit();
|
world.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void saveTo(File file) throws FileNotFoundException, UnsupportedEncodingException, XMLStreamException {
|
||||||
|
Store.saveToFile(world, file);
|
||||||
|
world.commit();
|
||||||
|
}
|
||||||
|
|
||||||
public static void imp(File file) throws IOException, SAXException {
|
public static void imp(File file) throws IOException, SAXException {
|
||||||
|
LOG.info("Import from {}", file.getName());
|
||||||
XSSFImporter xssfImporter = new XSSFImporter(file);
|
XSSFImporter xssfImporter = new XSSFImporter(file);
|
||||||
world = xssfImporter.doImport();
|
world = xssfImporter.doImport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void impXml(File file) throws ParserConfigurationException, SAXException, IOException {
|
||||||
|
LOG.info("Import from {}", file.getName());
|
||||||
|
Market market = Store.loadFromFile(file);
|
||||||
|
world.add(market);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Market getMarket() {
|
public static Market getMarket() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import ru.trader.World;
|
|||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -111,19 +112,83 @@ public class MainController {
|
|||||||
public void importWorld(ActionEvent actionEvent) {
|
public void importWorld(ActionEvent actionEvent) {
|
||||||
try {
|
try {
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Excel files (*.xlsx)", "*.xlsx");
|
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML bd files (*.xml)", "*.xml");
|
||||||
fileChooser.getExtensionFilters().add(extFilter);
|
fileChooser.getExtensionFilters().add(extFilter);
|
||||||
fileChooser.setInitialDirectory(new File("."));
|
fileChooser.setInitialDirectory(new File("."));
|
||||||
File file = fileChooser.showOpenDialog(null);
|
File file = fileChooser.showOpenDialog(null);
|
||||||
if (file !=null) {
|
if (file !=null) {
|
||||||
World.imp(file);
|
World.impXml(file);
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
} catch (SAXException | IOException e) {
|
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||||
LOG.error("Error on import file", e);
|
LOG.error("Error on import file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void exportWorld(ActionEvent actionEvent) {
|
||||||
|
try {
|
||||||
|
FileChooser fileChooser = new FileChooser();
|
||||||
|
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML bd files (*.xml)", "*.xml");
|
||||||
|
fileChooser.getExtensionFilters().add(extFilter);
|
||||||
|
fileChooser.setInitialDirectory(new File("."));
|
||||||
|
File file = fileChooser.showSaveDialog(null);
|
||||||
|
if (file !=null) {
|
||||||
|
World.saveTo(file);
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException | UnsupportedEncodingException | XMLStreamException e) {
|
||||||
|
LOG.error("Error on save as file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(ActionEvent actionEvent){
|
||||||
|
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.all")));
|
||||||
|
if (res == Dialog.ACTION_YES) {
|
||||||
|
market.clear();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearOffers(ActionEvent actionEvent){
|
||||||
|
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.offers")));
|
||||||
|
if (res == Dialog.ACTION_YES) {
|
||||||
|
market.clearOffers();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearStations(ActionEvent actionEvent){
|
||||||
|
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.stations")));
|
||||||
|
if (res == Dialog.ACTION_YES) {
|
||||||
|
market.clearStations();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearSystems(ActionEvent actionEvent){
|
||||||
|
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.systems")));
|
||||||
|
if (res == Dialog.ACTION_YES) {
|
||||||
|
market.clearSystems();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearItems(ActionEvent actionEvent){
|
||||||
|
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.items")));
|
||||||
|
if (res == Dialog.ACTION_YES) {
|
||||||
|
market.clearItems();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearGroups(ActionEvent actionEvent){
|
||||||
|
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.groups")));
|
||||||
|
if (res == Dialog.ACTION_YES) {
|
||||||
|
market.clearGroups();
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<GroupModel> addGroup(){
|
public Optional<GroupModel> addGroup(){
|
||||||
GroupModel group = Screeners.showAddGroup(market);
|
GroupModel group = Screeners.showAddGroup(market);
|
||||||
return Optional.ofNullable(group);
|
return Optional.ofNullable(group);
|
||||||
@@ -189,6 +254,7 @@ public class MainController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reload(){
|
private void reload(){
|
||||||
|
if (world != null) world.getModeler().clear();
|
||||||
world = new MarketModel(World.getMarket());
|
world = new MarketModel(World.getMarket());
|
||||||
market = world;
|
market = world;
|
||||||
Screeners.reinitAll();
|
Screeners.reinitAll();
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ public class OffersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init(){
|
void init(){
|
||||||
|
station = null;
|
||||||
|
system = null;
|
||||||
MarketModel market = MainController.getMarket();
|
MarketModel market = MainController.getMarket();
|
||||||
market.getNotificator().add(new OffersChangeListener());
|
market.getNotificator().add(new OffersChangeListener());
|
||||||
systems.setItems(market.systemsProperty());
|
systems.setItems(market.systemsProperty());
|
||||||
|
|||||||
@@ -248,6 +248,8 @@ public class Screeners {
|
|||||||
|
|
||||||
public static void reinitAll() {
|
public static void reinitAll() {
|
||||||
mainController.init();
|
mainController.init();
|
||||||
|
systemsEditorController.init();
|
||||||
|
vEditorController.init();
|
||||||
filterController.init();
|
filterController.init();
|
||||||
EMDNUpdater.setMarket(MainController.getMarket());
|
EMDNUpdater.setMarket(MainController.getMarket());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class StationEditorController {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(){
|
void init(){
|
||||||
if (updater != null){
|
if (updater != null){
|
||||||
name.textProperty().unbindBidirectional(updater.nameProperty());
|
name.textProperty().unbindBidirectional(updater.nameProperty());
|
||||||
distance.numberProperty().unbindBidirectional(updater.distanceProperty());
|
distance.numberProperty().unbindBidirectional(updater.distanceProperty());
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public class SystemsEditorController {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(){
|
void init(){
|
||||||
market = MainController.getMarket();
|
market = MainController.getMarket();
|
||||||
system1.setItems(market.systemsProperty());
|
system1.setItems(market.systemsProperty());
|
||||||
system2.setItems(market.systemsProperty());
|
system2.setItems(market.systemsProperty());
|
||||||
|
|||||||
@@ -203,4 +203,33 @@ public class MarketModel {
|
|||||||
return modeler.get(p);
|
return modeler.get(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear(){
|
||||||
|
LOG.info("Clear market");
|
||||||
|
market.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearOffers(){
|
||||||
|
LOG.info("Clear offers");
|
||||||
|
market.clearOffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearStations(){
|
||||||
|
LOG.info("Clear stations");
|
||||||
|
market.clearVendors();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearSystems(){
|
||||||
|
LOG.info("Clear systems");
|
||||||
|
market.clearPlaces();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearItems(){
|
||||||
|
LOG.info("Clear items");
|
||||||
|
market.clearItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearGroups(){
|
||||||
|
LOG.info("Clear groups");
|
||||||
|
market.clearGroups();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Market
|
# Market
|
||||||
|
market.all=All
|
||||||
market.systems=Systems
|
market.systems=Systems
|
||||||
market.stations=Stations
|
market.stations=Stations
|
||||||
|
market.groups=Commodities groups
|
||||||
market.items=Commods
|
market.items=Commods
|
||||||
market.offers=Offers
|
market.offers=Offers
|
||||||
market.item.name=Commodity
|
market.item.name=Commodity
|
||||||
@@ -46,6 +48,7 @@ main.title=Trader
|
|||||||
main.menu.file=File
|
main.menu.file=File
|
||||||
main.menu.file.save=Save
|
main.menu.file.save=Save
|
||||||
main.menu.file.import=Import...
|
main.menu.file.import=Import...
|
||||||
|
main.menu.file.export=Export...
|
||||||
main.menu.edit=Edit
|
main.menu.edit=Edit
|
||||||
main.menu.edit.addSystem=Add System
|
main.menu.edit.addSystem=Add System
|
||||||
main.menu.edit.editSystem=Edit System
|
main.menu.edit.editSystem=Edit System
|
||||||
@@ -54,6 +57,7 @@ main.menu.edit.addStation=Add Station
|
|||||||
main.menu.edit.editStation=Edit Station
|
main.menu.edit.editStation=Edit Station
|
||||||
main.menu.edit.removeStation=Delete Station
|
main.menu.edit.removeStation=Delete Station
|
||||||
main.menu.edit.addItem=Add Commodity
|
main.menu.edit.addItem=Add Commodity
|
||||||
|
main.menu.edit.clear=Clear
|
||||||
main.menu.settings=Settings
|
main.menu.settings=Settings
|
||||||
main.menu.settings.language=Language
|
main.menu.settings.language=Language
|
||||||
main.menu.settings.language.item=English
|
main.menu.settings.language.item=English
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Market
|
# Market
|
||||||
|
market.all=\u0412\u0441\u0435
|
||||||
market.systems=\u0421\u0438\u0441\u0442\u0435\u043C\u044B
|
market.systems=\u0421\u0438\u0441\u0442\u0435\u043C\u044B
|
||||||
market.stations=\u0421\u0442\u0430\u043D\u0446\u0438\u0438
|
market.stations=\u0421\u0442\u0430\u043D\u0446\u0438\u0438
|
||||||
|
market.groups=\u0413\u0440\u0443\u043F\u043F\u044B \u0442\u043E\u0432\u0430\u0440\u043E\u0432
|
||||||
market.items=\u0422\u043E\u0432\u0430\u0440\u044B
|
market.items=\u0422\u043E\u0432\u0430\u0440\u044B
|
||||||
market.offers=\u0417\u0430\u043A\u0430\u0437\u044B
|
market.offers=\u0417\u0430\u043A\u0430\u0437\u044B
|
||||||
market.item.name=\u0422\u043E\u0432\u0430\u0440
|
market.item.name=\u0422\u043E\u0432\u0430\u0440
|
||||||
@@ -47,6 +49,7 @@ main.title=\u0422\u043E\u0440\u0433\u043E\u0439\u0434
|
|||||||
main.menu.file=\u0424\u0430\u0439\u043B
|
main.menu.file=\u0424\u0430\u0439\u043B
|
||||||
main.menu.file.save=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C
|
main.menu.file.save=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C
|
||||||
main.menu.file.import=\u0418\u043C\u043F\u043E\u0440\u0442...
|
main.menu.file.import=\u0418\u043C\u043F\u043E\u0440\u0442...
|
||||||
|
main.menu.file.export=\u042D\u043A\u0441\u043F\u043E\u0440\u0442...
|
||||||
main.menu.edit=\u041F\u0440\u0430\u0432\u043A\u0430
|
main.menu.edit=\u041F\u0440\u0430\u0432\u043A\u0430
|
||||||
main.menu.edit.addSystem=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0438\u0441\u0442\u0435\u043C\u0443
|
main.menu.edit.addSystem=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0441\u0438\u0441\u0442\u0435\u043C\u0443
|
||||||
main.menu.edit.editSystem=\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0441\u0438\u0441\u0442\u0435\u043C\u0443
|
main.menu.edit.editSystem=\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0441\u0438\u0441\u0442\u0435\u043C\u0443
|
||||||
@@ -55,6 +58,7 @@ main.menu.edit.addStation=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u044
|
|||||||
main.menu.edit.editStation=\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0441\u0442\u0430\u043D\u0446\u0438\u044E
|
main.menu.edit.editStation=\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0441\u0442\u0430\u043D\u0446\u0438\u044E
|
||||||
main.menu.edit.removeStation=\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0430\u043D\u0446\u0438\u044E
|
main.menu.edit.removeStation=\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u0442\u0430\u043D\u0446\u0438\u044E
|
||||||
main.menu.edit.addItem=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0442\u043E\u0432\u0430\u0440
|
main.menu.edit.addItem=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0442\u043E\u0432\u0430\u0440
|
||||||
|
main.menu.edit.clear=\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C
|
||||||
main.menu.settings=\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438
|
main.menu.settings=\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438
|
||||||
main.menu.settings.language=\u042F\u0437\u044B\u043A
|
main.menu.settings.language=\u042F\u0437\u044B\u043A
|
||||||
main.menu.settings.language.item=\u0420\u0443\u0441\u0441\u043A\u0438\u0439
|
main.menu.settings.language.item=\u0420\u0443\u0441\u0441\u043A\u0438\u0439
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<Menu text="%main.menu.file">
|
<Menu text="%main.menu.file">
|
||||||
<MenuItem text="%main.menu.file.save" onAction="#save"/>
|
<MenuItem text="%main.menu.file.save" onAction="#save"/>
|
||||||
<MenuItem text="%main.menu.file.import" onAction="#importWorld"/>
|
<MenuItem text="%main.menu.file.import" onAction="#importWorld"/>
|
||||||
|
<MenuItem text="%main.menu.file.export" onAction="#exportWorld"/>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu text="%main.menu.edit">
|
<Menu text="%main.menu.edit">
|
||||||
<MenuItem text="%main.menu.edit.addSystem" onAction="#addSystem"/>
|
<MenuItem text="%main.menu.edit.addSystem" onAction="#addSystem"/>
|
||||||
@@ -20,6 +21,14 @@
|
|||||||
<MenuItem text="%main.menu.edit.addStation" onAction="#addStation"/>
|
<MenuItem text="%main.menu.edit.addStation" onAction="#addStation"/>
|
||||||
<MenuItem text="%main.menu.edit.editStation" onAction="#editStation"/>
|
<MenuItem text="%main.menu.edit.editStation" onAction="#editStation"/>
|
||||||
<MenuItem text="%main.menu.edit.removeStation" onAction="#removeStation"/>
|
<MenuItem text="%main.menu.edit.removeStation" onAction="#removeStation"/>
|
||||||
|
<Menu text="%main.menu.edit.clear">
|
||||||
|
<MenuItem text="%market.offers" onAction="#clearOffers"/>
|
||||||
|
<MenuItem text="%market.stations" onAction="#clearStations"/>
|
||||||
|
<MenuItem text="%market.systems" onAction="#clearSystems"/>
|
||||||
|
<MenuItem text="%market.items" onAction="#clearItems"/>
|
||||||
|
<MenuItem text="%market.groups" onAction="#clearGroups"/>
|
||||||
|
<MenuItem text="%market.all" onAction="#clear"/>
|
||||||
|
</Menu>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu text="%main.menu.settings">
|
<Menu text="%main.menu.settings">
|
||||||
<MenuItem text="%main.menu.settings.filter" onAction="#editFilter"/>
|
<MenuItem text="%main.menu.settings.filter" onAction="#editFilter"/>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package ru.trader.core;
|
package ru.trader.core;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface Market {
|
public interface Market {
|
||||||
@@ -51,4 +53,98 @@ public interface Market {
|
|||||||
default Collection<Offer> getBuy(Item item){
|
default Collection<Offer> getBuy(Item item){
|
||||||
return getStatBuy(item).getOffers();
|
return getStatBuy(item).getOffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void add(Market market){
|
||||||
|
// add groups
|
||||||
|
Collection<Group> groups = market.getGroups();
|
||||||
|
HashMap<Group, Group> mapGroups = new HashMap<>(groups.size(), 0.9f);
|
||||||
|
for (Group group : groups) {
|
||||||
|
Group nGroup = this.addGroup(group.getName(), group.getType());
|
||||||
|
mapGroups.put(group, nGroup);
|
||||||
|
}
|
||||||
|
// add items
|
||||||
|
Collection<Item> items = market.getItems();
|
||||||
|
HashMap<Item, Item> mapItems = new HashMap<>(items.size(), 0.9f);
|
||||||
|
for (Item item : items) {
|
||||||
|
Item nItem = this.addItem(item.getName(), mapGroups.get(item.getGroup()));
|
||||||
|
mapItems.put(item, nItem);
|
||||||
|
}
|
||||||
|
mapGroups.clear();
|
||||||
|
// add places and vendors
|
||||||
|
for (Place place : market.get()) {
|
||||||
|
Place nPlace = this.addPlace(place.getName(), place.getX(), place.getY(), place.getZ());
|
||||||
|
for (Vendor vendor : place.get()) {
|
||||||
|
Vendor nVendor = nPlace.addVendor(vendor.getName());
|
||||||
|
nVendor.setDistance(vendor.getDistance());
|
||||||
|
// add services
|
||||||
|
for (SERVICE_TYPE service : vendor.getServices()) {
|
||||||
|
nVendor.add(service);
|
||||||
|
}
|
||||||
|
// add offers
|
||||||
|
for (Offer offer : vendor.getAllBuyOffers()) {
|
||||||
|
nVendor.addOffer(offer.getType(), mapItems.get(offer.getItem()), offer.getPrice(), offer.getCount());
|
||||||
|
}
|
||||||
|
for (Offer offer : vendor.getAllSellOffers()) {
|
||||||
|
nVendor.addOffer(offer.getType(), mapItems.get(offer.getItem()), offer.getPrice(), offer.getCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clear(){
|
||||||
|
clear(true, true, true, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clearGroups(){
|
||||||
|
clear(true, false, false, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clearItems(){
|
||||||
|
clear(true, false, false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clearPlaces(){
|
||||||
|
clear(false, false, true, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clearVendors(){
|
||||||
|
clear(false, true, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clearOffers(){
|
||||||
|
clear(true, false, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
default void clear(boolean offers, boolean vendors, boolean places, boolean items, boolean groups){
|
||||||
|
if (places){
|
||||||
|
Collection<Place> p = new ArrayList<>(get());
|
||||||
|
for (Place place : p) {
|
||||||
|
remove(place);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (vendors || offers){
|
||||||
|
for (Place place : get()) {
|
||||||
|
if (vendors) {
|
||||||
|
place.clear();
|
||||||
|
} else {
|
||||||
|
place.clearOffers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (items){
|
||||||
|
Collection<Item> i = new ArrayList<>(getItems());
|
||||||
|
for (Item item : i) {
|
||||||
|
remove(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (groups){
|
||||||
|
Collection<Group> g = new ArrayList<>(getGroups());
|
||||||
|
for (Group group : g) {
|
||||||
|
remove(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ru.trader.core;
|
|||||||
|
|
||||||
import ru.trader.graph.Connectable;
|
import ru.trader.graph.Connectable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -46,4 +47,16 @@ public interface Place extends Connectable<Place> {
|
|||||||
return Math.sqrt(Math.pow(x - getX(), 2) + Math.pow(y - getY(), 2) + Math.pow(z - getZ(), 2));
|
return Math.sqrt(Math.pow(x - getX(), 2) + Math.pow(y - getY(), 2) + Math.pow(z - getZ(), 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void clear(){
|
||||||
|
Collection<Vendor> vendors = new ArrayList<>(get());
|
||||||
|
for (Vendor vendor : vendors) {
|
||||||
|
remove(vendor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default void clearOffers(){
|
||||||
|
for (Vendor vendor : get()) {
|
||||||
|
vendor.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package ru.trader.core;
|
package ru.trader.core;
|
||||||
|
|
||||||
import ru.trader.graph.Connectable;
|
import ru.trader.graph.Connectable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface Vendor extends Connectable<Vendor> {
|
public interface Vendor extends Connectable<Vendor> {
|
||||||
@@ -65,4 +67,12 @@ public interface Vendor extends Connectable<Vendor> {
|
|||||||
default boolean canRefill(){
|
default boolean canRefill(){
|
||||||
return getPlace().canRefill();
|
return getPlace().canRefill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void clear(){
|
||||||
|
Collection<Offer> offers = new ArrayList<>(getAllSellOffers());
|
||||||
|
offers.addAll(getAllBuyOffers());
|
||||||
|
for (Offer offer : offers) {
|
||||||
|
remove(offer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user