<commit_before>package com.turbo.whack;

import java.util.HashSet;
import java.util.Set;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;

public class SimpleDataStore {
	private String app_name = null;
	private SharedPreferences pref;
	private SharedPreferences.Editor editor;
	
	/**
	 * Constructor to retrieve a DataStore object.
	 * @param context The application context. Preferably this shouldn't be the activity.
	 * @param name The handle for the storage file.
	 */
	public SimpleDataStore(String name) {
		app_name = name;
		pref = ActivityHelper.context.getSharedPreferences(app_name, Context.MODE_PRIVATE);
		editor = pref.edit();
	}
	
	/**
	 * Add a new key or overwrite an existing int value
	 * @param key type string
	 * @param value type string
	 * @return False on failure, true otherwise.
	 */
	public boolean store_int_value(String key, int value) {
		editor.putInt(key, value);
		return editor.commit();
	}
	
	/**
	 * Add two values mapped to the same key. This is experimental.
	 * @param key
	 * @param value1
	 * @param value2
	 * @return
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public boolean store_multi_string(String key, String value1, String value2) {
		Set<String> set = new HashSet<String>(); ///< Set<type> is an interface
		set.add(value1);
		set.add(value2);
		editor.putStringSet(key, set);
		return editor.commit();
	}
	
	/**
	 * Add a new key or overwrite existing string value
	 * @param key type string
	 * @param value type string
	 * @return False on failure, true otherwise.
	 */
	public boolean store_string_value(String key, String value) {
		editor.putString(key, value);
		return editor.commit();
	}
	
	/**
	 * Retrieves an integer value from the stored table. Returns -1 on failure.
	 * @param key type string<commit_msg>PR #11: Introduce error handling.<commit_after>package com.turbo.whack;

import java.util.HashSet;
import java.util.Set;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;

public class SimpleDataStore {
	private String app_name = null;
	private SharedPreferences pref;
	private SharedPreferences.Editor editor;
	
	/**
	 * Constructor to retrieve a DataStore object.
	 * @param name The handle for the storage file.
	 */
	public SimpleDataStore(String name) {
		app_name = name;
		pref = ActivityHelper.context.getSharedPreferences(app_name, Context.MODE_PRIVATE);
		editor = pref.edit();
	}
	
	/**
	 * Add a new key or overwrite an existing int value
	 * @param key type string
	 * @param value type string.
	 * @return False on failure, true otherwise.
	 */
	public boolean store_int_value(String key, int value) {
		editor.putInt(key, value);
		return editor.commit();
	}
	
	/**
	 * Add two values mapped to the same key. This is experimental. Do not document.
	 * @param key
	 * @param value1
	 * @param value2
	 * @return
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public boolean store_multi_string(String key, String value1, String value2) {
		if(value1 == null || value2 == null) {
			Log.i(ActivityHelper.WH_LOG_WARN, "Cannot store null value.");
			return false;
		}
		Set<String> set = new HashSet<String>(); ///< Set<type> is an interface
		set.add(value1);
		set.add(value2);
		editor.putStringSet(key, set);
		return editor.commit();
	}
	
	/**
	 * Add a new key or overwrite existing string value
	 * @param key type string
	 * @param value type string. Cannot be null.
	 * @return False on failure, true otherwise.
	 */
	public boolean store_string_value(String key, String value) {
		if(value == null) {
			Log.i(ActivityHelper.WH_LOG_WARN, "Cannot store null value.");
			return false;
		}
		editor.putString(key, value);
		return editor.commit();
	}
	
	/**
	 * Retrieves an integer value from the stored table. Returns -1 on failure.
	 * @param key type string
{'fraction_non_alphanumeric': 0.10485093481556342, 'fraction_numerical': 0.004547751389590703, 'mean_word_length': 3.875615763546798, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '2359511', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1167, 'n_words': 395}