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

240 lines
6.4 KiB
Java
Raw Normal View History

package net.osmand.data;
import net.osmand.util.Algorithms;
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;
2019-07-31 20:03:49 +02:00
import java.util.LinkedHashMap;
2018-12-19 08:46:47 +01:00
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-22 15:36:07 +02:00
private long[] deletedRoutesIds;
private long[] routesIds;
public int distance;
public int x31;
public int y31;
2018-12-19 08:46:47 +01:00
private List<TransportStopExit> exits;
private List<TransportRoute> routes = null;
2019-07-31 20:03:49 +02:00
private LinkedHashMap<String, int[]> referencesToRoutesMap;
2019-07-22 15:36:07 +02:00
private TransportStopAggregated transportStopAggregated;
public TransportStop() {}
public List<TransportRoute> getRoutes() {
return routes;
}
2019-07-31 20:03:49 +02:00
public LinkedHashMap<String, int[]> getReferencesToRoutesMap() {
return referencesToRoutesMap;
}
public void putReferencesToRoutes(String repositoryFileName, int[] referencesToRoutes) {
LinkedHashMap<String, int[]> referencesToRoutesMap = this.referencesToRoutesMap;
if (referencesToRoutesMap == null) {
referencesToRoutesMap = new LinkedHashMap<>();
this.referencesToRoutesMap = referencesToRoutesMap;
}
referencesToRoutesMap.put(repositoryFileName, referencesToRoutes);
}
public void setRoutes(List<TransportRoute> routes) {
this.routes = routes;
}
public void addRoute(TransportRoute rt) {
if (this.routes == null) {
this.routes = new ArrayList<TransportRoute>();
}
this.routes.add(rt);
}
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-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) {
// CHECK route ids are sorted (used later)
2019-07-22 15:36:07 +02:00
this.routesIds = routesIds;
}
2019-07-22 15:36:07 +02:00
public boolean hasRoute(long routeId) {
// make assumption that ids are sorted
2019-07-22 15:36:07 +02:00
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 void addRouteId(long routeId) {
// make assumption that ids are sorted
routesIds = Algorithms.addToArrayL(routesIds, routeId, true);
}
public void addDeletedRouteId(long routeId) {
deletedRoutesIds = Algorithms.addToArrayL(deletedRoutesIds, routeId, true);
}
2019-07-22 15:36:07 +02:00
public boolean isRouteDeleted(long routeId) {
return deletedRoutesIds != null && Arrays.binarySearch(deletedRoutesIds, routeId) >= 0;
}
public boolean hasReferencesToRoutes() {
return !isDeleted() && referencesToRoutes != null && referencesToRoutes.length > 0;
}
public boolean hasReferencesToRoutesMap() {
return !isDeleted() && referencesToRoutesMap != null && !referencesToRoutesMap.isEmpty();
}
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) &&
// don't compare routes cause stop could be identical
// ((this.routesIds == null && thatObj.routesIds == null) || (this.routesIds != null && this.routesIds.equals(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) {
2019-07-30 00:11:32 +02:00
if(exit1 == null) {
return false;
}
2019-07-22 16:53:50 +02:00
boolean contains = false;
for (TransportStopExit exit2 : thatObj.exits) {
2019-07-30 00:11:32 +02:00
if (Algorithms.objectEquals(exit1, exit2) ) {
2019-07-22 16:53:50 +02:00
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;
}
}