Source:
<code>static Map<String, ContactData> loadContactsFromTelephoneBook(final Context context, final String mySimlarId) { Lg.i("loading contacts from telephone book"); final Map<String, ContactData> result = new HashMap<>(); final String[] projection = { ContactsContract.CommonDataKinds.Phone.CONTACT_ID, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY, ContactsContract.CommonDataKinds.Phone.PHOTO_ID }; final Cursor contacts = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, null, null, null); if (contacts == null) { Lg.e("contacts cursor null"); return result; } while (contacts.moveToNext()) { final long contactId = contacts.getLong(0); final String number = contacts.getString(1); final String name = contacts.getString(2); final boolean hasPhotoId = contacts.getLong(3) != 0; if (Util.isNullOrEmpty(number)) { continue; } final SimlarNumber simlarNumber = new SimlarNumber(number); final String simlarId = simlarNumber.getSimlarId(); if (Util.isNullOrEmpty(simlarId)) { continue; } if (Util.equalString(simlarId, mySimlarId)) { continue; } <START> String photoUri = null; <END> if (hasPhotoId) { photoUri = Uri.withAppendedPath(ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, contactId), ContactsContract.Contacts.Photo.CONTENT_DIRECTORY).toString(); } if (!result.containsKey(simlarId) || Util.isNullOrEmpty(result.get(simlarId).name)) { result.put(simlarId, new ContactData(Util.equalString(name, number) ? "" : name, simlarNumber.getGuiTelephoneNumber(), ContactStatus.UNKNOWN, photoUri)); } } contacts.close(); Lg.i("found ", result.size(), " contacts from telephone book"); return result; }</code><technical_language>do ternary operator, here, too. Besides, Uri.EMPTY instead of null more null-safe</technical_language>

Target:
static Map<String, ContactData> loadContactsFromTelephoneBook(final Context context, final String mySimlarId) { Lg.i("loading contacts from telephone book"); final Map<String, ContactData> result = new HashMap<>(); final String[] projection = { ContactsContract.CommonDataKinds.Phone.CONTACT_ID, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.SORT_KEY_PRIMARY, ContactsContract.CommonDataKinds.Phone.PHOTO_ID }; final Cursor contacts = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, null, null, null); if (contacts == null) { Lg.e("contacts cursor null"); return result; } while (contacts.moveToNext()) { final long contactId = contacts.getLong(0); final String number = contacts.getString(1); final String name = contacts.getString(2); final boolean hasPhotoId = contacts.getLong(3) != 0; if (Util.isNullOrEmpty(number)) { continue; } final SimlarNumber simlarNumber = new SimlarNumber(number); final String simlarId = simlarNumber.getSimlarId(); if (Util.isNullOrEmpty(simlarId)) { continue; } if (Util.equalString(simlarId, mySimlarId)) { continue; } final String photoUri = hasPhotoId ? Uri.withAppendedPath(ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId), ContactsContract.Contacts.Photo.CONTENT_DIRECTORY).toString() : null; if (!result.containsKey(simlarId) || Util.isNullOrEmpty(result.get(simlarId).name)) { result.put(simlarId, new ContactData(Util.equalString(name, number) ? "" : name, simlarNumber.getGuiTelephoneNumber(), ContactStatus.UNKNOWN, photoUri)); } } contacts.close(); Lg.i("found ", result.size(), " contacts from telephone book"); return result; }