diff --git a/SabreTools.DatFiles.Test/ItemDictionaryDBTests.cs b/SabreTools.DatFiles.Test/ItemDictionaryDBTests.cs index a9dc7cb5..8dcd1197 100644 --- a/SabreTools.DatFiles.Test/ItemDictionaryDBTests.cs +++ b/SabreTools.DatFiles.Test/ItemDictionaryDBTests.cs @@ -801,7 +801,7 @@ namespace SabreTools.DatFiles.Test _ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false); Assert.Equal(1, dict.DatStatistics.TotalCount); - Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]); + Assert.Equal(1, dict.DatStatistics.GetItemCount(ItemType.Rom)); Assert.Equal(12345, dict.DatStatistics.TotalSize); Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]); Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]); @@ -811,7 +811,7 @@ namespace SabreTools.DatFiles.Test dict.RecalculateStats(); Assert.Equal(1, dict.DatStatistics.TotalCount); - Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]); + Assert.Equal(1, dict.DatStatistics.GetItemCount(ItemType.Rom)); Assert.Equal(12345, dict.DatStatistics.TotalSize); Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]); Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]); diff --git a/SabreTools.DatFiles.Test/ItemDictionaryTests.cs b/SabreTools.DatFiles.Test/ItemDictionaryTests.cs index e73ff4e0..48be92bb 100644 --- a/SabreTools.DatFiles.Test/ItemDictionaryTests.cs +++ b/SabreTools.DatFiles.Test/ItemDictionaryTests.cs @@ -638,7 +638,7 @@ namespace SabreTools.DatFiles.Test _ = dict.AddItem(item, statsOnly: false); Assert.Equal(1, dict.DatStatistics.TotalCount); - Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]); + Assert.Equal(1, dict.DatStatistics.GetItemCount(ItemType.Rom)); Assert.Equal(12345, dict.DatStatistics.TotalSize); Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]); Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]); @@ -648,7 +648,7 @@ namespace SabreTools.DatFiles.Test dict.RecalculateStats(); Assert.Equal(1, dict.DatStatistics.TotalCount); - Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]); + Assert.Equal(1, dict.DatStatistics.GetItemCount(ItemType.Rom)); Assert.Equal(12345, dict.DatStatistics.TotalSize); Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]); Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]); diff --git a/SabreTools.DatFiles/DatStatistics.cs b/SabreTools.DatFiles/DatStatistics.cs index 771c197c..38873ce4 100644 --- a/SabreTools.DatFiles/DatStatistics.cs +++ b/SabreTools.DatFiles/DatStatistics.cs @@ -13,6 +13,11 @@ namespace SabreTools.DatFiles { #region Private instance variables + /// + /// Number of items for each item type + /// + private readonly Dictionary _itemCounts = []; + /// /// Lock for statistics calculation /// @@ -27,11 +32,6 @@ namespace SabreTools.DatFiles /// public long TotalCount { get; private set; } = 0; - /// - /// Number of items for each item type - /// - public Dictionary ItemCounts { get; } = []; - /// /// Number of machines /// @@ -173,7 +173,7 @@ namespace SabreTools.DatFiles TotalCount += stats.TotalCount; // Loop through and add stats for all items - foreach (var itemCountKvp in stats.ItemCounts) + foreach (var itemCountKvp in stats._itemCounts) { AddItemCount(itemCountKvp.Key, itemCountKvp.Value); } @@ -220,12 +220,12 @@ namespace SabreTools.DatFiles /// The number of items of that type, if it exists public long GetItemCount(ItemType itemType) { - lock (ItemCounts) + lock (_itemCounts) { - if (!ItemCounts.ContainsKey(itemType)) + if (!_itemCounts.ContainsKey(itemType)) return 0; - return ItemCounts[itemType]; + return _itemCounts[itemType]; } } @@ -270,14 +270,14 @@ namespace SabreTools.DatFiles /// Amount to increment by, defaults to 1 private void AddItemCount(ItemType itemType, long interval = 1) { - lock (ItemCounts) + lock (_itemCounts) { - if (!ItemCounts.ContainsKey(itemType)) - ItemCounts[itemType] = 0; + if (!_itemCounts.ContainsKey(itemType)) + _itemCounts[itemType] = 0; - ItemCounts[itemType] += interval; - if (ItemCounts[itemType] < 0) - ItemCounts[itemType] = 0; + _itemCounts[itemType] += interval; + if (_itemCounts[itemType] < 0) + _itemCounts[itemType] = 0; } } @@ -372,7 +372,7 @@ namespace SabreTools.DatFiles public void ResetStatistics() { TotalCount = 0; - ItemCounts.Clear(); + _itemCounts.Clear(); GameCount = 0; TotalSize = 0; HashCounts.Clear(); @@ -405,14 +405,14 @@ namespace SabreTools.DatFiles /// Amount to increment by, defaults to 1 private void RemoveItemCount(ItemType itemType, long interval = 1) { - lock (ItemCounts) + lock (_itemCounts) { - if (!ItemCounts.ContainsKey(itemType)) + if (!_itemCounts.ContainsKey(itemType)) return; - ItemCounts[itemType] -= interval; - if (ItemCounts[itemType] < 0) - ItemCounts[itemType] = 0; + _itemCounts[itemType] -= interval; + if (_itemCounts[itemType] < 0) + _itemCounts[itemType] = 0; } }