Search in sources :

Example 1 with DisplayName

use of com.alexstyl.specialdates.contact.DisplayName in project Memento-Calendar by alexstyl.

the class FacebookContactFactory method createContactFrom.

ContactEvent createContactFrom(Map<String, String> map) throws InvalidFacebookContactException {
    try {
        Date date = dateFrom(map);
        DisplayName name = nameFrom(map);
        long uid = idOf(map);
        URI imagePath = FacebookImagePath.INSTANCE.forUid(uid);
        return new ContactEvent(Optional.Companion.<Long>absent(), StandardEventType.BIRTHDAY, date, new Contact(uid, name, imagePath, SOURCE_FACEBOOK));
    } catch (DateParseException | IndexOutOfBoundsException ex) {
        throw new InvalidFacebookContactException(ex);
    }
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) DateParseException(com.alexstyl.specialdates.date.DateParseException) DisplayName(com.alexstyl.specialdates.contact.DisplayName) URI(java.net.URI) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact)

Example 2 with DisplayName

use of com.alexstyl.specialdates.contact.DisplayName in project Memento-Calendar by alexstyl.

the class ContactsSearch method searchForContacts.

List<Contact> searchForContacts(String searchQuery, int numberOfResults) {
    List<Contact> matchedContacts = new ArrayList<>();
    if (numberOfResults == 0) {
        return matchedContacts;
    }
    searchQuery = searchQuery.trim();
    List<Contact> allContacts = contactsProvider.getAllContacts();
    if (allContacts.size() == 0) {
        return matchedContacts;
    }
    int count = 0;
    int index = 0;
    int contactSize = allContacts.size();
    do {
        Contact contact = allContacts.get(index);
        DisplayName displayName = contact.getDisplayName();
        if (nameMatcher.match(displayName, searchQuery)) {
            matchedContacts.add(contact);
            count++;
        }
        index++;
    } while (count < numberOfResults && index < contactSize);
    return matchedContacts;
}
Also used : ArrayList(java.util.ArrayList) DisplayName(com.alexstyl.specialdates.contact.DisplayName) Contact(com.alexstyl.specialdates.contact.Contact)

Aggregations

Contact (com.alexstyl.specialdates.contact.Contact)2 DisplayName (com.alexstyl.specialdates.contact.DisplayName)2 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)1 Date (com.alexstyl.specialdates.date.Date)1 DateParseException (com.alexstyl.specialdates.date.DateParseException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1