forked from upstream-mirrors/OpenTracks
Cleaned up ContentProviderUtils's factory pattern.
This commit is contained in:
@@ -353,45 +353,14 @@ public interface ContentProviderUtils {
|
|||||||
/**
|
/**
|
||||||
* A factory which can produce instances of {@link ContentProviderUtils}, and can be overridden for testing.
|
* A factory which can produce instances of {@link ContentProviderUtils}, and can be overridden for testing.
|
||||||
*/
|
*/
|
||||||
//TODO Is this still used? From a quick glance, it doesn't looks like it; probably a left over from testing.
|
|
||||||
@Deprecated
|
|
||||||
class Factory {
|
class Factory {
|
||||||
|
|
||||||
private static Factory instance = new Factory();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of {@link ContentProviderUtils}.
|
* Creates an instance of {@link ContentProviderUtils}.
|
||||||
*
|
*
|
||||||
* @param context the context
|
* @param context the context
|
||||||
*/
|
*/
|
||||||
public static ContentProviderUtils get(Context context) {
|
public static ContentProviderUtils get(Context context) {
|
||||||
return instance.newForContext(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the factory instance.
|
|
||||||
*/
|
|
||||||
public static Factory getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrides the factory instance for testing.
|
|
||||||
* Don't forget to set it back to the original value after testing.
|
|
||||||
*
|
|
||||||
* @param factory the factory
|
|
||||||
*/
|
|
||||||
public static void overrideInstance(Factory factory) {
|
|
||||||
instance = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of {@link ContentProviderUtils}. Allows subclasses
|
|
||||||
* to override for testing.
|
|
||||||
*
|
|
||||||
* @param context the context
|
|
||||||
*/
|
|
||||||
private ContentProviderUtils newForContext(Context context) {
|
|
||||||
return new ContentProviderUtilsImpl(context.getContentResolver());
|
return new ContentProviderUtilsImpl(context.getContentResolver());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user