Use TreeSet to sort Addressbook names

This commit is contained in:
str4d
2013-11-12 02:33:19 +00:00
parent fc618ad9e5
commit d437f45132
2 changed files with 7 additions and 10 deletions

View File

@ -1,6 +1,6 @@
package net.i2p.android.router.loader;
public class AddressEntry implements Comparable<Object> {
public class AddressEntry {
private final String mHostName;
public AddressEntry(String hostName) {
@ -10,10 +10,4 @@ public class AddressEntry implements Comparable<Object> {
public String getHostName() {
return mHostName;
}
public int compareTo(Object another) {
if (another instanceof AddressEntry)
return -1;
return mHostName.compareTo(((AddressEntry) another).getHostName());
}
}

View File

@ -1,8 +1,10 @@
package net.i2p.android.router.loader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import net.i2p.android.router.util.Util;
import net.i2p.client.naming.NamingService;
import net.i2p.router.RouterContext;
@ -29,11 +31,12 @@ public class AddressEntryLoader extends AsyncTaskLoader<List<AddressEntry>> {
Util.i("NamingService: " + ns.getName());
// After router shutdown we get nothing... why?
List<AddressEntry> ret = new ArrayList<AddressEntry>();
for (String hostName : ns.getNames()) {
Set<String> names = new TreeSet<String>();
names.addAll(ns.getNames());
for (String hostName : names) {
AddressEntry name = new AddressEntry(hostName);
ret.add(name);
}
Collections.sort(ret);
return ret;
}