Sort transport routes

This commit is contained in:
Victor Shcherb 2018-08-11 16:06:59 +02:00
parent 208b5e9b18
commit fe075102ae
2 changed files with 19 additions and 2 deletions

View file

@ -18,7 +18,7 @@ public interface TransportIndexRepository {
public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
int limit, List<TransportStop> stops, ResultMatcher<TransportStop> matcher); int limit, List<TransportStop> stops, ResultMatcher<TransportStop> matcher);
public Collection<TransportRoute> getRouteForStop(TransportStop stop); public List<TransportRoute> getRouteForStop(TransportStop stop);
} }

View file

@ -1,8 +1,10 @@
package net.osmand.plus.resources; package net.osmand.plus.resources;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -12,6 +14,7 @@ import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource; import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource;
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType; import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -55,10 +58,24 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository
} }
@Override @Override
public synchronized Collection<TransportRoute> getRouteForStop(TransportStop stop){ public synchronized List<TransportRoute> getRouteForStop(TransportStop stop){
try { try {
Collection<TransportRoute> res = getOpenFile().getTransportRoutes(stop.getReferencesToRoutes()).valueCollection(); Collection<TransportRoute> res = getOpenFile().getTransportRoutes(stop.getReferencesToRoutes()).valueCollection();
if(res != null){ if(res != null){
List<TransportRoute> lst = new ArrayList<>(res);
Collections.sort(lst, new Comparator<TransportRoute>() {
@Override
public int compare(TransportRoute o1, TransportRoute o2) {
int i1 = Algorithms.extractFirstIntegerNumber(o1);
int i2 = Algorithms.extractFirstIntegerNumber(o2);
int r = Integer.compare(i1, i2);
if( r == 0){
r = Algorithms.compare(o1.getName(), o2.getName());
}
return r;
}
});
return res; return res;
} }
} catch (IOException e) { } catch (IOException e) {