using System.Collections.Generic; using System.Linq; namespace Unity.PlasticSCM.Editor.UI.Tree { internal class TreeViewItemIds { internal TreeViewItemIds() { mKeysById = new Dictionary(); mItemsById = new Dictionary(); } internal bool TryGetItemIdByKey(string key, out int itemId) { return mKeysById.TryGetValue(key, out itemId); } internal bool TryGetItemById(int itemId, out T item) { return mItemsById.TryGetValue(itemId, out item); } internal int AddItemIdByKey(string key) { int itemId = GetNextItemId(); mKeysById.Add(key, itemId); return itemId; } internal void AddItemById(int itemId, T item) { mItemsById[itemId] = item; } internal void ClearItems() { mItemsById.Clear(); } int GetNextItemId() { return mKeysById.Count + 1; } readonly Dictionary mKeysById; readonly Dictionary mItemsById; } internal class TreeViewItemIds { internal void Clear() { mCacheByCategories.Clear(); mCacheByInfo.Clear(); } internal List GetCategoryIds() { return new List(mCacheByCategories.Values); } internal List> GetCategoryItems() { return mCacheByCategories.ToList(); } internal List> GetInfoItems() { return mCacheByInfo.ToList(); } internal bool TryGetCategoryItemId(C category, out int itemId) { return mCacheByCategories.TryGetValue(category, out itemId); } internal bool TryGetInfoItemId(I info, out int itemId) { return mCacheByInfo.TryGetValue(info, out itemId); } internal int AddCategoryItem(C category) { int itemId = GetNextItemId(); mCacheByCategories.Add(category, itemId); return itemId; } internal int AddInfoItem(I info) { int itemId = GetNextItemId(); mCacheByInfo.Add(info, itemId); return itemId; } int GetNextItemId() { return mCacheByCategories.Count + mCacheByInfo.Count + 1; } readonly Dictionary mCacheByCategories = new Dictionary(); readonly Dictionary mCacheByInfo = new Dictionary(); } }