Sort transport routes
This commit is contained in:
parent
208b5e9b18
commit
fe075102ae
2 changed files with 19 additions and 2 deletions
|
@ -18,7 +18,7 @@ public interface TransportIndexRepository {
|
|||
public void searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
||||
int limit, List<TransportStop> stops, ResultMatcher<TransportStop> matcher);
|
||||
|
||||
public Collection<TransportRoute> getRouteForStop(TransportStop stop);
|
||||
public List<TransportRoute> getRouteForStop(TransportStop stop);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package net.osmand.plus.resources;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -12,6 +14,7 @@ import net.osmand.data.TransportRoute;
|
|||
import net.osmand.data.TransportStop;
|
||||
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource;
|
||||
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -55,10 +58,24 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized Collection<TransportRoute> getRouteForStop(TransportStop stop){
|
||||
public synchronized List<TransportRoute> getRouteForStop(TransportStop stop){
|
||||
try {
|
||||
Collection<TransportRoute> res = getOpenFile().getTransportRoutes(stop.getReferencesToRoutes()).valueCollection();
|
||||
|
||||
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;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in a new issue