Search in sources :

Example 1 with HashMapList

use of com.alexstyl.specialdates.util.HashMapList in project Memento-Calendar by alexstyl.

the class PeopleEventsSearch method searchForContacts.

List<ContactWithEvents> searchForContacts(String searchQuery, int counter) {
    if (counter <= 0) {
        return new ArrayList<>();
    }
    searchQuery = searchQuery.trim();
    HashMapList<Contact, ContactEvent> events = new HashMapList<>();
    TimePeriod between = TimePeriod.Companion.aYearFromNow();
    List<ContactEvent> contactEventsOnDate = peopleEventsProvider.fetchEventsBetween(between);
    int size = 0;
    for (ContactEvent contactEvent : contactEventsOnDate) {
        Contact contact = contactEvent.getContact();
        if (nameMatcher.match(contact.getDisplayName(), searchQuery)) {
            events.addValue(contact, contactEvent);
            size++;
        }
        if (size >= counter) {
            break;
        }
    }
    List<ContactWithEvents> contactWithEvents = new ArrayList<>();
    for (Contact contact : events.keys()) {
        List<ContactEvent> list = events.get(contact);
        contactWithEvents.add(new ContactWithEvents(contact, list));
    }
    return contactWithEvents;
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) TimePeriod(com.alexstyl.specialdates.date.TimePeriod) ArrayList(java.util.ArrayList) HashMapList(com.alexstyl.specialdates.util.HashMapList) Contact(com.alexstyl.specialdates.contact.Contact)

Aggregations

Contact (com.alexstyl.specialdates.contact.Contact)1 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)1 TimePeriod (com.alexstyl.specialdates.date.TimePeriod)1 HashMapList (com.alexstyl.specialdates.util.HashMapList)1 ArrayList (java.util.ArrayList)1