@Test public void testFilterContactsByName() throws Exception { List<Contact> filteredContacts = contactService.filterContactsByContent("Alice",false); assertThat(filteredContacts.size()).isEqualTo(2); }
@Override public List<Contact> filterContactsByContent(String query, boolean excludeNotPayable) { Preconditions.checkNotNull(query, "'query' must be present. Use * for wildcard."); String lowerQuery = query.toLowerCase(); List<Contact> filteredContacts = Lists.newArrayList(); for (Contact contact : contacts) { if (excludeNotPayable && !contact.getBitcoinAddress().isPresent() ) { continue; } final boolean isNameMatched; final boolean isEmailMatched; final boolean isNoteMatched; if ("*".equals(query)) { isNameMatched = true; isEmailMatched = true; isNoteMatched = true; } else { isNameMatched = contact.getName().toLowerCase().contains(lowerQuery); isEmailMatched = contact.getEmail().or("").toLowerCase().contains(lowerQuery); isNoteMatched = contact.getNotes().or("").toLowerCase().contains(lowerQuery); } boolean isTagMatched = false; for (String tag : contact.getTags()) { if (tag.toLowerCase().contains(lowerQuery)) { isTagMatched = true; break; } } if (isNameMatched || isEmailMatched || isNoteMatched || isTagMatched ) { filteredContacts.add(contact); } } return filteredContacts; }
PersistentContactService extends AbstractService implements ContactService { @Override public List<Contact> filterContactsByContent(String query, boolean excludeNotPayable) { Preconditions.checkNotNull(query, "'query' must be present. Use * for wildcard."); String lowerQuery = query.toLowerCase(); List<Contact> filteredContacts = Lists.newArrayList(); for (Contact contact : contacts) { if (excludeNotPayable && !contact.getBitcoinAddress().isPresent() ) { continue; } final boolean isNameMatched; final boolean isEmailMatched; final boolean isNoteMatched; if ("*".equals(query)) { isNameMatched = true; isEmailMatched = true; isNoteMatched = true; } else { isNameMatched = contact.getName().toLowerCase().contains(lowerQuery); isEmailMatched = contact.getEmail().or("").toLowerCase().contains(lowerQuery); isNoteMatched = contact.getNotes().or("").toLowerCase().contains(lowerQuery); } boolean isTagMatched = false; for (String tag : contact.getTags()) { if (tag.toLowerCase().contains(lowerQuery)) { isTagMatched = true; break; } } if (isNameMatched || isEmailMatched || isNoteMatched || isTagMatched ) { filteredContacts.add(contact); } } return filteredContacts; } }
PersistentContactService extends AbstractService implements ContactService { @Override public List<Contact> filterContactsByContent(String query, boolean excludeNotPayable) { Preconditions.checkNotNull(query, "'query' must be present. Use * for wildcard."); String lowerQuery = query.toLowerCase(); List<Contact> filteredContacts = Lists.newArrayList(); for (Contact contact : contacts) { if (excludeNotPayable && !contact.getBitcoinAddress().isPresent() ) { continue; } final boolean isNameMatched; final boolean isEmailMatched; final boolean isNoteMatched; if ("*".equals(query)) { isNameMatched = true; isEmailMatched = true; isNoteMatched = true; } else { isNameMatched = contact.getName().toLowerCase().contains(lowerQuery); isEmailMatched = contact.getEmail().or("").toLowerCase().contains(lowerQuery); isNoteMatched = contact.getNotes().or("").toLowerCase().contains(lowerQuery); } boolean isTagMatched = false; for (String tag : contact.getTags()) { if (tag.toLowerCase().contains(lowerQuery)) { isTagMatched = true; break; } } if (isNameMatched || isEmailMatched || isNoteMatched || isTagMatched ) { filteredContacts.add(contact); } } return filteredContacts; } PersistentContactService(WalletPassword walletPassword);   PersistentContactService(EncryptedContactsFile backingStoreFile, CharSequence password); }
PersistentContactService extends AbstractService implements ContactService { @Override public List<Contact> filterContactsByContent(String query, boolean excludeNotPayable) { Preconditions.checkNotNull(query, "'query' must be present. Use * for wildcard."); String lowerQuery = query.toLowerCase(); List<Contact> filteredContacts = Lists.newArrayList(); for (Contact contact : contacts) { if (excludeNotPayable && !contact.getBitcoinAddress().isPresent() ) { continue; } final boolean isNameMatched; final boolean isEmailMatched; final boolean isNoteMatched; if ("*".equals(query)) { isNameMatched = true; isEmailMatched = true; isNoteMatched = true; } else { isNameMatched = contact.getName().toLowerCase().contains(lowerQuery); isEmailMatched = contact.getEmail().or("").toLowerCase().contains(lowerQuery); isNoteMatched = contact.getNotes().or("").toLowerCase().contains(lowerQuery); } boolean isTagMatched = false; for (String tag : contact.getTags()) { if (tag.toLowerCase().contains(lowerQuery)) { isTagMatched = true; break; } } if (isNameMatched || isEmailMatched || isNoteMatched || isTagMatched ) { filteredContacts.add(contact); } } return filteredContacts; } PersistentContactService(WalletPassword walletPassword);   PersistentContactService(EncryptedContactsFile backingStoreFile, CharSequence password); @Override Contact newContact(String name); @Override List<Contact> allContacts(); @Override List<Contact> filterContactsByBitcoinAddress(Address address); @Override List<Contact> filterContactsByContent(String query, boolean excludeNotPayable); @Override Optional<Contact> filterContactsForSingleMatch(String query, boolean excludeNotPayable); @Override void addAll(Collection<Contact> selectedContacts); @Override void loadContacts(CharSequence password); @Override void removeAll(Collection<Contact> selectedContacts); @Override void updateContacts(Collection<Contact> editedContacts); @Override void writeContacts(); @Override void addDemoContacts(); }
PersistentContactService extends AbstractService implements ContactService { @Override public List<Contact> filterContactsByContent(String query, boolean excludeNotPayable) { Preconditions.checkNotNull(query, "'query' must be present. Use * for wildcard."); String lowerQuery = query.toLowerCase(); List<Contact> filteredContacts = Lists.newArrayList(); for (Contact contact : contacts) { if (excludeNotPayable && !contact.getBitcoinAddress().isPresent() ) { continue; } final boolean isNameMatched; final boolean isEmailMatched; final boolean isNoteMatched; if ("*".equals(query)) { isNameMatched = true; isEmailMatched = true; isNoteMatched = true; } else { isNameMatched = contact.getName().toLowerCase().contains(lowerQuery); isEmailMatched = contact.getEmail().or("").toLowerCase().contains(lowerQuery); isNoteMatched = contact.getNotes().or("").toLowerCase().contains(lowerQuery); } boolean isTagMatched = false; for (String tag : contact.getTags()) { if (tag.toLowerCase().contains(lowerQuery)) { isTagMatched = true; break; } } if (isNameMatched || isEmailMatched || isNoteMatched || isTagMatched ) { filteredContacts.add(contact); } } return filteredContacts; } PersistentContactService(WalletPassword walletPassword);   PersistentContactService(EncryptedContactsFile backingStoreFile, CharSequence password); @Override Contact newContact(String name); @Override List<Contact> allContacts(); @Override List<Contact> filterContactsByBitcoinAddress(Address address); @Override List<Contact> filterContactsByContent(String query, boolean excludeNotPayable); @Override Optional<Contact> filterContactsForSingleMatch(String query, boolean excludeNotPayable); @Override void addAll(Collection<Contact> selectedContacts); @Override void loadContacts(CharSequence password); @Override void removeAll(Collection<Contact> selectedContacts); @Override void updateContacts(Collection<Contact> editedContacts); @Override void writeContacts(); @Override void addDemoContacts();  }