add support position of station
This commit is contained in:
@@ -47,4 +47,6 @@ public interface Market {
|
||||
void updateName(Vendor vendor, String name);
|
||||
|
||||
void updateName(Item item, String name);
|
||||
|
||||
void updatePosition(Vendor vendor, double x, double y, double z);
|
||||
}
|
||||
|
||||
@@ -144,6 +144,14 @@ public abstract class MarketSupport implements Market {
|
||||
vendor.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(Vendor vendor, double x, double y, double z){
|
||||
change = true;
|
||||
vendor.setX(x);
|
||||
vendor.setY(y);
|
||||
vendor.setZ(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(Item item, String name){
|
||||
change = true;
|
||||
|
||||
@@ -14,6 +14,9 @@ public abstract class Vendor implements Comparable<Vendor> {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(Vendor.class);
|
||||
|
||||
private String name;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
protected abstract Collection<Offer> getOffers();
|
||||
protected abstract Collection<Item> getItems(OFFER_TYPE offerType);
|
||||
@@ -107,4 +110,37 @@ public abstract class Vendor implements Comparable<Vendor> {
|
||||
if (this == other) return 0;
|
||||
return name != null ? other.name != null ? name.compareTo(other.name) : -1 : 0;
|
||||
}
|
||||
|
||||
public double getDistance(Vendor other){
|
||||
return getDistance(other.x, other.y, other.z);
|
||||
}
|
||||
|
||||
public double getDistance(double x, double y, double z){
|
||||
return Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y-this.y, 2) + Math.pow(z - this.z, 2));
|
||||
}
|
||||
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(double z) {
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.xml.sax.helpers.DefaultHandler;
|
||||
import ru.trader.core.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
public class MarketDocHandler extends DefaultHandler {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(MarketDocHandler.class);
|
||||
@@ -25,6 +26,9 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
protected final static String TYPE_ATTR = "type";
|
||||
protected final static String PRICE_ATTR = "price";
|
||||
protected final static String ITEM_ATTR = "item";
|
||||
protected final static String X_ATTR = "x";
|
||||
protected final static String Y_ATTR = "y";
|
||||
protected final static String Z_ATTR = "z";
|
||||
|
||||
protected Market world;
|
||||
protected Vendor curVendor;
|
||||
@@ -62,12 +66,17 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
|
||||
protected void parseVendor(Attributes attributes) throws SAXException {
|
||||
String name = attributes.getValue(NAME_ATTR);
|
||||
onVendor(name);
|
||||
String x = attributes.getValue(X_ATTR);
|
||||
String y = attributes.getValue(Y_ATTR);
|
||||
String z = attributes.getValue(Z_ATTR);
|
||||
LOG.debug("parse vendor {} position ({};{};{})", name, x, y, z);
|
||||
onVendor(name, x != null ? Double.valueOf(x) : 0, y != null ? Double.valueOf(y) : 0, z != null ? Double.valueOf(z) : 0);
|
||||
}
|
||||
|
||||
protected void parseItem(Attributes attributes) throws SAXException {
|
||||
String name = attributes.getValue(NAME_ATTR);
|
||||
String id = attributes.getValue(ID_ATTR);
|
||||
LOG.debug("parse item {} ({})", name, id);
|
||||
onItem(name, id);
|
||||
}
|
||||
|
||||
@@ -86,8 +95,11 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
curVendor.add(offer);
|
||||
}
|
||||
|
||||
protected void onVendor(String name){
|
||||
protected void onVendor(String name, double x, double y, double z){
|
||||
curVendor = new SimpleVendor(name);
|
||||
curVendor.setX(x);
|
||||
curVendor.setY(y);
|
||||
curVendor.setZ(z);
|
||||
}
|
||||
|
||||
protected void onItem(String name, String id) {
|
||||
|
||||
@@ -75,6 +75,10 @@ public class MarketStreamWriter {
|
||||
protected void writeVendor(Vendor vendor) throws XMLStreamException {
|
||||
out.writeStartElement(MarketDocHandler.VENDOR);
|
||||
out.writeAttribute(MarketDocHandler.NAME_ATTR, vendor.getName());
|
||||
out.writeAttribute(MarketDocHandler.X_ATTR, String.valueOf(vendor.getX()));
|
||||
out.writeAttribute(MarketDocHandler.Y_ATTR, String.valueOf(vendor.getY()));
|
||||
out.writeAttribute(MarketDocHandler.Z_ATTR, String.valueOf(vendor.getZ()));
|
||||
|
||||
for (Offer offer : vendor.getAllOffers()) {
|
||||
writeOffer(offer);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
<xs:element name="offer" type="offerType" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="x" type="xs:double" use="optional"/>
|
||||
<xs:attribute name="y" type="xs:double" use="optional"/>
|
||||
<xs:attribute name="z" type="xs:double" use="optional"/>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="offerType">
|
||||
|
||||
Reference in New Issue
Block a user