<commit_before>package com.novoda.downloadmanager.lib;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

public class BatchStartingService {
    private final ContentResolver resolver;
    private Uri batchesUri;

    public BatchStartingService(ContentResolver resolver, DownloadsUriProvider downloadsUriProvider) {
        this.resolver = resolver;
        this.batchesUri = downloadsUriProvider.getBatchesUri();
    }

    public boolean isBatchStartingForTheFirstTime(long batchId) {

        String[] projection = {DownloadContract.Batches.COLUMN_HAS_STARTED};

        Cursor cursor = resolver.query(
                ContentUris.withAppendedId(batchesUri, batchId),
                projection,
                null,
                null,
                null
        );
        if (cursor == null) {
            throw new RuntimeException("Failed to query for batch with batchId = " + batchId);
        }

        try {
            int hasStarted = DownloadContract.Batches.BATCH_HAS_NOT_STARTED;

            if (cursor.moveToFirst()) {
                hasStarted = Cursors.getInt(cursor, DownloadContract.Batches.COLUMN_HAS_STARTED);
            }

            return hasStarted != DownloadContract.Batches.BATCH_HAS_STARTED;
        } finally {
            cursor.close();
        }
    }

    public void markMatchAsStarted(long batchId) {
        ContentValues values = new ContentValues(1);
        values.put(DownloadContract.Batches.COLUMN_HAS_STARTED, DownloadContract.Batches.BATCH_HAS_STARTED);
        resolver.update(ContentUris.withAppendedId(batchesUri, batchId), values, null, null);
    }
}<commit_msg>extracted methods for BatchStartingService<commit_after>package com.novoda.downloadmanager.lib;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

public class BatchStartingService {
    private final ContentResolver resolver;
    private Uri batchesUri;

    public BatchStartingService(ContentResolver resolver, DownloadsUriProvider downloadsUriProvider) {
        this.resolver = resolver;
        this.batchesUri = downloadsUriProvider.getBatchesUri();
    }

    public boolean isBatchStartingForTheFirstTime(long batchId) {
        Cursor cursor = queryForBatch(batchId);

        try {
            return batchHasNotAlreadyStarted(cursor);
        } finally {
            cursor.close();
        }
    }

    private Cursor queryForBatch(long batchId) {
        String[] projection = {DownloadContract.Batches.COLUMN_HAS_STARTED};

        Cursor cursor = resolver.query(
                ContentUris.withAppendedId(batchesUri, batchId),
                projection,
                null,
                null,
                null
        );

        if (cursor == null) {
            throw new RuntimeException("Failed to query for batch with batchId = " + batchId);
        }

        return cursor;
    }

    private boolean batchHasNotAlreadyStarted(Cursor cursor) {
        int hasStarted = DownloadContract.Batches.BATCH_HAS_NOT_STARTED;

        if (cursor.moveToFirst()) {
            hasStarted = Cursors.getInt(cursor, DownloadContract.Batches.COLUMN_HAS_STARTED);
        }

        return hasStarted != DownloadContract.Batches.BATCH_HAS_STARTED;
    }

    public void markMatchAsStarted(long batchId) {
        ContentValues values = new ContentValues(1);
        values.put(DownloadContract.Batches.COLUMN_HAS_STARTED, DownloadContract.Batches.BATCH_HAS_STARTED);
        resolver.update(ContentUris.withAppendedId(batchesUri, batchId), values, null, null);
    }
}
{'fraction_non_alphanumeric': 0.077762982689747, 'fraction_numerical': 0.0005326231691078562, 'mean_word_length': 2.8131979695431473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5015064', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1000, 'n_words': 196}