From 8d9c3c05341a5cd4f1879df692453d1327ea6a96 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 25 Jan 2015 12:36:00 +0100 Subject: lift language level to java 7, and some code cleanup --- .../keychain/util/ContactHelper.java | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 4ce7a1bac..11b29f521 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -73,20 +73,20 @@ public class ContactHelper { ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?"; public static final String ID_SELECTION = ContactsContract.RawContacts._ID + "=?"; - private static final Map photoCache = new HashMap(); + private static final Map photoCache = new HashMap<>(); public static List getPossibleUserEmails(Context context) { Set accountMails = getAccountEmails(context); accountMails.addAll(getMainProfileContactEmails(context)); // now return the Set (without duplicates) as a List - return new ArrayList(accountMails); + return new ArrayList<>(accountMails); } public static List getPossibleUserNames(Context context) { Set accountMails = getAccountEmails(context); Set names = getContactNamesFromEmails(context, accountMails); names.addAll(getMainProfileContactName(context)); - return new ArrayList(names); + return new ArrayList<>(names); } /** @@ -97,7 +97,7 @@ public class ContactHelper { */ private static Set getAccountEmails(Context context) { final Account[] accounts = AccountManager.get(context).getAccounts(); - final Set emailSet = new HashSet(); + final Set emailSet = new HashSet<>(); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emailSet.add(account.name); @@ -116,7 +116,7 @@ public class ContactHelper { */ private static Set getContactNamesFromEmails(Context context, Set emails) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - Set names = new HashSet(); + Set names = new HashSet<>(); for (String email : emails) { ContentResolver resolver = context.getContentResolver(); Cursor profileCursor = resolver.query( @@ -128,7 +128,7 @@ public class ContactHelper { ); if (profileCursor == null) return null; - Set currNames = new HashSet(); + Set currNames = new HashSet<>(); while (profileCursor.moveToNext()) { String name = profileCursor.getString(1); if (name != null) { @@ -140,7 +140,7 @@ public class ContactHelper { } return names; } else { - return new HashSet(); + return new HashSet<>(); } } @@ -172,7 +172,7 @@ public class ContactHelper { ); if (profileCursor == null) return null; - Set emails = new HashSet(); + Set emails = new HashSet<>(); while (profileCursor.moveToNext()) { String email = profileCursor.getString(0); if (email != null) { @@ -182,7 +182,7 @@ public class ContactHelper { profileCursor.close(); return emails; } else { - return new HashSet(); + return new HashSet<>(); } } @@ -201,7 +201,7 @@ public class ContactHelper { null, null, null); if (profileCursor == null) return null; - Set names = new HashSet(); + Set names = new HashSet<>(); // should only contain one entry! while (profileCursor.moveToNext()) { String name = profileCursor.getString(0); @@ -210,9 +210,9 @@ public class ContactHelper { } } profileCursor.close(); - return new ArrayList(names); + return new ArrayList<>(names); } else { - return new ArrayList(); + return new ArrayList<>(); } } @@ -221,9 +221,9 @@ public class ContactHelper { Cursor mailCursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Email.DATA}, null, null, null); - if (mailCursor == null) return new ArrayList(); + if (mailCursor == null) return new ArrayList<>(); - Set mails = new HashSet(); + Set mails = new HashSet<>(); while (mailCursor.moveToNext()) { String email = mailCursor.getString(0); if (email != null) { @@ -231,7 +231,7 @@ public class ContactHelper { } } mailCursor.close(); - return new ArrayList(mails); + return new ArrayList<>(mails); } public static List getContactNames(Context context) { @@ -239,9 +239,9 @@ public class ContactHelper { Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI, new String[]{ContactsContract.Contacts.DISPLAY_NAME}, null, null, null); - if (cursor == null) return new ArrayList(); + if (cursor == null) return new ArrayList<>(); - Set names = new HashSet(); + Set names = new HashSet<>(); while (cursor.moveToNext()) { String name = cursor.getString(0); if (name != null) { @@ -249,7 +249,7 @@ public class ContactHelper { } } cursor.close(); - return new ArrayList(names); + return new ArrayList<>(names); } @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @@ -309,7 +309,7 @@ public class ContactHelper { boolean isExpired = !cursor.isNull(4) && new Date(cursor.getLong(4) * 1000).before(new Date()); boolean isRevoked = cursor.getInt(5) > 0; int rawContactId = findRawContactId(resolver, fingerprint); - ArrayList ops = new ArrayList(); + ArrayList ops = new ArrayList<>(); // Do not store expired or revoked keys in contact db - and remove them if they already exist if (isExpired || isRevoked) { @@ -351,7 +351,7 @@ public class ContactHelper { * @return a set of all key fingerprints currently present in the contact db */ private static Set getRawContactFingerprints(ContentResolver resolver) { - HashSet result = new HashSet(); + HashSet result = new HashSet<>(); Cursor fingerprints = resolver.query(ContactsContract.RawContacts.CONTENT_URI, SOURCE_ID_PROJECTION, ACCOUNT_TYPE_SELECTION, new String[]{Constants.ACCOUNT_TYPE}, null); if (fingerprints != null) { -- cgit v1.2.3