OsmAnd/OsmAnd-java/src/main/java/net/osmand/data/TransportStop.java

154 lines
4.1 KiB
Java
Raw Normal View History

package net.osmand.data;
import net.osmand.util.MapUtils;
2018-12-19 08:46:47 +01:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TransportStop extends MapObject {
2019-03-04 12:29:26 +01:00
private static final int DELETED_STOP = -1;
private int[] referencesToRoutes = null;
2019-07-03 09:31:47 +02:00
private TransportStopAggregated transportStopAggregated;
public int distance;
public int x31;
public int y31;
2018-12-19 08:46:47 +01:00
private List<TransportStopExit> exits;
2019-03-04 12:29:26 +01:00
public TransportStop() {
}
2019-03-04 12:29:26 +01:00
public int[] getReferencesToRoutes() {
return referencesToRoutes;
}
2019-03-04 12:29:26 +01:00
public void setReferencesToRoutes(int[] referencesToRoutes) {
this.referencesToRoutes = referencesToRoutes;
}
2019-03-04 12:29:26 +01:00
public boolean isDeleted() {
return referencesToRoutes != null && referencesToRoutes.length == 1 && referencesToRoutes[0] == DELETED_STOP;
}
2019-07-09 17:20:48 +02:00
public boolean hasReferencesToRoutes() {
return referencesToRoutes != null && referencesToRoutes.length > 0;
}
2019-03-04 12:29:26 +01:00
public void setDeleted() {
this.referencesToRoutes = new int[] { DELETED_STOP };
}
2018-06-08 16:13:24 +02:00
public Amenity getAmenity() {
2019-07-03 09:31:47 +02:00
if (transportStopAggregated != null) {
return transportStopAggregated.getAmenity();
}
return null;
2018-06-08 16:13:24 +02:00
}
public void setAmenity(Amenity amenity) {
2019-07-03 09:31:47 +02:00
if (transportStopAggregated == null) {
transportStopAggregated = new TransportStopAggregated();
}
transportStopAggregated.setAmenity(amenity);
}
public List<TransportStop> getLocalTransportStops() {
if (transportStopAggregated != null) {
return transportStopAggregated.getLocalTransportStops();
}
return Collections.emptyList();
}
public void addLocalTransportStop(TransportStop stop) {
if (transportStopAggregated == null) {
transportStopAggregated = new TransportStopAggregated();
}
transportStopAggregated.addLocalTransportStop(stop);
}
public List<TransportStop> getNearbyTransportStops() {
if (transportStopAggregated != null) {
return transportStopAggregated.getNearbyTransportStops();
}
return Collections.emptyList();
}
public void addNearbyTransportStop(TransportStop stop) {
if (transportStopAggregated == null) {
transportStopAggregated = new TransportStopAggregated();
}
transportStopAggregated.addNearbyTransportStop(stop);
}
public TransportStopAggregated getTransportStopAggregated() {
return transportStopAggregated;
}
public void setTransportStopAggregated(TransportStopAggregated stopAggregated) {
transportStopAggregated = stopAggregated;
2018-06-08 16:13:24 +02:00
}
2019-03-04 12:29:26 +01:00
@Override
public void setLocation(double latitude, double longitude) {
super.setLocation(latitude, longitude);
}
public void setLocation(int zoom, int dx, int dy) {
x31 = dx << (31 - zoom);
y31 = dy << (31 - zoom);
setLocation(MapUtils.getLatitudeFromTile(zoom, dy), MapUtils.getLongitudeFromTile(zoom, dx));
}
2018-12-19 08:46:47 +01:00
public void addExit(TransportStopExit transportStopExit) {
if (exits == null) {
exits = new ArrayList<>();
}
exits.add(transportStopExit);
}
2019-03-04 12:29:26 +01:00
public List<TransportStopExit> getExits() {
2018-12-19 08:46:47 +01:00
if (exits == null) {
return Collections.emptyList();
}
return this.exits;
}
2019-03-04 12:29:26 +01:00
public String getExitsString() {
2018-12-19 08:46:47 +01:00
String exitsString = "";
2018-12-19 13:56:38 +01:00
String refString = "";
2018-12-19 08:46:47 +01:00
if (this.exits != null) {
int i = 1;
2019-03-04 12:29:26 +01:00
exitsString = exitsString + " Exits: [";
for (TransportStopExit e : this.exits) {
2018-12-19 13:56:38 +01:00
if (e.getRef() != null) {
refString = " [ref:" + e.getRef() + "] ";
2018-12-19 08:46:47 +01:00
}
2018-12-19 13:56:38 +01:00
exitsString = exitsString + " " + i + ")" + refString + e.getName() + " " + e.getLocation() + " ]";
i++;
2018-12-19 08:46:47 +01:00
}
}
return exitsString;
}
2019-03-04 12:29:26 +01:00
public boolean compareStop(TransportStop thatObj) {
if (this.compareObject(thatObj) &&
((this.referencesToRoutes == null && thatObj.referencesToRoutes == null) ||
(this.referencesToRoutes != null && thatObj.referencesToRoutes != null && this.referencesToRoutes.length == thatObj.referencesToRoutes.length)) &&
((this.exits == null && thatObj.exits == null) ||
(this.exits != null && thatObj.exits != null && this.exits.size() == thatObj.exits.size()))) {
if (this.exits != null) {
for (int i = 0; i < this.exits.size(); i++) {
if (!this.exits.get(i).compareExit(thatObj.exits.get(i))) {
return false;
}
}
}
} else {
return false;
}
return true;
}
}