Archived
0

implement editing orders of track

This commit is contained in:
iMoHax
2015-12-03 14:29:46 +03:00
parent 064549b268
commit eb6acf5b56
8 changed files with 195 additions and 52 deletions

View File

@@ -3,6 +3,7 @@ package ru.trader.analysis;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.core.Order;
import ru.trader.core.TransitVendor;
import ru.trader.core.Vendor;
@@ -115,6 +116,27 @@ public class Route implements Comparable<Route> {
updateStats();
}
public void add(int index, Order order){
LOG.trace("Add order {} to route {}, index = {}", order, this, index);
RouteEntry entry = entries.get(index);
entry.add(order);
updateStats();
}
public void remove(int index, Order order){
LOG.trace("Remove order {} from route {}, index = {}", order, this, index);
RouteEntry entry = entries.get(index);
entry.remove(order);
updateStats();
}
public void removeAllOrders(int index){
LOG.trace("Remove all orders from route {}, index = {}", this, index);
RouteEntry entry = entries.get(index);
entry.clear();
updateStats();
}
public void addAll(Collection<RouteEntry> entries){
LOG.trace("Add {} entries {} to route {}", entries, this);
this.entries.addAll(entries);
@@ -313,12 +335,15 @@ public class Route implements Comparable<Route> {
};
}
public static Route singletone(Vendor root){
public static Route singletone(Vendor root, double balance, long cargo){
RouteEntry entry = new RouteEntry(root, 0,0,0);
if (!(root instanceof TransitVendor)){
entry.setLand(true);
}
return new Route(entry);
Route route = new Route(entry);
route.setBalance(balance);
route.setCargo(cargo);
return route;
}
public static Route clone(Route route){

View File

@@ -94,6 +94,14 @@ public class RouteEntry {
orders.add(fixedWrap(order));
}
void remove(Order order){
orders.removeIf(o -> o.fixed && o.equals(order));
}
void clear(){
orders.removeIf(o -> o.fixed);
}
void addAll(Collection<Order> orders){
orders.forEach(this::add);
}

View File

@@ -139,7 +139,7 @@ public class MarketAnalyzer {
return res;
}
private Collection<Order> getOrders(Collection<Vendor> sellers, Collection<Vendor> buyers, double lowProfit) {
public Collection<Order> getOrders(Collection<Vendor> sellers, Collection<Vendor> buyers, double lowProfit) {
List<Order> res = new ArrayList<>();
callback.start(sellers.size());
for (Vendor seller : sellers) {