implement parsing Shipyard from EDCE
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ru.trader.edce;
|
||||
|
||||
import ru.trader.edce.entities.Commodity;
|
||||
import ru.trader.edce.entities.ShipyardItem;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -114,29 +115,29 @@ public class Converter {
|
||||
GROUP_ID.put("Weapons", "weapons");
|
||||
|
||||
|
||||
SHIP_ID.put(128049249L,"Sidewinder");
|
||||
SHIP_ID.put(128049261L, "Hauler");
|
||||
SHIP_ID.put(128049255L, "Eagle");
|
||||
SHIP_ID.put(128049267L, "Adder");
|
||||
// SHIP_ID.put("Imperial Eagle");
|
||||
SHIP_ID.put(128049273L, "Viper");
|
||||
SHIP_ID.put(128049279L, "Cobra MK3");
|
||||
SHIP_ID.put(128671217L, "Diamondback Scout");
|
||||
SHIP_ID.put(128049285L, "TYPE-6");
|
||||
// SHIP_ID.put("Diamondback Explorer");
|
||||
SHIP_ID.put(128049309L, "Vulture");
|
||||
SHIP_ID.put(128049303L, "ASP");
|
||||
// SHIP_ID.put("TYPE-7");
|
||||
// SHIP_ID.put("Imperial Clipper");
|
||||
// SHIP_ID.put("Imperial Courier");
|
||||
SHIP_ID.put(128049321L, "Federal Dropship");
|
||||
// SHIP_ID.put("Federal Assault Ship");
|
||||
// SHIP_ID.put("Federal Gunship");
|
||||
// SHIP_ID.put("Orca");
|
||||
// SHIP_ID.put("Fer-de-Lance");
|
||||
SHIP_ID.put(128049339L, "Python");
|
||||
// SHIP_ID.put("TYPE-9");
|
||||
SHIP_ID.put(128049363L, "Anaconda");
|
||||
SHIP_ID.put(128049249L,"sidewinder");
|
||||
SHIP_ID.put(128049261L, "hauler");
|
||||
SHIP_ID.put(128049255L, "eagle");
|
||||
SHIP_ID.put(128049267L, "adder");
|
||||
SHIP_ID.put(128672138L, "imperial_eagle");
|
||||
SHIP_ID.put(128049273L, "viper");
|
||||
SHIP_ID.put(128049279L, "cobraMk3");
|
||||
SHIP_ID.put(128671217L, "diamondback_scout");
|
||||
SHIP_ID.put(128049285L, "type6");
|
||||
SHIP_ID.put(128671831L, "diamondback_explorer");
|
||||
SHIP_ID.put(128049309L, "vulture");
|
||||
SHIP_ID.put(128049303L, "asp");
|
||||
SHIP_ID.put(128049297L, "type7");
|
||||
SHIP_ID.put(128049315L, "imperial_clipper");
|
||||
SHIP_ID.put(128671223L, "imperial_courier");
|
||||
SHIP_ID.put(128049321L, "federal_dropship");
|
||||
SHIP_ID.put(128672145L, "federal_assault_ship");
|
||||
SHIP_ID.put(128672152L, "federal_gunship");
|
||||
SHIP_ID.put(128049327L, "orca");
|
||||
SHIP_ID.put(128049351L, "fer_de_lance");
|
||||
SHIP_ID.put(128049339L, "python");
|
||||
SHIP_ID.put(128049333L, "type9");
|
||||
SHIP_ID.put(128049363L, "anaconda");
|
||||
}
|
||||
|
||||
public static String getItemId(Commodity commodity){
|
||||
@@ -151,4 +152,8 @@ public class Converter {
|
||||
return GROUP_ID.get(edName);
|
||||
}
|
||||
|
||||
public static String getShipId(ShipyardItem ship){
|
||||
return SHIP_ID.get(ship.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
utils/src/main/java/ru/trader/edce/entities/Shipyard.java
Normal file
35
utils/src/main/java/ru/trader/edce/entities/Shipyard.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package ru.trader.edce.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Shipyard {
|
||||
@JsonProperty("shipyard_list")
|
||||
private Map<String, ShipyardItem> items = new HashMap<>();
|
||||
@JsonProperty("unavailable_list")
|
||||
private List<ShipyardItem> unavailables = new ArrayList<>();
|
||||
|
||||
|
||||
public Map<String, ShipyardItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(Map<String, ShipyardItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public List<ShipyardItem> getUnavailables() {
|
||||
return unavailables;
|
||||
}
|
||||
|
||||
public void setUnavailables(List<ShipyardItem> unavailables) {
|
||||
this.unavailables = unavailables;
|
||||
}
|
||||
|
||||
public Collection<ShipyardItem> getShips(){
|
||||
Collection<ShipyardItem> ships = new ArrayList<>(items.values());
|
||||
ships.addAll(unavailables);
|
||||
return ships;
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,13 @@ public class ShipyardItem {
|
||||
public void setBasevalue(long basevalue) {
|
||||
this.basevalue = basevalue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShipyardItem{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", basevalue=" + basevalue +
|
||||
"} ";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public class Starport {
|
||||
private String faction;
|
||||
private List<Commodity> commodities = new ArrayList<>();
|
||||
private Map<String, Module> modules = new LinkedHashMap<>();
|
||||
private Shipyard ships;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
@@ -49,6 +50,14 @@ public class Starport {
|
||||
this.modules = modules;
|
||||
}
|
||||
|
||||
public Shipyard getShips() {
|
||||
return ships;
|
||||
}
|
||||
|
||||
public void setShips(Shipyard ships) {
|
||||
this.ships = ships;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -186,4 +186,23 @@ public class ParseTest extends Assert {
|
||||
assertNotNull(ship);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseShipyard() throws Exception {
|
||||
LOG.info("Test parse json9");
|
||||
InputStream is = getClass().getResourceAsStream("/edce/edce9.json");
|
||||
String json = read(is);
|
||||
LOG.trace("Parse json:");
|
||||
LOG.trace("{}", json);
|
||||
EDPacket packet = EDCEParser.parseJSON(json);
|
||||
Commander commander = packet.getCommander();
|
||||
assertNotNull(commander);
|
||||
System system = packet.getLastSystem();
|
||||
assertNotNull(system);
|
||||
Starport starport = packet.getLastStarport();
|
||||
assertNotNull(starport);
|
||||
Shipyard shipyard = starport.getShips();
|
||||
assertNotNull(shipyard);
|
||||
assertEquals(23, shipyard.getShips().size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user