Update favs

This commit is contained in:
Victor Shcherb 2015-06-08 22:54:12 +02:00
parent ddae62466c
commit afef7a56f1
2 changed files with 33 additions and 8 deletions

View file

@ -138,6 +138,24 @@ public class Algorithms {
return i;
}
public static int extractIntegerNumber(String s) {
int i = 0;
int k = 0;
for (k = 0; k < s.length(); k++) {
if (Character.isDigit(s.charAt(k))) {
break;
}
}
for (; k < s.length(); k++) {
if (Character.isDigit(s.charAt(k))) {
i = i * 10 + (s.charAt(k) - '0');
} else {
break;
}
}
return i;
}
public static String extractIntegerPrefix(String s) {
int k = 0;
for (; k < s.length(); k++) {

View file

@ -452,14 +452,26 @@ public class FavouritesDbHelper {
return collator.compare(lhs.name, rhs.name);
}
});
Comparator<FavouritePoint> favoritesComparator = getComparator();
for (FavoriteGroup g : favoriteGroups) {
Collections.sort(g.points, favoritesComparator);
}
if (cachedFavoritePoints != null) {
Collections.sort(cachedFavoritePoints, favoritesComparator);
}
}
public static Comparator<FavouritePoint> getComparator() {
final Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
Comparator<FavouritePoint> favoritesComparator = new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint o1, FavouritePoint o2) {
String s1 = o1.getName();
String s2 = o2.getName();
int i1 = Algorithms.extractFirstIntegerNumber(s1);
int i2 = Algorithms.extractFirstIntegerNumber(s2);
int i1 = Algorithms.extractIntegerNumber(s1);
int i2 = Algorithms.extractIntegerNumber(s2);
if(i1 == i2) {
String ot1 = Algorithms.extractIntegerPrefix(s1);
String ot2 = Algorithms.extractIntegerPrefix(s2);
@ -469,12 +481,7 @@ public class FavouritesDbHelper {
return i1 - i2;
}
};
for (FavoriteGroup g : favoriteGroups) {
Collections.sort(g.points, favoritesComparator);
}
if (cachedFavoritePoints != null) {
Collections.sort(cachedFavoritePoints, favoritesComparator);
}
return favoritesComparator;
}