collect more info on check powerplay intersects
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.beans.property.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
@@ -11,6 +12,7 @@ import ru.trader.model.*;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.PowerStateStringConverter;
|
||||
import ru.trader.view.support.PowerStringConverter;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
import ru.trader.view.support.autocomplete.AutoCompletion;
|
||||
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
||||
import ru.trader.view.support.autocomplete.SystemsProvider;
|
||||
@@ -45,12 +47,12 @@ public class PowerPlayController {
|
||||
@FXML
|
||||
private ListView<SystemModel> controlSystems;
|
||||
@FXML
|
||||
private TableView<SystemModel> tblResults;
|
||||
private TableView<ResultEntry> tblResults;
|
||||
|
||||
private MarketModel world;
|
||||
private ProfileModel profile;
|
||||
private PowerPlayAnalyzator analyzator;
|
||||
private final List<SystemModel> result = FXCollections.observableArrayList();
|
||||
private final List<ResultEntry> result = FXCollections.observableArrayList();
|
||||
|
||||
|
||||
@FXML
|
||||
@@ -98,17 +100,17 @@ public class PowerPlayController {
|
||||
Collection<Place> controlls = getControlSystems();
|
||||
result.clear();
|
||||
if (starSystem != null && !controlls.isEmpty()){
|
||||
Collection<Place> intersects = analyzator.getIntersects(starSystem, controlls);
|
||||
result.addAll(BindingsHelper.observableList(intersects, world.getModeler()::get));
|
||||
Collection<PowerPlayAnalyzator.IntersectData> intersects = analyzator.getIntersects(starSystem, controlls);
|
||||
result.addAll(BindingsHelper.observableList(intersects, d -> new ResultEntry(d, starSystem)));
|
||||
}
|
||||
}
|
||||
|
||||
private void getControlling(){
|
||||
Place starSystem = ModelFabric.get(checkedSystem.getValue());
|
||||
final Place starSystem = ModelFabric.get(checkedSystem.getValue());
|
||||
result.clear();
|
||||
if (starSystem != null){
|
||||
Collection<Place> controllings = analyzator.getControlling(starSystem);
|
||||
result.addAll(BindingsHelper.observableList(controllings, world.getModeler()::get));
|
||||
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem);
|
||||
result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +118,17 @@ public class PowerPlayController {
|
||||
Collection<Place> controlls = getControlSystems();
|
||||
result.clear();
|
||||
if (!controlls.isEmpty()){
|
||||
Collection<Place> near = analyzator.getNear(controlls);
|
||||
result.addAll(BindingsHelper.observableList(near, world.getModeler()::get));
|
||||
Collection<PowerPlayAnalyzator.IntersectData> near = analyzator.getNear(controlls);
|
||||
result.addAll(BindingsHelper.observableList(near, ResultEntry::new));
|
||||
}
|
||||
}
|
||||
|
||||
private void getNearExpansions(){
|
||||
Collection<Place> controlls = getControlSystems();
|
||||
result.clear();
|
||||
if (!controlls.isEmpty()){
|
||||
Collection<PowerPlayAnalyzator.IntersectData> near = analyzator.getNearExpansions(controlls);
|
||||
result.addAll(BindingsHelper.observableList(near, ResultEntry::new));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +159,9 @@ public class PowerPlayController {
|
||||
if (rbNear.isSelected()){
|
||||
getNear();
|
||||
}
|
||||
|
||||
if (rbExpansions.isSelected()){
|
||||
getNearExpansions();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -184,10 +197,83 @@ public class PowerPlayController {
|
||||
|
||||
@FXML
|
||||
private void copyToClipboard(){
|
||||
SystemModel starSystem = tblResults.getSelectionModel().getSelectedItem();
|
||||
if (starSystem != null){
|
||||
Main.copyToClipboard(starSystem.getName());
|
||||
ResultEntry entry = tblResults.getSelectionModel().getSelectedItem();
|
||||
if (entry != null){
|
||||
Main.copyToClipboard(entry.starSystem.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ResultEntry {
|
||||
private final SystemModel starSystem;
|
||||
private final StationModel nearStation;
|
||||
private final ReadOnlyDoubleProperty distance;
|
||||
private final ReadOnlyStringProperty maxSizePad;
|
||||
private final ReadOnlyIntegerProperty intersectCount;
|
||||
private final ReadOnlyStringProperty controlling;
|
||||
|
||||
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
|
||||
this(data, null);
|
||||
}
|
||||
|
||||
public ResultEntry(PowerPlayAnalyzator.IntersectData data, Place from) {
|
||||
starSystem = world.getModeler().get(data.getStarSystem());
|
||||
maxSizePad = new SimpleStringProperty(starSystem.getMaxSizePad());
|
||||
intersectCount = new SimpleIntegerProperty(data.getCount());
|
||||
nearStation = starSystem.getNear();
|
||||
controlling = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
|
||||
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN);
|
||||
}
|
||||
|
||||
private String getControllingString(Collection<PowerPlayAnalyzator.ControllingData> controllings) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (PowerPlayAnalyzator.ControllingData data : controllings) {
|
||||
if (res.length() != 0) res.append("\n");
|
||||
res.append(data.getCenter().getName());
|
||||
res.append(" (").append(ViewUtils.distanceToString(data.getDistance())).append(")");
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
|
||||
public ReadOnlyStringProperty stationProperty(){
|
||||
return new SimpleStringProperty(String.format("%s (%.0f Ls)", nearStation.getName(), nearStation.getDistance()));
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty nameProperty(){
|
||||
return starSystem.nameProperty();
|
||||
}
|
||||
|
||||
public GOVERNMENT getGovernment() {
|
||||
return starSystem.getGovernment();
|
||||
}
|
||||
|
||||
public FACTION getFaction() {
|
||||
return starSystem.getFaction();
|
||||
}
|
||||
|
||||
public POWER getPower() {
|
||||
return starSystem.getPower();
|
||||
}
|
||||
|
||||
public POWER_STATE getPowerState() {
|
||||
return starSystem.getPowerState();
|
||||
}
|
||||
|
||||
public ReadOnlyDoubleProperty distanceProperty() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty maxSizePadProperty() {
|
||||
return maxSizePad;
|
||||
}
|
||||
|
||||
public ReadOnlyIntegerProperty intersectCountProperty() {
|
||||
return intersectCount;
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty controllingProperty() {
|
||||
return controlling;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import ru.trader.core.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SystemModel {
|
||||
@@ -167,6 +168,24 @@ public class SystemModel {
|
||||
&& (system.getFaction() == FACTION.NONE || !system.isEmpty());
|
||||
}
|
||||
|
||||
public String getMaxSizePad(){
|
||||
if (system.isEmpty()) return "-";
|
||||
String size = "M";
|
||||
for (Vendor vendor : system.get()) {
|
||||
STATION_TYPE type = vendor.getType();
|
||||
if (type != null){
|
||||
if (type.hasLargeLandpad()) return "L";
|
||||
} else {
|
||||
size = "?";
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public StationModel getNear(){
|
||||
Optional<Vendor> near = system.get().stream().sorted((v1, v2) -> Double.compare(v1.getDistance(), v2.getDistance())).findFirst();
|
||||
return asModel(near.orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -74,9 +74,18 @@
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="110" text="%market.order.distance" fx:id="sortColumn" sortType="ASCENDING">
|
||||
<cellFactory><DistanceCell /></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="80" text="Типы площадок">
|
||||
<TableColumn minWidth="80" text="Тип площадки">
|
||||
<cellValueFactory><PropertyValueFactory property="maxSizePad"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="80" text="Пересечений">
|
||||
<cellValueFactory><PropertyValueFactory property="intersectCount"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="200" text="Контролируемые системы">
|
||||
<cellValueFactory><PropertyValueFactory property="controlling"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package ru.trader.analysis;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.core.Market;
|
||||
import ru.trader.core.POWER;
|
||||
import ru.trader.core.Place;
|
||||
import ru.trader.core.StarSystemFilter;
|
||||
import ru.trader.core.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -33,59 +30,95 @@ public class PowerPlayAnalyzator {
|
||||
this.starSystemFilter = starSystemFilter;
|
||||
}
|
||||
|
||||
public Collection<Place> getControlling(Place starSystem){
|
||||
return getControlling(starSystem, market.get(), CONTROLLING_RADIUS);
|
||||
public Collection<IntersectData> getControlling(Place starSystem){
|
||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||
return getControlling(starSystem, candidates, CONTROLLING_RADIUS).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<Place> getIntersects(Collection<Place> starSystems){
|
||||
public Collection<IntersectData> getIntersects(Collection<Place> starSystems){
|
||||
return getIntersects(market.get(), starSystems, CONTROLLING_RADIUS);
|
||||
}
|
||||
|
||||
public Collection<Place> getIntersects(Place starSystem, Collection<Place> starSystems){
|
||||
return getIntersects(starSystem, market.get(), starSystems, CONTROLLING_RADIUS);
|
||||
public Collection<IntersectData> getIntersects(Place starSystem, Collection<Place> starSystems){
|
||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||
return getIntersects(starSystem, candidates, starSystems, CONTROLLING_RADIUS).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<Place> getNear(Collection<Place> starSystems){
|
||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getPower() == POWER.NONE);
|
||||
return getNear(candidates, starSystems, CONTROLLING_RADIUS, CONTROLLING_RADIUS*2);
|
||||
public Collection<IntersectData> getNear(Collection<Place> starSystems){
|
||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getPower() == POWER.NONE && p.getFaction() != FACTION.NONE);
|
||||
return getNear(candidates, starSystems, CONTROLLING_RADIUS, CONTROLLING_RADIUS*2).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Collection<Place> getControlling(Place starSystem, Collection<Place> starSystems, double radius){
|
||||
return starSystems.stream()
|
||||
.filter(new Controlling(starSystem, radius))
|
||||
.collect(Collectors.toList());
|
||||
public Collection<IntersectData> getNearExpansions(Collection<Place> starSystems){
|
||||
return getNearExpansions(market.get(), starSystems, CONTROLLING_RADIUS * 2);
|
||||
}
|
||||
|
||||
public static Collection<IntersectData> getControlling(Place starSystem, Collection<Place> starSystems, double radius){
|
||||
return getControlling(starSystem, starSystems.stream(), radius).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Stream<IntersectData> getControlling(Place starSystem, Stream<Place> starSystems, double radius){
|
||||
IntersectsMapper controllingMapper = new IntersectsMapper(Collections.singleton(starSystem), radius, true, true);
|
||||
return starSystems
|
||||
.map(controllingMapper)
|
||||
.filter(IntersectData::isIntersect);
|
||||
}
|
||||
|
||||
|
||||
public static Collection<Place> getNear(Collection<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
||||
return starSystems.stream()
|
||||
.filter(new FarDropper(centers, maxDistance))
|
||||
.filter(intersectsAnyPredicate(centers, radius).negate())
|
||||
.sorted(new DistanceComparator(centers))
|
||||
.collect(Collectors.toList());
|
||||
public static Collection<IntersectData> getNear(Collection<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
||||
return getNear(starSystems.stream(), centers, radius, maxDistance).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Collection<Place> getNear(Stream<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
||||
public static Stream<IntersectData> getNear(Stream<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
||||
IntersectsMapper controllingMapper = new IntersectsMapper(centers, radius, true, true);
|
||||
IntersectsMapper distanceMapper = new IntersectsMapper(centers, maxDistance, false, true);
|
||||
return starSystems.filter(new FarDropper(centers, maxDistance))
|
||||
.filter(intersectsAnyPredicate(centers, radius).negate())
|
||||
.sorted(new DistanceComparator(centers))
|
||||
.collect(Collectors.toList());
|
||||
.map(controllingMapper)
|
||||
.filter(d -> d.getCount() == 0)
|
||||
.map(d -> distanceMapper.apply(d.getStarSystem()))
|
||||
.filter(IntersectData::isIntersect)
|
||||
.sorted(new DistanceComparator());
|
||||
}
|
||||
|
||||
public static Collection<Place> getIntersects(Place checkedSystem, Collection<Place> starSystems, Collection<Place> centers, double radius){
|
||||
return starSystems.stream()
|
||||
public static Collection<IntersectData> getNearExpansions(Collection<Place> starSystems, Collection<Place> centers, double maxDistance){
|
||||
return getNearExpansions(starSystems.stream(), centers, maxDistance).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Stream<IntersectData> getNearExpansions(Stream<Place> starSystems, Collection<Place> centers, double maxDistance){
|
||||
IntersectsMapper mapper = new IntersectsMapper(centers, maxDistance, false, true);
|
||||
return starSystems.filter(new FarDropper(centers, maxDistance))
|
||||
.filter(p -> p.getPowerState() == POWER_STATE.EXPANSION)
|
||||
.map(mapper)
|
||||
.sorted(new DistanceComparator());
|
||||
}
|
||||
|
||||
|
||||
public static Collection<IntersectData> getIntersects(Place checkedSystem, Collection<Place> starSystems, Collection<Place> centers, double radius){
|
||||
return getIntersects(checkedSystem, starSystems.stream(), centers, radius).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Stream<IntersectData> getIntersects(Place checkedSystem, Stream<Place> starSystems, Collection<Place> centers, double radius){
|
||||
IntersectsMapper mapper = new IntersectsMapper(centers, radius, true, true);
|
||||
return starSystems
|
||||
.filter(new FarDropper(centers, radius))
|
||||
.filter(intersectsPredicate(checkedSystem, centers, radius))
|
||||
.collect(Collectors.toList());
|
||||
.filter(new Controlling(checkedSystem, radius))
|
||||
.map(mapper)
|
||||
.filter(IntersectData::isIntersect);
|
||||
}
|
||||
|
||||
public static Collection<Place> getIntersects(Collection<Place> starSystems, Collection<Place> centers, double radius){
|
||||
return starSystems.stream()
|
||||
public static Collection<IntersectData> getIntersects(Collection<Place> starSystems, Collection<Place> centers, double radius){
|
||||
return getIntersects(starSystems.stream(), centers, radius).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Stream<IntersectData> getIntersects(Stream<Place> starSystems, Collection<Place> centers, double radius){
|
||||
IntersectsMapper mapper = new IntersectsMapper(centers, radius, false, false);
|
||||
final int needCount = centers.size();
|
||||
return starSystems
|
||||
.filter(new FarDropper(centers, radius))
|
||||
.filter(intersectsPredicate(centers, radius))
|
||||
.collect(Collectors.toList());
|
||||
.map(mapper)
|
||||
.filter(d -> d.getCount() == needCount);
|
||||
}
|
||||
|
||||
/*
|
||||
private static Predicate<Place> intersectsAnyPredicate(Collection<Place> places, double radius){
|
||||
Predicate<Place> intersects = null;
|
||||
for (Place place : places) {
|
||||
@@ -108,7 +141,7 @@ public class PowerPlayAnalyzator {
|
||||
private static Predicate<Place> intersectsPredicate(Place checkedPlace, Collection<Place> places, double radius){
|
||||
return new Controlling(checkedPlace, radius).and(intersectsAnyPredicate(places, radius));
|
||||
}
|
||||
|
||||
*/
|
||||
private static class Controlling implements Predicate<Place> {
|
||||
private final Place center;
|
||||
private final double radius;
|
||||
@@ -178,39 +211,129 @@ public class PowerPlayAnalyzator {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DistanceComparator implements Comparator<Place> {
|
||||
private final Collection<Place> centers;
|
||||
private final HashMap<Place, Double> distances;
|
||||
private static class DistanceComparator implements Comparator<IntersectData> {
|
||||
|
||||
|
||||
private DistanceComparator(Collection<Place> centers) {
|
||||
this.centers = centers;
|
||||
distances = new HashMap<>(100);
|
||||
|
||||
}
|
||||
|
||||
private double getMinDistance(Place place){
|
||||
Double distance = distances.get(place);
|
||||
if (distance != null) return distance;
|
||||
|
||||
Collection<Double> ds = new LimitedQueue<>(3, Comparator.naturalOrder());
|
||||
for (Place center : centers) {
|
||||
double d = center.getDistance(place);
|
||||
ds.add(d);
|
||||
}
|
||||
private double getMinDistance(IntersectData data){
|
||||
ControllingData[] contollings = data.contollings;
|
||||
double dist = 0;
|
||||
for (Double d : ds) {
|
||||
dist += d;
|
||||
int count = Math.min(3, contollings.length);
|
||||
for (int i = 0; i < count; i++) {
|
||||
dist += contollings[i].distance;
|
||||
}
|
||||
distances.put(place, dist);
|
||||
return dist;
|
||||
return dist/count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Place o1, Place o2) {
|
||||
public int compare(IntersectData o1, IntersectData o2) {
|
||||
return Double.compare(getMinDistance(o1), getMinDistance(o2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class IntersectsMapper implements Function<Place, IntersectData> {
|
||||
private final Collection<Place> centers;
|
||||
private final double radius;
|
||||
private final boolean findAny;
|
||||
private final boolean checkedAll;
|
||||
|
||||
private IntersectsMapper(Collection<Place> centers, double radius, boolean findAny, boolean checkedAll) {
|
||||
this.centers = new ArrayList<>(centers);
|
||||
this.radius = radius;
|
||||
this.findAny = findAny;
|
||||
this.checkedAll = findAny || checkedAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntersectData apply(Place place) {
|
||||
Collection<ControllingData> controllingDatas = null;
|
||||
for (Place center : centers) {
|
||||
if (place == center) continue;
|
||||
double distance = center.getDistance(place);
|
||||
LOG.trace("Check {}, distance to {} = {}, radius = {}", place, center, distance, radius);
|
||||
if (distance <= radius){
|
||||
if (findAny){
|
||||
return new IntersectData(place, center, distance);
|
||||
}
|
||||
if (controllingDatas == null) controllingDatas = new ArrayList<>(3);
|
||||
controllingDatas.add(new ControllingData(center, distance));
|
||||
} else {
|
||||
if (!checkedAll) break;
|
||||
}
|
||||
}
|
||||
if (controllingDatas == null){
|
||||
return new IntersectData(place);
|
||||
}
|
||||
return new IntersectData(place, controllingDatas);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class IntersectData {
|
||||
private final Place starSystem;
|
||||
private final ControllingData[] contollings;
|
||||
|
||||
public IntersectData(Place starSystem) {
|
||||
this.starSystem = starSystem;
|
||||
this.contollings = new ControllingData[0];
|
||||
}
|
||||
|
||||
|
||||
public IntersectData(Place starSystem, Place control, double distance) {
|
||||
this.starSystem = starSystem;
|
||||
this.contollings = new ControllingData[]{new ControllingData(control,distance)};
|
||||
}
|
||||
|
||||
public IntersectData(Place starSystem, Collection<ControllingData> controlling) {
|
||||
this.starSystem = starSystem;
|
||||
this.contollings = controlling.toArray(new ControllingData[controlling.size()]);
|
||||
Arrays.sort(contollings);
|
||||
}
|
||||
|
||||
public Place getStarSystem() {
|
||||
return starSystem;
|
||||
}
|
||||
|
||||
public Collection<ControllingData> getControllingSystems(){
|
||||
return Arrays.asList(contollings);
|
||||
}
|
||||
|
||||
public int getCount(){
|
||||
return contollings.length;
|
||||
}
|
||||
|
||||
public double getMinDistance(){
|
||||
return contollings.length > 0 ? contollings[0].distance : Double.NaN;
|
||||
}
|
||||
|
||||
public boolean isIntersect(){
|
||||
return contollings.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ControllingData implements Comparable<ControllingData> {
|
||||
private final Place center;
|
||||
private final Double distance;
|
||||
|
||||
public ControllingData(Place center, Double distance) {
|
||||
this.center = center;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public Place getCenter() {
|
||||
return center;
|
||||
}
|
||||
|
||||
public Double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull ControllingData o) {
|
||||
Objects.requireNonNull(o, "Not compare with null");
|
||||
return Double.compare(distance, o.distance);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,10 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
||||
Collection<Place> centers = new ArrayList<>();
|
||||
centers.add(lhs3262);
|
||||
|
||||
Collection<Place> intersects = analyzator.getIntersects(starSystems, centers, 15);
|
||||
Collection<PowerPlayAnalyzator.IntersectData> intersects = analyzator.getIntersects(starSystems, centers, 15);
|
||||
LOG.info("Test intersects by LHS 3262, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect) <= 15);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 15);
|
||||
}
|
||||
assertTrue(intersects.containsAll(controllingLhs3262));
|
||||
assertEquals(controllingLhs3262.size(), intersects.size());
|
||||
@@ -58,30 +58,30 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
||||
centers.add(aulin);
|
||||
intersects = analyzator.getIntersects(starSystems, centers, 15);
|
||||
LOG.info("Test intersects by LHS 3262 and Aulin, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect) <= 15);
|
||||
assertTrue(aulin.getDistance(intersect) <= 15);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 15);
|
||||
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 15);
|
||||
}
|
||||
assertTrue(intersects.containsAll(expectedIntersect));
|
||||
assertEquals(expectedIntersect.size(), intersects.size());
|
||||
|
||||
centers.add(morgor);
|
||||
intersects = analyzator.getIntersects(starSystems, centers, 15);
|
||||
intersects = PowerPlayAnalyzator.getIntersects(starSystems, centers, 15);
|
||||
LOG.info("Test intersects by LHS 3262 and Aulin and Morgor, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect) <= 15);
|
||||
assertTrue(aulin.getDistance(intersect) <= 15);
|
||||
assertTrue(morgor.getDistance(intersect) <= 15);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 15);
|
||||
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 15);
|
||||
assertTrue(morgor.getDistance(intersect.getStarSystem()) <= 15);
|
||||
}
|
||||
assertTrue(intersects.containsAll(expected3Intersect));
|
||||
assertEquals(expected3Intersect.size(), intersects.size());
|
||||
|
||||
intersects = analyzator.getIntersects(starSystems, centers, 12);
|
||||
intersects = PowerPlayAnalyzator.getIntersects(starSystems, centers, 12);
|
||||
LOG.info("Test intersects by LHS 3262 and Aulin and Morgor, 12 radius, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect) <= 12);
|
||||
assertTrue(aulin.getDistance(intersect) <= 12);
|
||||
assertTrue(morgor.getDistance(intersect) <= 12);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 12);
|
||||
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 12);
|
||||
assertTrue(morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||
}
|
||||
assertEquals(0, intersects.size());
|
||||
|
||||
@@ -102,41 +102,41 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
||||
Collection<Place> centers = new ArrayList<>();
|
||||
centers.add(lhs3262);
|
||||
centers.add(aulin);
|
||||
Collection<Place> intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
Collection<PowerPlayAnalyzator.IntersectData> intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
LOG.info("Test LHS 417 intersect LHS 3262 or Aulin, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect) <= 12 || aulin.getDistance(intersect) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 12 || aulin.getDistance(intersect.getStarSystem()) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||
}
|
||||
assertTrue(intersects.containsAll(expectedIntersect));
|
||||
assertEquals(expectedIntersect.size(), intersects.size());
|
||||
|
||||
centers.add(morgor);
|
||||
intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
LOG.info("Test LHS 417 intersect LHS 3262 or Aulin or Morgor, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect) <= 12 || aulin.getDistance(intersect) <= 12 || morgor.getDistance(intersect) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 12 || aulin.getDistance(intersect.getStarSystem()) <= 12 || morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||
}
|
||||
assertTrue(intersects.containsAll(expected3Intersect));
|
||||
assertEquals(expected3Intersect.size(), intersects.size());
|
||||
|
||||
centers.clear();
|
||||
centers.add(morgor);
|
||||
intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
LOG.info("Test LHS 417 intersect Morgor, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(morgor.getDistance(intersect) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||
}
|
||||
assertEquals(0, intersects.size());
|
||||
|
||||
centers.add(aulin);
|
||||
intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||
LOG.info("Test LHS 417 intersect Aulin or Morgor, found {}", intersects.size());
|
||||
for (Place intersect : intersects) {
|
||||
assertTrue(aulin.getDistance(intersect) <= 12 || morgor.getDistance(intersect) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
||||
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 12 || morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||
}
|
||||
assertTrue(intersects.containsAll(expected2Intersect));
|
||||
assertEquals(expected2Intersect.size(), intersects.size());
|
||||
@@ -155,11 +155,11 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
||||
Collection<Place> centers = new ArrayList<>();
|
||||
centers.add(lhs3262);
|
||||
centers.add(aulin);
|
||||
Collection<Place> near = analyzator.getNear(starSystems, centers, 15, 30);
|
||||
Collection<PowerPlayAnalyzator.IntersectData> near = PowerPlayAnalyzator.getNear(starSystems, centers, 15, 30);
|
||||
LOG.info("Test near by LHS 3262 and Aulin, found {}", near.size());
|
||||
assertTrue(near.size() > 0);
|
||||
for (Place place : near) {
|
||||
Collection<Place> intersect = analyzator.getIntersects(place, starSystems, centers, 15);
|
||||
for (PowerPlayAnalyzator.IntersectData place : near) {
|
||||
Collection<PowerPlayAnalyzator.IntersectData> intersect = PowerPlayAnalyzator.getIntersects(place.getStarSystem(), starSystems, centers, 15);
|
||||
assertEquals(0, intersect.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PPImportTest extends Assert {
|
||||
|
||||
@@ -42,11 +43,16 @@ public class PPImportTest extends Assert {
|
||||
|
||||
PowerPlayAnalyzator analyzator = new PowerPlayAnalyzator(market);
|
||||
|
||||
Collection<Place> intersectsMahon = analyzator.getIntersects(Arrays.asList(opala, gd_319));
|
||||
Collection<Place> intersectsDuval = analyzator.getIntersects(bolg, Arrays.asList(opala, gd_319));
|
||||
Collection<Place> intersectsMahon = analyzator.getIntersects(Arrays.asList(opala, gd_319))
|
||||
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||
Collection<Place> intersectsDuval = analyzator.getIntersects(bolg, Arrays.asList(opala, gd_319))
|
||||
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||
|
||||
Collection<Place> exploitedOpala = analyzator.getControlling(opala);
|
||||
Collection<Place> exploitedBolg = analyzator.getControlling(bolg);
|
||||
|
||||
Collection<Place> exploitedOpala = analyzator.getControlling(opala)
|
||||
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||
Collection<Place> exploitedBolg = analyzator.getControlling(bolg)
|
||||
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||
|
||||
for (Place place : intersectsMahon) {
|
||||
assertEquals(POWER_STATE.EXPLOITED, place.getPowerState());
|
||||
|
||||
Reference in New Issue
Block a user