<commit_before>package by.istin.android.xcore.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.provider.BaseColumns;

import java.util.ArrayList;
import java.util.List;

import by.istin.android.xcore.provider.ModelContract;

public class ContentUtils {

    public static ContentValues getEntity(Context context, Class<?> entityClass, Long id) {
        Cursor entityCursor = null;
        ContentValues values = null;
        try {
            entityCursor = context.getContentResolver().query(ModelContract.getUri(entityClass, id), null, null, null, null);
            if (!CursorUtils.isEmpty(entityCursor) && entityCursor.moveToFirst()) {
                values = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(entityCursor, values);
            }
        } finally {
            CursorUtils.close(entityCursor);
        }
        return values;
    }

    public static void putEntity(Context context, Class<?> entityClass, ContentValues entity) {
        context.getContentResolver().insert(ModelContract.getUri(entityClass), entity);
    }

    public static void putEntities(Context context, Class<?> entityClass, List<ContentValues> entities) {
        if (entities == null) return;
        putEntities(context, entityClass, entities.toArray(new ContentValues[entities.size()]));
    }

    public static void putEntities(Context context, Class<?> entityClass, ContentValues... entity) {
        context.getContentResolver().bulkInsert(ModelContract.getUri(entityClass), entity);
    }

    public static void removeEntity(Context context, Class<?> entityClass, long id) {
        String where = BaseColumns._ID + "=?";
        removeEntities(context, entityClass, where, String.valueOf(id));
    }

    public static void removeEntities(Context context, Class<?> entityClass, String where, String ... selectionArgs) {
        context.getContentResolver().delete(ModelContract.getUri(entityClass), where, selectionArgs);
    }

    public static ContentValues getEntity(Context context, Class<?> entityClass, String selection, String ... selectionArgs) {
        List<ContentValues> entities = getEntities(context, entityClass, selection, selectionArgs);
        if (entities == null || entities.isEmpty()) {
            return null;
        }
        return entities.get(0);
    }

    public static List<ContentValues> getEntities(Context context, Class<?> entityClass, String selection, String ... selectionArgs) {
        Cursor entityCursor = null;
        List<ContentValues> result = null;
        try {
            entityCursor = context.getContentResolver().query(ModelContract.getUri(entityClass), null, selection, selectionArgs, null);
            if (!CursorUtils.isEmpty(entityCursor) && entityCursor.moveToFirst()) {
                result = new ArrayList<ContentValues>();
                CursorUtils.convertToContentValuesAndClose(entityCursor, result);
            }
        } finally {
            CursorUtils.close(entityCursor);
        }
        return result;
    }
}<commit_msg>added getEntitiesWithOrder method to ContentUtils class<commit_after>package by.istin.android.xcore.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.provider.BaseColumns;

import java.util.ArrayList;
import java.util.List;

import by.istin.android.xcore.provider.ModelContract;

public class ContentUtils {

    public static ContentValues getEntity(Context context, Class<?> entityClass, Long id) {
        Cursor entityCursor = null;
        ContentValues values = null;
        try {
            entityCursor = context.getContentResolver().query(ModelContract.getUri(entityClass, id), null, null, null, null);
            if (!CursorUtils.isEmpty(entityCursor) && entityCursor.moveToFirst()) {
                values = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(entityCursor, values);
            }
        } finally {
            CursorUtils.close(entityCursor);
        }
        return values;
    }

    public static void putEntity(Context context, Class<?> entityClass, ContentValues entity) {
        context.getContentResolver().insert(ModelContract.getUri(entityClass), entity);
    }

    public static void putEntities(Context context, Class<?> entityClass, List<ContentValues> entities) {
        if (entities == null) return;
        putEntities(context, entityClass, entities.toArray(new ContentValues[entities.size()]));
    }

    public static void putEntities(Context context, Class<?> entityClass, ContentValues... entity) {
        context.getContentResolver().bulkInsert(ModelContract.getUri(entityClass), entity);
    }

    public static void removeEntity(Context context, Class<?> entityClass, long id) {
        String where = BaseColumns._ID + "=?";
        removeEntities(context, entityClass, where, String.valueOf(id));
    }

    public static void removeEntities(Context context, Class<?> entityClass, String where, String ... selectionArgs) {
        context.getContentResolver().delete(ModelContract.getUri(entityClass), where, selectionArgs);
    }

    public static ContentValues getEntity(Context context, Class<?> entityClass, String selection, String ... selectionArgs) {
        List<ContentValues> entities = getEntities(context, entityClass, selection, selectionArgs);
        if (entities == null || entities.isEmpty()) {
            return null;
        }
        return entities.get(0);
    }

    public static List<ContentValues> getEntitiesWithOrder(Context context, Class<?> entityClass, String sortOrder, String selection, String... selectionArgs) {
        Cursor entityCursor = null;
        List<ContentValues> result = null;
        try {
            entityCursor = context.getContentResolver().query(ModelContract.getUri(entityClass), null, selection, selectionArgs, sortOrder);
            if (!CursorUtils.isEmpty(entityCursor) && entityCursor.moveToFirst()) {
                result = new ArrayList<ContentValues>();
                CursorUtils.convertToContentValuesAndClose(entityCursor, result);
            }
        } finally {
            CursorUtils.close(entityCursor);
        }
        return result;
    }

    public static List<ContentValues> getEntities(Context context, Class<?> entityClass, String selection, String ... selectionArgs) {
        return getEntitiesWithOrder(context, entityClass, null, selection, selectionArgs);
    }
}
{'fraction_non_alphanumeric': 0.10235863320229815, 'fraction_numerical': 0.0003023888720895071, 'mean_word_length': 3.3721083939193655, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2280353', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1623, 'n_words': 396}