mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make item counts private
This commit is contained in:
@@ -801,7 +801,7 @@ namespace SabreTools.DatFiles.Test
|
|||||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||||
|
|
||||||
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
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(12345, dict.DatStatistics.TotalSize);
|
||||||
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]);
|
Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
@@ -811,7 +811,7 @@ namespace SabreTools.DatFiles.Test
|
|||||||
dict.RecalculateStats();
|
dict.RecalculateStats();
|
||||||
|
|
||||||
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
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(12345, dict.DatStatistics.TotalSize);
|
||||||
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]);
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
|
|||||||
@@ -638,7 +638,7 @@ namespace SabreTools.DatFiles.Test
|
|||||||
_ = dict.AddItem(item, statsOnly: false);
|
_ = dict.AddItem(item, statsOnly: false);
|
||||||
|
|
||||||
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
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(12345, dict.DatStatistics.TotalSize);
|
||||||
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]);
|
Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
@@ -648,7 +648,7 @@ namespace SabreTools.DatFiles.Test
|
|||||||
dict.RecalculateStats();
|
dict.RecalculateStats();
|
||||||
|
|
||||||
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
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(12345, dict.DatStatistics.TotalSize);
|
||||||
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]);
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ namespace SabreTools.DatFiles
|
|||||||
{
|
{
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Number of items for each item type
|
||||||
|
/// </summary>
|
||||||
|
private readonly Dictionary<ItemType, long> _itemCounts = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lock for statistics calculation
|
/// Lock for statistics calculation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,11 +32,6 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long TotalCount { get; private set; } = 0;
|
public long TotalCount { get; private set; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items for each item type
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<ItemType, long> ItemCounts { get; } = [];
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of machines
|
/// Number of machines
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -173,7 +173,7 @@ namespace SabreTools.DatFiles
|
|||||||
TotalCount += stats.TotalCount;
|
TotalCount += stats.TotalCount;
|
||||||
|
|
||||||
// Loop through and add stats for all items
|
// 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);
|
AddItemCount(itemCountKvp.Key, itemCountKvp.Value);
|
||||||
}
|
}
|
||||||
@@ -220,12 +220,12 @@ namespace SabreTools.DatFiles
|
|||||||
/// <returns>The number of items of that type, if it exists</returns>
|
/// <returns>The number of items of that type, if it exists</returns>
|
||||||
public long GetItemCount(ItemType itemType)
|
public long GetItemCount(ItemType itemType)
|
||||||
{
|
{
|
||||||
lock (ItemCounts)
|
lock (_itemCounts)
|
||||||
{
|
{
|
||||||
if (!ItemCounts.ContainsKey(itemType))
|
if (!_itemCounts.ContainsKey(itemType))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return ItemCounts[itemType];
|
return _itemCounts[itemType];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,14 +270,14 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
||||||
private void AddItemCount(ItemType itemType, long interval = 1)
|
private void AddItemCount(ItemType itemType, long interval = 1)
|
||||||
{
|
{
|
||||||
lock (ItemCounts)
|
lock (_itemCounts)
|
||||||
{
|
{
|
||||||
if (!ItemCounts.ContainsKey(itemType))
|
if (!_itemCounts.ContainsKey(itemType))
|
||||||
ItemCounts[itemType] = 0;
|
_itemCounts[itemType] = 0;
|
||||||
|
|
||||||
ItemCounts[itemType] += interval;
|
_itemCounts[itemType] += interval;
|
||||||
if (ItemCounts[itemType] < 0)
|
if (_itemCounts[itemType] < 0)
|
||||||
ItemCounts[itemType] = 0;
|
_itemCounts[itemType] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ namespace SabreTools.DatFiles
|
|||||||
public void ResetStatistics()
|
public void ResetStatistics()
|
||||||
{
|
{
|
||||||
TotalCount = 0;
|
TotalCount = 0;
|
||||||
ItemCounts.Clear();
|
_itemCounts.Clear();
|
||||||
GameCount = 0;
|
GameCount = 0;
|
||||||
TotalSize = 0;
|
TotalSize = 0;
|
||||||
HashCounts.Clear();
|
HashCounts.Clear();
|
||||||
@@ -405,14 +405,14 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
||||||
private void RemoveItemCount(ItemType itemType, long interval = 1)
|
private void RemoveItemCount(ItemType itemType, long interval = 1)
|
||||||
{
|
{
|
||||||
lock (ItemCounts)
|
lock (_itemCounts)
|
||||||
{
|
{
|
||||||
if (!ItemCounts.ContainsKey(itemType))
|
if (!_itemCounts.ContainsKey(itemType))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ItemCounts[itemType] -= interval;
|
_itemCounts[itemType] -= interval;
|
||||||
if (ItemCounts[itemType] < 0)
|
if (_itemCounts[itemType] < 0)
|
||||||
ItemCounts[itemType] = 0;
|
_itemCounts[itemType] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user