File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
src/net/cyclestreets/contacts Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 11package net .cyclestreets .contacts ;
22
3+ import java .util .Comparator ;
4+
35public class Contact
46{
57 private final String name_ ;
@@ -22,10 +24,33 @@ public Contact(final String name,
2224 postcode_ = postcode ;
2325 } // Contact
2426
27+ public String name () { return name_ ; }
2528 public String address () { return address_ ; }
2629 public String neighbourhood () { return neighbourhood_ ; }
2730 public String city () { return city_ ; }
2831 public String postcode () { return postcode_ ; }
2932
3033 public String toString () { return name_ ; }
34+
35+ static public Comparator <Contact > comparator ()
36+ {
37+ return ContactsComparator .instance ();
38+ } // Comparator
39+
40+ static private class ContactsComparator implements Comparator <Contact >
41+ {
42+ static private ContactsComparator instance_ ;
43+ static public ContactsComparator instance ()
44+ {
45+ if (instance_ == null )
46+ instance_ = new ContactsComparator ();
47+ return instance_ ;
48+ } // instance
49+
50+ @ Override
51+ public int compare (final Contact lhs , final Contact rhs )
52+ {
53+ return lhs .name ().compareToIgnoreCase (rhs .name ());
54+ } // compare
55+ } // class ContactsComparator
3156} // class Contact
Original file line number Diff line number Diff line change 11package net .cyclestreets .contacts ;
22
33import java .util .ArrayList ;
4+ import java .util .Collections ;
45import java .util .List ;
56
67import android .content .Context ;
@@ -69,6 +70,8 @@ static public List<Contact> fetch(final Context context)
6970 addrCur .close ();
7071 } // finally
7172
73+ Collections .sort (contacts , Contact .comparator ());
74+
7275 return contacts ;
7376 } // queryContacts
7477
You can’t perform that action at this time.
0 commit comments