<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using LazyStorage.Interfaces;

namespace LazyStorage.Xml
{
    internal class XmlRepositoryWithConverter<T> : IRepository<T>
    {
        private readonly string _uri;
        private List<T> _repository = new List<T>();
        private readonly string _storageFolder;
        private readonly IConverter<T> _converter;

        public XmlRepositoryWithConverter(string storageFolder, IConverter<T> converter)
        {
            _uri = $"{storageFolder}{typeof(T)}.xml";
            _storageFolder = storageFolder;
            _converter = converter;
            Load();
        }

        public ICollection<T> Get(Func<T, bool> exp = null)
        {
            return exp != null ? _repository.Where(exp).ToList() : _repository.ToList();
        }

        public void Set(T item)
        {
            var storableObject = _converter.GetStorableObject(item);
            var matchingItemsInStore = _repository.Where(x => _converter.IsEqual(storableObject, x));

            if (matchingItemsInStore.Any())
            {
                // Update
                _repository.Remove(matchingItemsInStore.First());
                _repository.Add(item);
            }
            else
            {
                // Insert
                _repository.Add(item);
            }
        }

        public void Delete(T item)
        {
            var storableObject = _converter.GetStorableObject(item);
            var obj = _repository.Where(x => _converter.IsEqual(storableObject, x));
            _repository.Remove(obj.First());
        }
<commit_msg>Don't evaluate this multiple times<commit_after>using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using LazyStorage.Interfaces;

namespace LazyStorage.Xml
{
    internal class XmlRepositoryWithConverter<T> : IRepository<T>
    {
        private readonly string _uri;
        private List<T> _repository = new List<T>();
        private readonly string _storageFolder;
        private readonly IConverter<T> _converter;

        public XmlRepositoryWithConverter(string storageFolder, IConverter<T> converter)
        {
            _uri = $"{storageFolder}{typeof(T)}.xml";
            _storageFolder = storageFolder;
            _converter = converter;
            Load();
        }

        public ICollection<T> Get(Func<T, bool> exp = null)
        {
            return exp != null ? _repository.Where(exp).ToList() : _repository.ToList();
        }

        public void Set(T item)
        {
            var storableObject = _converter.GetStorableObject(item);
            var matchingItemsInStore = _repository.Where(x => _converter.IsEqual(storableObject, x)).ToList();

            if (matchingItemsInStore.Any())
            {
                // Update
                _repository.Remove(matchingItemsInStore.First());
                _repository.Add(item);
            }
            else
            {
                // Insert
                _repository.Add(item);
            }
        }

        public void Delete(T item)
        {
            var storableObject = _converter.GetStorableObject(item);
            var obj = _repository.Where(x => _converter.IsEqual(storableObject, x));
            _repository.Remove(obj.First());
        }

{'fraction_non_alphanumeric': 0.0966411314083677, 'fraction_numerical': 0.0, 'mean_word_length': 1.988556338028169, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4257547', 'n_tokens_mistral': 910, 'n_tokens_neox': 880, 'n_words': 186}