package com.alexstyl.specialdates.contact;

import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.ContactsContract;

import com.alexstyl.specialdates.DisplayName;

class DeviceContactFactory {

    private final ContentResolver resolver;

    DeviceContactFactory(ContentResolver contentResolver) {
        resolver = contentResolver;
    }

    DeviceContact createContactWithId(long contactID) throws ContactNotFoundException {
        String selection = ContactsContract.Data.CONTACT_ID + " = " + contactID + " AND " + ContactsContract.Data.MIMETYPE + " = ?";

        Cursor cursor = resolver.query(ContactsQuery.CONTENT_URI, ContactsQuery.PROJECTION, selection, new String[]{
                ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
        }, ContactsQuery.SORT_ORDER + " LIMIT 1");
        if (isInvalid(cursor)) {
            throw new RuntimeException("Cursor was invalid");
        }

        try {
            if (cursor.moveToFirst()) {
                DisplayName displayName = getDisplayNameFrom(cursor);
                String lookupKey = getLookupKeyFrom(cursor);
                return new DeviceContact(contactID, displayName, lookupKey);
            }
        } finally {
            cursor.close();
        }
        throw new ContactNotFoundException(contactID);
    }

    private boolean isInvalid(Cursor cursor) {
        return cursor == null || cursor.isClosed();
    }

    private String getLookupKeyFrom(Cursor cursor) {
        return cursor.getString(ContactsQuery.LOOKUP_KEY);
    }

    private DisplayName getDisplayNameFrom(Cursor cursor) {
        return DisplayName.from(cursor.getString(ContactsQuery.DISPLAY_NAME));
    }

}

@@ -1363,16 +1363,23 @@
 private 
+static 
 boolean 
@@ -1480,27 +1480,41 @@
 ate 
-String getLookupKey
+static DisplayName getDisplayName
 From
@@ -1542,24 +1542,41 @@
      return 
+DisplayName.from(
 cursor.getSt
@@ -1598,18 +1598,21 @@
 ery.
-LOOKUP_KEY
+DISPLAY_NAME)
 );%0A 
@@ -1633,34 +1633,34 @@
 ate 
-DisplayName getDisplayName
+static String getLookupKey
 From
@@ -1692,33 +1692,16 @@
  return 
-DisplayName.from(
 cursor.g
@@ -1719,37 +1719,34 @@
 ntactsQuery.
-DISPLAY_NAME)
+LOOKUP_KEY
 );%0A    %7D%0A%0A%7D%0A

Set methods that don't use any fields as static