Use TreeSet to sort Addressbook names
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
package net.i2p.android.router.loader;
|
package net.i2p.android.router.loader;
|
||||||
|
|
||||||
public class AddressEntry implements Comparable<Object> {
|
public class AddressEntry {
|
||||||
private final String mHostName;
|
private final String mHostName;
|
||||||
|
|
||||||
public AddressEntry(String hostName) {
|
public AddressEntry(String hostName) {
|
||||||
@ -10,10 +10,4 @@ public class AddressEntry implements Comparable<Object> {
|
|||||||
public String getHostName() {
|
public String getHostName() {
|
||||||
return mHostName;
|
return mHostName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Object another) {
|
|
||||||
if (another instanceof AddressEntry)
|
|
||||||
return -1;
|
|
||||||
return mHostName.compareTo(((AddressEntry) another).getHostName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package net.i2p.android.router.loader;
|
package net.i2p.android.router.loader;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import net.i2p.android.router.util.Util;
|
import net.i2p.android.router.util.Util;
|
||||||
import net.i2p.client.naming.NamingService;
|
import net.i2p.client.naming.NamingService;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
@ -29,11 +31,12 @@ public class AddressEntryLoader extends AsyncTaskLoader<List<AddressEntry>> {
|
|||||||
Util.i("NamingService: " + ns.getName());
|
Util.i("NamingService: " + ns.getName());
|
||||||
// After router shutdown we get nothing... why?
|
// After router shutdown we get nothing... why?
|
||||||
List<AddressEntry> ret = new ArrayList<AddressEntry>();
|
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);
|
AddressEntry name = new AddressEntry(hostName);
|
||||||
ret.add(name);
|
ret.add(name);
|
||||||
}
|
}
|
||||||
Collections.sort(ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user