<commit_before>package com.oasisfeng.pattern;

import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;

/**
 * Local Content Provider Pattern:
 * Self-contained component across the app, as singleton instance for each process.
 *
 * Created by Oasis on 2016/8/20.
 */
@ParametersAreNonnullByDefault
public class LocalContentProvider extends ContentProvider {

	protected static <T extends LocalContentProvider> T getInstance(final Context context, final Class<T> clazz) {
		final ProviderInfo provider = queryProviderInfo(context, clazz);
		if (provider == null) return null;
		return getInstance(context, provider.authority);
	}

	protected static <T extends LocalContentProvider> T getInstance(final Context context, final String authority) {
		final ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(authority);
		if (client == null) throw new IllegalStateException("No active provider associated with authority: " + authority);
		try {
			final ContentProvider provider = client.getLocalContentProvider();
			if (provider == null)
				throw new IllegalStateException("android:multiprocess=\"true\" is required for this provider.");
			if (! (provider instanceof LocalContentProvider))
				throw new IllegalArgumentException("Not a LocalContentProvider associated with authority: " + authority);
			@SuppressWarnings("unchecked") final T casted = (T) provider;
			return casted;
		} finally { //noinspection deprecation
			client.release();<commit_msg>UPDATE: Throwing IllegalStateException instead of returning null in LocalContentProvider.getInstance().<commit_after>package com.oasisfeng.pattern;

import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;

/**
 * Local Content Provider Pattern:
 * Self-contained component across the app, as singleton instance for each process.
 *
 * Created by Oasis on 2016/8/20.
 */
@ParametersAreNonnullByDefault
public class LocalContentProvider extends ContentProvider {

	protected static <T extends LocalContentProvider> T getInstance(final Context context, final Class<T> clazz) {
		final ProviderInfo provider = queryProviderInfo(context, clazz);
		if (provider == null) throw new IllegalStateException(clazz + " not declared in AndroidManifest.xml");
		return getInstance(context, provider.authority);
	}

	protected static <T extends LocalContentProvider> T getInstance(final Context context, final String authority) {
		final ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(authority);
		if (client == null) throw new IllegalStateException("No active provider associated with authority: " + authority);
		try {
			final ContentProvider provider = client.getLocalContentProvider();
			if (provider == null)
				throw new IllegalStateException("android:multiprocess=\"true\" is required for this provider.");
			if (! (provider instanceof LocalContentProvider))
				throw new IllegalArgumentException("Not a LocalContentProvider associated with authority: " + authority);
			@SuppressWarnings("unchecked") final T casted = (T) provider;
			return casted;
		} finally { //noinspection deprecation
			client.release();
{'fraction_non_alphanumeric': 0.08559236947791164, 'fraction_numerical': 0.0035140562248995983, 'mean_word_length': 6.1288014311270125, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5937223', 'n_tokens_mistral': 1031, 'n_tokens_neox': 963, 'n_words': 304}