From 3db3ef53be9b976687e0d93de7c22f8a1cb24623 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Thu, 3 Nov 2016 15:53:25 +0300 Subject: [PATCH] collect more info on check powerplay intersects --- .../controllers/PowerPlayController.java | 114 +++++++- .../java/ru/trader/model/SystemModel.java | 19 ++ client/src/main/resources/view/powerplay.fxml | 11 +- .../trader/analysis/PowerPlayAnalyzator.java | 247 +++++++++++++----- .../analysis/PowerPlayAnalyzatorTest.java | 70 ++--- .../ru/trader/powerplay/PPImportTest.java | 14 +- 6 files changed, 359 insertions(+), 116 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/PowerPlayController.java b/client/src/main/java/ru/trader/controllers/PowerPlayController.java index de841a4..d56cadc 100644 --- a/client/src/main/java/ru/trader/controllers/PowerPlayController.java +++ b/client/src/main/java/ru/trader/controllers/PowerPlayController.java @@ -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 controlSystems; @FXML - private TableView tblResults; + private TableView tblResults; private MarketModel world; private ProfileModel profile; private PowerPlayAnalyzator analyzator; - private final List result = FXCollections.observableArrayList(); + private final List result = FXCollections.observableArrayList(); @FXML @@ -98,17 +100,17 @@ public class PowerPlayController { Collection controlls = getControlSystems(); result.clear(); if (starSystem != null && !controlls.isEmpty()){ - Collection intersects = analyzator.getIntersects(starSystem, controlls); - result.addAll(BindingsHelper.observableList(intersects, world.getModeler()::get)); + Collection 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 controllings = analyzator.getControlling(starSystem); - result.addAll(BindingsHelper.observableList(controllings, world.getModeler()::get)); + Collection controllings = analyzator.getControlling(starSystem); + result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem))); } } @@ -116,8 +118,17 @@ public class PowerPlayController { Collection controlls = getControlSystems(); result.clear(); if (!controlls.isEmpty()){ - Collection near = analyzator.getNear(controlls); - result.addAll(BindingsHelper.observableList(near, world.getModeler()::get)); + Collection near = analyzator.getNear(controlls); + result.addAll(BindingsHelper.observableList(near, ResultEntry::new)); + } + } + + private void getNearExpansions(){ + Collection controlls = getControlSystems(); + result.clear(); + if (!controlls.isEmpty()){ + Collection 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 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; + } + } +} \ No newline at end of file diff --git a/client/src/main/java/ru/trader/model/SystemModel.java b/client/src/main/java/ru/trader/model/SystemModel.java index f081880..0c95ba7 100644 --- a/client/src/main/java/ru/trader/model/SystemModel.java +++ b/client/src/main/java/ru/trader/model/SystemModel.java @@ -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 near = system.get().stream().sorted((v1, v2) -> Double.compare(v1.getDistance(), v2.getDistance())).findFirst(); + return asModel(near.orElse(null)); + } @Override public String toString() { diff --git a/client/src/main/resources/view/powerplay.fxml b/client/src/main/resources/view/powerplay.fxml index ac4fedb..4f5c81f 100644 --- a/client/src/main/resources/view/powerplay.fxml +++ b/client/src/main/resources/view/powerplay.fxml @@ -74,9 +74,18 @@ + - + + + + + + + + + diff --git a/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java b/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java index 1021e8a..a6de876 100644 --- a/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java +++ b/core/src/main/java/ru/trader/analysis/PowerPlayAnalyzator.java @@ -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 getControlling(Place starSystem){ - return getControlling(starSystem, market.get(), CONTROLLING_RADIUS); + public Collection getControlling(Place starSystem){ + Stream candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE); + return getControlling(starSystem, candidates, CONTROLLING_RADIUS).collect(Collectors.toList()); } - public Collection getIntersects(Collection starSystems){ + public Collection getIntersects(Collection starSystems){ return getIntersects(market.get(), starSystems, CONTROLLING_RADIUS); } - public Collection getIntersects(Place starSystem, Collection starSystems){ - return getIntersects(starSystem, market.get(), starSystems, CONTROLLING_RADIUS); + public Collection getIntersects(Place starSystem, Collection starSystems){ + Stream candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE); + return getIntersects(starSystem, candidates, starSystems, CONTROLLING_RADIUS).collect(Collectors.toList()); } - public Collection getNear(Collection starSystems){ - Stream candidates = market.get().stream().filter(p -> p.getPower() == POWER.NONE); - return getNear(candidates, starSystems, CONTROLLING_RADIUS, CONTROLLING_RADIUS*2); + public Collection getNear(Collection starSystems){ + Stream 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 getControlling(Place starSystem, Collection starSystems, double radius){ - return starSystems.stream() - .filter(new Controlling(starSystem, radius)) - .collect(Collectors.toList()); + public Collection getNearExpansions(Collection starSystems){ + return getNearExpansions(market.get(), starSystems, CONTROLLING_RADIUS * 2); + } + + public static Collection getControlling(Place starSystem, Collection starSystems, double radius){ + return getControlling(starSystem, starSystems.stream(), radius).collect(Collectors.toList()); + } + + public static Stream getControlling(Place starSystem, Stream starSystems, double radius){ + IntersectsMapper controllingMapper = new IntersectsMapper(Collections.singleton(starSystem), radius, true, true); + return starSystems + .map(controllingMapper) + .filter(IntersectData::isIntersect); } - public static Collection getNear(Collection starSystems, Collection 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 getNear(Collection starSystems, Collection centers, double radius, double maxDistance){ + return getNear(starSystems.stream(), centers, radius, maxDistance).collect(Collectors.toList()); } - public static Collection getNear(Stream starSystems, Collection centers, double radius, double maxDistance){ + public static Stream getNear(Stream starSystems, Collection 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 getIntersects(Place checkedSystem, Collection starSystems, Collection centers, double radius){ - return starSystems.stream() + public static Collection getNearExpansions(Collection starSystems, Collection centers, double maxDistance){ + return getNearExpansions(starSystems.stream(), centers, maxDistance).collect(Collectors.toList()); + } + + public static Stream getNearExpansions(Stream starSystems, Collection 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 getIntersects(Place checkedSystem, Collection starSystems, Collection centers, double radius){ + return getIntersects(checkedSystem, starSystems.stream(), centers, radius).collect(Collectors.toList()); + } + + public static Stream getIntersects(Place checkedSystem, Stream starSystems, Collection 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 getIntersects(Collection starSystems, Collection centers, double radius){ - return starSystems.stream() + public static Collection getIntersects(Collection starSystems, Collection centers, double radius){ + return getIntersects(starSystems.stream(), centers, radius).collect(Collectors.toList()); + } + + public static Stream getIntersects(Stream starSystems, Collection 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 intersectsAnyPredicate(Collection places, double radius){ Predicate intersects = null; for (Place place : places) { @@ -108,7 +141,7 @@ public class PowerPlayAnalyzator { private static Predicate intersectsPredicate(Place checkedPlace, Collection places, double radius){ return new Controlling(checkedPlace, radius).and(intersectsAnyPredicate(places, radius)); } - + */ private static class Controlling implements Predicate { private final Place center; private final double radius; @@ -178,39 +211,129 @@ public class PowerPlayAnalyzator { } } - private static class DistanceComparator implements Comparator { - private final Collection centers; - private final HashMap distances; + private static class DistanceComparator implements Comparator { - private DistanceComparator(Collection centers) { - this.centers = centers; - distances = new HashMap<>(100); - - } - - private double getMinDistance(Place place){ - Double distance = distances.get(place); - if (distance != null) return distance; - - Collection 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 { + private final Collection centers; + private final double radius; + private final boolean findAny; + private final boolean checkedAll; + + private IntersectsMapper(Collection 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 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 controlling) { + this.starSystem = starSystem; + this.contollings = controlling.toArray(new ControllingData[controlling.size()]); + Arrays.sort(contollings); + } + + public Place getStarSystem() { + return starSystem; + } + + public Collection 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 { + 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); + } + } + } diff --git a/core/src/test/java/ru/trader/analysis/PowerPlayAnalyzatorTest.java b/core/src/test/java/ru/trader/analysis/PowerPlayAnalyzatorTest.java index c733c97..bd7a769 100644 --- a/core/src/test/java/ru/trader/analysis/PowerPlayAnalyzatorTest.java +++ b/core/src/test/java/ru/trader/analysis/PowerPlayAnalyzatorTest.java @@ -47,10 +47,10 @@ public class PowerPlayAnalyzatorTest extends Assert { Collection centers = new ArrayList<>(); centers.add(lhs3262); - Collection intersects = analyzator.getIntersects(starSystems, centers, 15); + Collection 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 centers = new ArrayList<>(); centers.add(lhs3262); centers.add(aulin); - Collection intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12); + Collection 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 centers = new ArrayList<>(); centers.add(lhs3262); centers.add(aulin); - Collection near = analyzator.getNear(starSystems, centers, 15, 30); + Collection 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 intersect = analyzator.getIntersects(place, starSystems, centers, 15); + for (PowerPlayAnalyzator.IntersectData place : near) { + Collection intersect = PowerPlayAnalyzator.getIntersects(place.getStarSystem(), starSystems, centers, 15); assertEquals(0, intersect.size()); } diff --git a/utils/src/test/java/ru/trader/powerplay/PPImportTest.java b/utils/src/test/java/ru/trader/powerplay/PPImportTest.java index cafceed..f519c69 100644 --- a/utils/src/test/java/ru/trader/powerplay/PPImportTest.java +++ b/utils/src/test/java/ru/trader/powerplay/PPImportTest.java @@ -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 intersectsMahon = analyzator.getIntersects(Arrays.asList(opala, gd_319)); - Collection intersectsDuval = analyzator.getIntersects(bolg, Arrays.asList(opala, gd_319)); + Collection intersectsMahon = analyzator.getIntersects(Arrays.asList(opala, gd_319)) + .stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList()); + Collection intersectsDuval = analyzator.getIntersects(bolg, Arrays.asList(opala, gd_319)) + .stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList()); - Collection exploitedOpala = analyzator.getControlling(opala); - Collection exploitedBolg = analyzator.getControlling(bolg); + + Collection exploitedOpala = analyzator.getControlling(opala) + .stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList()); + Collection exploitedBolg = analyzator.getControlling(bolg) + .stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList()); for (Place place : intersectsMahon) { assertEquals(POWER_STATE.EXPLOITED, place.getPowerState());