<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using int32.Utils.Extensions;

namespace int32.Utils.Configuration
{
    public class Config
    {
        private readonly List<ConfigEntry> _entries;

        public object this[string key]
        {
            get { return GetConfigEntry(key).Value; }
        }

        public Config()
        {
            _entries = new List<ConfigEntry>();
        }

        public void Set(ConfigEntry entry)
        {
            _entries.Add(entry);
        }

        public void Set(string key, object value)
        {
            _entries.Add(new ConfigEntry(key, value));
        }

        public T Get<T>(string key)
        {
            return GetConfigEntry(key).Value.As<T>();
        }

        public void Remove(string key)
        {
            Remove(i => i.Key.Equals(key));
        }

        public void Remove(Func<ConfigEntry, bool> where)
        {
            for (var i = 0; i < _entries.Count; i++)
                if (where(_entries[i]))
                    _entries.RemoveAt(i);
        }

        private ConfigEntry GetConfigEntry(string key)
        {
            return _entries.SingleOrDefault(i => i.Key.Equals(key)).ThrowIfNull(key);<commit_msg>check if config entry already exists<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using int32.Utils.Extensions;

namespace int32.Utils.Configuration
{
    public class Config
    {
        private readonly List<ConfigEntry> _entries;

        public object this[string key]
        {
            get { return GetConfigEntry(key).Value; }
            set { Set(key, value); }
        }

        public Config()
        {
            _entries = new List<ConfigEntry>();
        }

        public void Set(ConfigEntry entry)
        {
            entry.ThrowIfNull("entry");

            if (_entries.Contains(entry))
                throw new ArgumentException(string.Format("Entry with key {0} already exists", entry.Key));

            _entries.Add(entry);
        }

        public void Set(string key, object value)
        {
            Set(new ConfigEntry(key, value));
        }

        public T Get<T>(string key)
        {
            return GetConfigEntry(key).Value.As<T>();
        }

        public void Remove(string key)
        {
            Remove(i => i.Key.Equals(key));
        }

        public void Remove(Func<ConfigEntry, bool> where)
        {
            for (var i = 0; i < _entries.Count; i++)
                if (where(_entries[i]))
                    _entries.RemoveAt(i);
        }

        private ConfigEntry GetConfigEntry(string key)
        {
            return _entries.SingleOrDefault(i => i.Key.Equals(key)).ThrowIfNull(key);
{'fraction_non_alphanumeric': 0.1044613710554951, 'fraction_numerical': 0.003989844033369605, 'mean_word_length': 1.7524950099800398, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '5429626', 'n_tokens_mistral': 759, 'n_tokens_neox': 731, 'n_words': 173}