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,
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;
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) {