optimise memory using
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package ru.trader.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface Market {
|
||||
|
||||
@@ -28,12 +26,18 @@ public interface Market {
|
||||
}
|
||||
|
||||
Collection<Place> get();
|
||||
default Collection<String> getPlaceNames(){
|
||||
return get() .stream().map(Place::getName).collect(Collectors.toList());
|
||||
}
|
||||
default Collection<Vendor> getVendors(){
|
||||
return getVendors(false);
|
||||
}
|
||||
default Collection<Vendor> getVendors(boolean includeTransit){
|
||||
return new PlacesWrapper(get(), includeTransit);
|
||||
}
|
||||
default Collection<String> getVendorNames(){
|
||||
return getVendors() .stream().map(Vendor::getFullName).collect(Collectors.toList());
|
||||
}
|
||||
Collection<Group> getGroups();
|
||||
Collection<Item> getItems();
|
||||
ItemStat getStat(OFFER_TYPE type, Item item);
|
||||
|
||||
@@ -5,6 +5,7 @@ import ru.trader.analysis.graph.Connectable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface Place extends Connectable<Place> {
|
||||
|
||||
@@ -33,6 +34,9 @@ public interface Place extends Connectable<Place> {
|
||||
return get();
|
||||
}
|
||||
}
|
||||
default Collection<String> getVendorNames(){
|
||||
return get().stream().map(Vendor::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
default Vendor get(String name){
|
||||
Optional<Vendor> vendor = get().stream().filter(p -> name.equalsIgnoreCase(p.getName())).findFirst();
|
||||
|
||||
@@ -10,6 +10,10 @@ public interface Vendor extends Connectable<Vendor> {
|
||||
String getName();
|
||||
void setName(String name);
|
||||
|
||||
default String getFullName(){
|
||||
return getPlace().getName()+": "+getName();
|
||||
}
|
||||
|
||||
Place getPlace();
|
||||
|
||||
double getDistance();
|
||||
|
||||
@@ -6,6 +6,7 @@ import ru.trader.core.*;
|
||||
import ru.trader.store.berkeley.entities.BDBGroup;
|
||||
import ru.trader.store.berkeley.entities.BDBItem;
|
||||
import ru.trader.store.berkeley.entities.BDBPlace;
|
||||
import ru.trader.store.berkeley.entities.BDBVendor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -136,6 +137,24 @@ public class BDBMarket extends AbstractMarket {
|
||||
return vendors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPlaceNames() {
|
||||
return store.getPlaceAccessor().getAllNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getVendorNames() {
|
||||
Collection<BDBPlace> places = store.getPlaceAccessor().getAllPlaces();
|
||||
Collection<String> res = new LinkedList<>();
|
||||
for (BDBPlace place : places) {
|
||||
Collection<String> names = store.getVendorAccessor().getNamesByPlace(place.getId());
|
||||
for (String name : names) {
|
||||
res.add(place.getName()+": "+name);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStat getStat(OFFER_TYPE type, Item item) {
|
||||
ItemStat entry = getItemCache(type).get(item);
|
||||
|
||||
@@ -147,6 +147,11 @@ public class PlaceProxy extends AbstractPlace {
|
||||
return !store.getVendorAccessor().contains(place.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getVendorNames() {
|
||||
return store.getVendorAccessor().getNamesByPlace(place.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -45,6 +45,14 @@ public class PlaceDA<T> {
|
||||
});
|
||||
}
|
||||
|
||||
public Collection<BDBPlace> getAllPlaces(){
|
||||
return DAUtils.getAll(indexById, p -> p);
|
||||
}
|
||||
|
||||
public Collection<String> getAllNames(){
|
||||
return DAUtils.getAll(indexById, BDBPlace::getName);
|
||||
}
|
||||
|
||||
public BDBPlace put(BDBPlace place){
|
||||
return indexById.put(place);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,15 @@ public class VendorDA<T> {
|
||||
return DAUtils.getAll(indexByPlaceId, placeId, convertFunc);
|
||||
}
|
||||
|
||||
public Collection<BDBVendor> getAllVendors(){
|
||||
return DAUtils.getAll(indexById, v -> v);
|
||||
}
|
||||
|
||||
public Collection<String> getNamesByPlace(long placeId){
|
||||
return DAUtils.getAll(indexByPlaceId, placeId, BDBVendor::getName);
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(long placeId){
|
||||
return indexByPlaceId.contains(placeId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user