<commit_before>package todomore.android;

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

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import com.darwinsys.todo.model.Priority;
import com.darwinsys.todo.model.Task;

import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;

/** 
 * This class encapsulates various make-work functions that 
 * WOULD NOT BE NEEDED IF ANDROID'S API WERE OBJECT ORIENTED!
 * @author <NAME>
 */
public class GruntWork {
	
	private final static String TAG = "GruntWork";
	

	public static ContentValues taskToContentValuesWithout_ID(Task t) {
		return taskToContentValues(t, false);
	}

	public static ContentValues taskToContentValues(Task t) {
		return taskToContentValues(t, true);
	}
	
	private static ContentValues taskToContentValues(Task t, boolean include_ID) {
		ContentValues cv = new ContentValues();
		cv.put("id", t.getId());
		if (include_ID && t instanceof AndroidTask) {
			cv.put("_id", ((AndroidTask)t)._id);
		}
		cv.put("name", t.getName());
		cv.put("priority", t.getPriority().ordinal());
//		Date creationDate = new Date(); // when you decided you had to do it
//		Project project;	// what this task is part of
//		Context context;	// where to do it
//		Date dueDate;		// when to do it by
//		Status status;
//		Date completedDate = null; // when you actually did it
		cv.put("modified", t.getModified());
//		String description;
		return cv;
	}
 
	public static Task cursorToTask(Cursor c) {
		if (c.isAfterLast()) {
			Log.d(TAG, "Cursor has no more rows");
			return null;
		}
		AndroidTask t = new AndroidTask();
		t._id = c.getInt(1);
		t.setName(c.getString(c.getColumnIndex("name")));
		t.setPriority(Priority.values()[(c.getColumnIndex("priority"))]);
		t.setModified(c.getLong(c.getColumnIndex("modified")));
		return t;
	}
	
	public static List<Task> cursorToTaskList(Cursor c) {
		List<Task> list = new ArrayList<>();
		while (c.moveToNext()) {
			list.add(cursorToTask(c));
		}
		return list;
		}

	/**
	 * Convert JSON goo like this:
	 * [{"id":102,"priority":"High","name":"TEST 2",
	 * "creationDate":{"year":2015,"month":11,"day":1},
	 * "project":null,"context":{"id":100,"name":"Life"},
	 * "dueDate":null,"status":"ACTIVE","completedDate":null,
	 * "modified":1448292432791,"description":"None","complete":false},
	 * {"id":103,"priority":"Low","name":"Low prio item",
	 * "creationDate":{"year":2015,"month":10,"day":23},"project":null,
	 * "context":{"id":80,"name":"Home"},"dueDate":null,"status":"NEW",
	 * "completedDate":null,"modified":1448312330383,
	 * "description":"","complete":false}]
	 * into a proper List<Task>.
	 */
	public static List<Task> jsonStringToListTask(String resultStr) {
		List<Task> ret = new ArrayList<>();
		try {
			JSONArray array = (JSONArray) new JSONTokener(resultStr).nextValue();
			for (int i = 0; i < array.length(); i++) {
				JSONObject o = array.getJSONObject(i);
				Task t = new Task();
				t.setId(o.getLong("id"));
				t.setPriority(Priority.valueOf(o.getString("priority")));
				t.setName(o.getString("name"));
				t.setModified(o.getLong("modified"));
				// XXX moar!!
				ret.add(t);
			}
		} catch (JSONException e) {
			throw new RuntimeException("This rudpucker failed to parse! " + e, e);
		}
		return ret;
	}

}
<commit_msg>No <> in 1.6, sigh<commit_after>package todomore.android;

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

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import com.darwinsys.todo.model.Priority;
import com.darwinsys.todo.model.Task;

import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;

/** 
 * This class encapsulates various make-work functions that 
 * WOULD NOT BE NEEDED IF ANDROID'S API WERE OBJECT ORIENTED!
 * @author <NAME>
 */
public class GruntWork {
	
	private final static String TAG = "GruntWork";
	

	public static ContentValues taskToContentValuesWithout_ID(Task t) {
		return taskToContentValues(t, false);
	}

	public static ContentValues taskToContentValues(Task t) {
		return taskToContentValues(t, true);
	}
	
	private static ContentValues taskToContentValues(Task t, boolean include_ID) {
		ContentValues cv = new ContentValues();
		cv.put("id", t.getId());
		if (include_ID && t instanceof AndroidTask) {
			cv.put("_id", ((AndroidTask)t)._id);
		}
		cv.put("name", t.getName());
		cv.put("priority", t.getPriority().ordinal());
//		Date creationDate = new Date(); // when you decided you had to do it
//		Project project;	// what this task is part of
//		Context context;	// where to do it
//		Date dueDate;		// when to do it by
//		Status status;
//		Date completedDate = null; // when you actually did it
		cv.put("modified", t.getModified());
//		String description;
		return cv;
	}
 
	public static Task cursorToTask(Cursor c) {
		if (c.isAfterLast()) {
			Log.d(TAG, "Cursor has no more rows");
			return null;
		}
		AndroidTask t = new AndroidTask();
		t._id = c.getInt(1);
		t.setName(c.getString(c.getColumnIndex("name")));
		t.setPriority(Priority.values()[(c.getColumnIndex("priority"))]);
		t.setModified(c.getLong(c.getColumnIndex("modified")));
		return t;
	}
	
	public static List<Task> cursorToTaskList(Cursor c) {
		List<Task> list = new ArrayList<Task>();
		while (c.moveToNext()) {
			list.add(cursorToTask(c));
		}
		return list;
		}

	/**
	 * Convert JSON goo like this:
	 * [{"id":102,"priority":"High","name":"TEST 2",
	 * "creationDate":{"year":2015,"month":11,"day":1},
	 * "project":null,"context":{"id":100,"name":"Life"},
	 * "dueDate":null,"status":"ACTIVE","completedDate":null,
	 * "modified":1448292432791,"description":"None","complete":false},
	 * {"id":103,"priority":"Low","name":"Low prio item",
	 * "creationDate":{"year":2015,"month":10,"day":23},"project":null,
	 * "context":{"id":80,"name":"Home"},"dueDate":null,"status":"NEW",
	 * "completedDate":null,"modified":1448312330383,
	 * "description":"","complete":false}]
	 * into a proper List<Task>.
	 */
	public static List<Task> jsonStringToListTask(String resultStr) {
		List<Task> ret = new ArrayList<Task>();
		try {
			JSONArray array = (JSONArray) new JSONTokener(resultStr).nextValue();
			for (int i = 0; i < array.length(); i++) {
				JSONObject o = array.getJSONObject(i);
				Task t = new Task();
				t.setId(o.getLong("id"));
				t.setPriority(Priority.valueOf(o.getString("priority")));
				t.setName(o.getString("name"));
				t.setModified(o.getLong("modified"));
				// XXX moar!!
				ret.add(t);
			}
		} catch (JSONException e) {
			throw new RuntimeException("This JSON failed to parse! " + e, e);
		}
		return ret;
	}

}

{'fraction_non_alphanumeric': 0.17126743840902345, 'fraction_numerical': 0.01662214306915999, 'mean_word_length': 4.505718954248366, 'pattern_counts': {'":': 68, '<': 22, '<?xml version=': 0, '>': 20, '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': '2474080', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2217, 'n_words': 509}