package com.salvadordalvik.fastlibrary.data;

import android.database.Cursor;
import android.os.AsyncTask;

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

/**
 * FastLib
 * Created by Matthew Shepard on 11/25/13.
 */
public class FastQueryTask<T> extends AsyncTask<String, Void, Cursor> {
    private final QueryResultCallback<T> callback;
    private final FastDatabase database;

    public interface QueryResultCallback<T>{
        public void queryResult(List<T> results);
        public T createItem(Cursor data);
    }

    public FastQueryTask(FastDatabase db, QueryResultCallback<T> callback) {
        this.callback = callback;
        this.database = db;
    }

    @Override
    protected Cursor doInBackground(String... params) {
        return database.query(params);
    }

    @Override
    protected void onPostExecute(Cursor cursor) {
        super.onPostExecute(cursor);
        callback.queryResult(createList(cursor));
        cursor.close();
    }

    protected List<T> createList(Cursor data){
        ArrayList<T> items = new ArrayList<T>();
        if(data != null && !data.isClosed() && data.moveToFirst()){
            do{
                items.add(callback.createItem(data));
            }while (data.moveToNext());
        }
        return items;
    }
}

@@ -1279,11 +1279,678 @@
 s;%0A    %7D
+%0A%0A    public void query(String table, String sort)%7B%0A        execute(table, sort);%0A    %7D%0A%0A    public void query(String table, String sort, String where)%7B%0A        execute(table, sort, where);%0A    %7D%0A%0A    public void query(String table, String sort, String where, String... whereargs)%7B%0A        if(whereargs == null)%7B%0A            execute(table, sort, where);%0A        %7Delse%7B%0A            String%5B%5D args = new String%5Bwhereargs.length+3%5D;%0A            args%5B0%5D = table;%0A            args%5B1%5D = sort;%0A            args%5B2%5D = where;%0A            for(int ix=0;ix%3Cwhereargs.length;ix++)%7B%0A                args%5Bix+3%5D = whereargs%5Bix%5D;%0A            %7D%0A            execute(args);%0A        %7D%0A    %7D
 %0A%7D%0A

Add clearer query method to query task.