2013-04-18 23:35:02 +02:00
|
|
|
package net.osmand.data;
|
|
|
|
|
2019-07-22 16:53:50 +02:00
|
|
|
import net.osmand.util.Algorithms;
|
2018-08-03 12:50:51 +02:00
|
|
|
import net.osmand.util.MapUtils;
|
|
|
|
|
2018-12-19 08:46:47 +01:00
|
|
|
import java.util.ArrayList;
|
2019-07-22 15:36:07 +02:00
|
|
|
import java.util.Arrays;
|
2018-12-19 08:46:47 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
public class TransportStop extends MapObject {
|
2019-03-04 12:29:26 +01:00
|
|
|
|
|
|
|
private static final int DELETED_STOP = -1;
|
|
|
|
|
2018-05-23 09:29:13 +02:00
|
|
|
private int[] referencesToRoutes = null;
|
2019-07-22 15:36:07 +02:00
|
|
|
private long[] deletedRoutesIds;
|
|
|
|
private long[] routesIds;
|
2018-05-23 09:29:13 +02:00
|
|
|
public int distance;
|
2018-08-03 12:50:51 +02:00
|
|
|
public int x31;
|
|
|
|
public int y31;
|
2018-12-19 08:46:47 +01:00
|
|
|
private List<TransportStopExit> exits;
|
2018-05-23 09:29:13 +02:00
|
|
|
|
2019-07-22 15:36:07 +02:00
|
|
|
private TransportStopAggregated transportStopAggregated;
|
|
|
|
|
2019-03-04 12:29:26 +01:00
|
|
|
public TransportStop() {
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
2019-03-04 12:29:26 +01:00
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
public int[] getReferencesToRoutes() {
|
|
|
|
return referencesToRoutes;
|
|
|
|
}
|
2019-03-04 12:29:26 +01:00
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
public void setReferencesToRoutes(int[] referencesToRoutes) {
|
|
|
|
this.referencesToRoutes = referencesToRoutes;
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:36:07 +02:00
|
|
|
public long[] getRoutesIds() {
|
|
|
|
return routesIds;
|
2019-03-04 12:29:26 +01:00
|
|
|
}
|
|
|
|
|
2019-07-22 15:36:07 +02:00
|
|
|
public void setRoutesIds(long[] routesIds) {
|
|
|
|
this.routesIds = routesIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasRoute(long routeId) {
|
|
|
|
return routesIds != null && Arrays.binarySearch(routesIds, routeId) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDeleted() {
|
|
|
|
return referencesToRoutes != null && referencesToRoutes.length == 1 && referencesToRoutes[0] == DELETED_STOP;
|
2019-07-09 17:20:48 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 12:29:26 +01:00
|
|
|
public void setDeleted() {
|
|
|
|
this.referencesToRoutes = new int[] { DELETED_STOP };
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:36:07 +02:00
|
|
|
public long[] getDeletedRoutesIds() {
|
|
|
|
return deletedRoutesIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDeletedRoutesIds(long[] deletedRoutesIds) {
|
|
|
|
this.deletedRoutesIds = deletedRoutesIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRouteDeleted(long routeId) {
|
|
|
|
return deletedRoutesIds != null && Arrays.binarySearch(deletedRoutesIds, routeId) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasReferencesToRoutes() {
|
|
|
|
return !isDeleted() && referencesToRoutes != null && referencesToRoutes.length > 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-08-03 12:50:51 +02: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
|
|
|
|
2019-07-22 16:53:50 +02:00
|
|
|
private boolean areRoutesEquals(long[] r1, long[] r2) {
|
|
|
|
boolean res = (r1 == null && r2 == null);
|
|
|
|
if (!res && r1 != null && r2 != null) {
|
|
|
|
res = true;
|
|
|
|
for (long id : r1) {
|
|
|
|
if (!Algorithms.containsInArrayL(r2, id)) {
|
|
|
|
res = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-03-04 12:29:26 +01:00
|
|
|
public boolean compareStop(TransportStop thatObj) {
|
2019-07-22 16:53:50 +02:00
|
|
|
if (this.compareObject(thatObj) && areRoutesEquals(this.routesIds, thatObj.routesIds) &&
|
2019-07-22 15:36:07 +02:00
|
|
|
((this.exits == null && thatObj.exits == null) || (this.exits != null && thatObj.exits != null && this.exits.size() == thatObj.exits.size()))) {
|
2019-03-04 12:29:26 +01:00
|
|
|
if (this.exits != null) {
|
2019-07-22 16:53:50 +02:00
|
|
|
for (TransportStopExit exit1 : this.exits) {
|
|
|
|
boolean contains = false;
|
|
|
|
for (TransportStopExit exit2 : thatObj.exits) {
|
|
|
|
if (exit1.getId().equals(exit2.getId())) {
|
|
|
|
contains = true;
|
|
|
|
if (!exit1.compareExit(exit2)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!contains) {
|
2019-03-04 12:29:26 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|