<commit_before>namespace XamKit.Core.Storage
{
    using System;

    using Android.App;
    using Android.Content;
    using Android.Preferences;

    using XamKit.Common;
    using XamKit.Core.Common.Storage;

    public class AppSettings : IAppSettings
    {
        private readonly object obj = new object();

        private static ISharedPreferences SharedPreferences
        {
            get
            {
                return PreferenceManager.GetDefaultSharedPreferences(Application.Context);
            }
        }

        /// <summary>
        /// Determines whether the application settings contains an element with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to locate in the application settings.
        /// </param>
        /// <returns>
        /// Returns a <see cref="bool"/> value indicating whether the key exists.
        /// </returns>
        public bool ContainsKey(string key)
        {
            bool containsKey;

            lock (this.obj)
            {
                using (SharedPreferences)
                {
                    containsKey = SharedPreferences.Contains(key);
                }
            }

            return containsKey;
        }

        /// <summary>
        /// Gets a value from the application settings with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to locate the value for in the application settings.
        /// </param>
        /// <param name="value">
        /// The value to return.
        /// </param>
        /// <typeparam name="T">
        /// The type of the value stored in the application settings.
        /// </typeparam>
        /// <returns>
        /// Returns the stored <see cref="T"/> value, if available, else returns the default.
        /// </returns>
        public T Get<T>(string key, T value = default(T))
        {
            lock (this.obj)
            {
                if (this.ContainsKey(key))
                {
                    Type type = typeof(T);
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
                    {
                        type = Nullable.GetUnderlyingType(type);
                    }

                    object setting = null;

                    var code = Type.GetTypeCode(type);

                    using (SharedPreferences)
                    {
                        switch (code)
                        {
                            case TypeCode.Boolean:
                                setting = SharedPreferences.GetBoolean(key, Helpers.SafeParseBool(value));
                                break;
                            case TypeCode.Int32:
                                break;
                            case TypeCode.Int64:
                                break;
                            case TypeCode.Single:
                                break;
                            case TypeCode.Double:
                                break;
                            case TypeCode.Decimal:
                                // Not supported
                                break;
                            case TypeCode.DateTime:
                                break;
                            case TypeCode.String:
                                break;
                            default:
                                if (value is Guid)
                                {

                                }
                                else
                                {
                                    throw new ArgumentException("The provided value is not a supported type.");
                                }
                                break;
                        }
                    }
                }
            }

            return value;
        }

        /// <summary>
        /// Adds or updates a value in the application settings with the specified key and value.
        /// </summary>
        /// <param name="key">
        /// The key to add or update.
        /// </param>
        /// <param name="value">
        /// The value to add or update the key with.
        /// </param>
        public void AddOrUpdate(string key, object value)
        {
            lock (this.obj)
            {
                using (SharedPreferences)
                {
                    using (var editor = SharedPreferences.Edit())
                    {
                    }
                }
            }
        }

        /// <summary>
        /// Removes a key and value from the application settings with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to remove.
        /// </param>
        public void Remove(string key)
        {
            lock (this.obj)
            {
                using (SharedPreferences)
                {
                    if (SharedPreferences.Contains(key))
                    {
                        using (var editor = SharedPreferences.Edit())
                        {
                            editor.Remove(key);
                            editor.Commit();<commit_msg>Finished up android app settings<commit_after>namespace XamKit.Core.Storage
{
    using System;

    using Android.App;
    using Android.Content;
    using Android.Preferences;

    using XamKit.Common;
    using XamKit.Core.Common.Storage;

    public class AppSettings : IAppSettings
    {
        private readonly object obj = new object();

        private static ISharedPreferences SharedPreferences
        {
            get
            {
                return PreferenceManager.GetDefaultSharedPreferences(Application.Context);
            }
        }

        /// <summary>
        /// Determines whether the application settings contains an element with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to locate in the application settings.
        /// </param>
        /// <returns>
        /// Returns a <see cref="bool"/> value indicating whether the key exists.
        /// </returns>
        public bool ContainsKey(string key)
        {
            bool containsKey;

            lock (this.obj)
            {
                using (SharedPreferences)
                {
                    containsKey = SharedPreferences.Contains(key);
                }
            }

            return containsKey;
        }

        /// <summary>
        /// Gets a value from the application settings with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to locate the value for in the application settings.
        /// </param>
        /// <param name="value">
        /// The value to return.
        /// </param>
        /// <typeparam name="T">
        /// The type of the value stored in the application settings.
        /// </typeparam>
        /// <returns>
        /// Returns the stored <see cref="T"/> value, if available, else returns the default.
        /// </returns>
        public T Get<T>(string key, T value = default(T))
        {
            lock (this.obj)
            {
                if (this.ContainsKey(key))
                {
                    Type type = typeof(T);
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
                    {
                        type = Nullable.GetUnderlyingType(type);
                    }

                    object setting = null;

                    var code = Type.GetTypeCode(type);

                    using (SharedPreferences)
                    {
                        switch (code)
                        {
                            case TypeCode.Boolean:
                                setting = SharedPreferences.GetBoolean(key, Helpers.SafeParseBool(value));
                                break;
                            case TypeCode.Int32:
                                setting = SharedPreferences.GetInt(key, Helpers.SafeParseInt(value));
                                break;
                            case TypeCode.Int64:
                                setting = SharedPreferences.GetLong(key, Helpers.SafeParseInt64(value));
                                break;
                            case TypeCode.Single:
                                setting = SharedPreferences.GetFloat(key, Helpers.SafeParseFloat(value));
                                break;
                            case TypeCode.Double:
                                // Not supported
                                break;
                            case TypeCode.Decimal:
                                // Not supported
                                break;
                            case TypeCode.DateTime:
                                var dateTimeTicks = SharedPreferences.GetLong(key, 0);
                                setting = new DateTime(dateTimeTicks, DateTimeKind.Utc);
                                break;
                            case TypeCode.String:
                                setting = SharedPreferences.GetString(key, Helpers.SafeParseString(value));
                                break;
                            default:
                                if (value is Guid)
                                {
                                    setting = Guid.Empty;
                                    var val = SharedPreferences.GetString(key, Guid.Empty.ToString());
                                    if (!string.IsNullOrWhiteSpace(val))
                                    {
                                        setting = Helpers.SafeParseGuid(val);
                                    }
                                }
                                else
                                {
                                    throw new ArgumentException("The provided value is not a supported type.");
                                }
                                break;
                        }
                    }

                    value = (T)setting;
                }
            }

            return value;
        }

        /// <summary>
        /// Adds or updates a value in the application settings with the specified key and value.
        /// </summary>
        /// <param name="key">
        /// The key to add or update.
        /// </param>
        /// <param name="value">
        /// The value to add or update the key with.
        /// </param>
        public void AddOrUpdate(string key, object value)
        {
            lock (this.obj)
            {
                var type = value.GetType();
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
                {
                    type = Nullable.GetUnderlyingType(type);
                }

                var code = Type.GetTypeCode(type);

                using (SharedPreferences)
                {
                    using (var editor = SharedPreferences.Edit())
                    {
                        switch (code)
                        {
                            case TypeCode.Boolean:
                                editor.PutBoolean(key, Helpers.SafeParseBool(value));
                                break;
                            case TypeCode.Int32:
                                editor.PutInt(key, Helpers.SafeParseInt(value));
                                break;
                            case TypeCode.Int64:
                                editor.PutLong(key, Helpers.SafeParseInt64(value));
                                break;
                            case TypeCode.Single:
                                editor.PutFloat(key, Helpers.SafeParseFloat(value));
                                break;
                            case TypeCode.Double:
                                // Not supported
                                break;
                            case TypeCode.Decimal:
                                // Not supported
                                break;
                            case TypeCode.DateTime:
                                editor.PutLong(key, Helpers.SafeParseDateTime(value).ToUniversalTime().Ticks);
                                break;
                            case TypeCode.String:
                                editor.PutString(key, Helpers.SafeParseString(value));
                                break;
                            default:
                                if (value is Guid)
                                {
                                    editor.PutString(key, Helpers.SafeParseGuid(value).ToString());
                                }
                                else
                                {
                                    throw new ArgumentException("The provided value is not a supported type.");
                                }
                                break;
                        }

                        editor.Commit();
                    }
                }
            }
        }

        /// <summary>
        /// Removes a key and value from the application settings with the specified key.
        /// </summary>
        /// <param name="key">
        /// The key to remove.
        /// </param>
        public void Remove(string key)
        {
            lock (this.obj)
            {
                using (SharedPreferences)
                {
                    if (SharedPreferences.Contains(key))
                    {
                        using (var editor = SharedPreferences.Edit())
                        {
                            editor.Remove(key);
                            editor.Commit();
{'fraction_non_alphanumeric': 0.0812690134724033, 'fraction_numerical': 0.0012313486889758076, 'mean_word_length': 0.8389717634523175, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1454062', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2751, 'n_words': 733}