using System; using System.Collections; using System.Collections.Generic; using Kreta.Core.Enum; using Kreta.Core.Exceptions; using Kreta.Ellenorzo.Domain.VN.Interfaces; namespace Kreta.Ellenorzo.Domain.VN.Indexers { /// /// Author: Kovács Kornél (DevKornél) Created On: 2019.07. /// public class UidsCollection : IEnumerable where T : class, IReadonlyUidRaw { private readonly List _uids = new List(); public UidsCollection(string uidsRaw, Converter uidsConverter) { if (string.IsNullOrWhiteSpace(uidsRaw)) { return; } string[] uidArray = uidsRaw.Split(Constant.UidDelimiter); if (uidArray.Length > 50) { throw new BlException(BlExceptionType.ListaTobbMint50ElemetTartalmaz); } _uids = new List(uidArray.Length); for (int i = 0; i < uidArray.Length; i++) { _uids.Add(GetUid(uidArray[i])); } T GetUid(string uidRaw) { string[] compositeKey = uidRaw.Split(Constant.UidInnerDelimiter); T uid = uidsConverter.Invoke(compositeKey); return uid; } } public T this[int index] => _uids[index]; public IEnumerator GetEnumerator() => throw new NotImplementedException(); IEnumerator IEnumerable.GetEnumerator() => _uids.GetEnumerator(); } }