diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index 69447e97..18ac9859 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -368,7 +368,7 @@ namespace SabreTools.DatFiles #endregion - #region Custom Functionality + #region Bucketing /// /// Take the arbitrarily bucketed Files Dictionary and convert to one bucketed by a user-defined method @@ -407,53 +407,7 @@ namespace SabreTools.DatFiles PerformSorting(); } } - - /// - /// Remove any keys that have null or empty values - /// - public void ClearEmpty() - { - var keys = items.Keys.Where(k => k != null).ToList(); - foreach (string key in keys) - { - // If the key doesn't exist, skip - if (!items.ContainsKey(key)) - continue; - - // If the value is null, remove - else if (items[key] == null) -#if NET40_OR_GREATER || NETCOREAPP - items.TryRemove(key, out _); -#else - items.Remove(key); -#endif - - // If there are no non-blank items, remove - else if (!items[key]!.Any(i => i != null && i is not Blank)) -#if NET40_OR_GREATER || NETCOREAPP - items.TryRemove(key, out _); -#else - items.Remove(key); -#endif - } - } - - /// - /// Remove all items marked for removal - /// - public void ClearMarked() - { - var keys = items.Keys.ToList(); - foreach (string key in keys) - { - ConcurrentList? oldItemList = items[key]; - ConcurrentList? newItemList = oldItemList?.Where(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true)?.ToConcurrentList(); - - Remove(key); - AddRange(key, newItemList); - } - } - + /// /// List all duplicates found in a DAT based on a DatItem /// @@ -530,32 +484,6 @@ namespace SabreTools.DatFiles return roms?.Any(r => datItem.Equals(r)) == true; } - /// - /// Recalculate the statistics for the Dat - /// - public void RecalculateStats() - { - // Wipe out any stats already there - DatStatistics.ResetStatistics(); - - // If we have a blank Dat in any way, return - if (items == null) - return; - - // Loop through and add - foreach (string key in items.Keys) - { - ConcurrentList? datItems = items[key]; - if (datItems == null) - continue; - - foreach (DatItem item in datItems) - { - DatStatistics.AddItemStatistics(item); - } - } - } - /// /// Get the highest-order Field value that represents the statistics /// @@ -740,6 +668,86 @@ namespace SabreTools.DatFiles #endregion + #region Custom Functionality + + /// + /// Remove any keys that have null or empty values + /// + public void ClearEmpty() + { + var keys = items.Keys.Where(k => k != null).ToList(); + foreach (string key in keys) + { + // If the key doesn't exist, skip + if (!items.ContainsKey(key)) + continue; + + // If the value is null, remove + else if (items[key] == null) +#if NET40_OR_GREATER || NETCOREAPP + items.TryRemove(key, out _); +#else + items.Remove(key); +#endif + + // If there are no non-blank items, remove + else if (!items[key]!.Any(i => i != null && i is not Blank)) +#if NET40_OR_GREATER || NETCOREAPP + items.TryRemove(key, out _); +#else + items.Remove(key); +#endif + } + } + + /// + /// Remove all items marked for removal + /// + public void ClearMarked() + { + var keys = items.Keys.ToList(); + foreach (string key in keys) + { + ConcurrentList? oldItemList = items[key]; + ConcurrentList? newItemList = oldItemList?.Where(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true)?.ToConcurrentList(); + + Remove(key); + AddRange(key, newItemList); + } + } + + #endregion + + #region Statistics + + /// + /// Recalculate the statistics for the Dat + /// + public void RecalculateStats() + { + // Wipe out any stats already there + DatStatistics.ResetStatistics(); + + // If we have a blank Dat in any way, return + if (items == null) + return; + + // Loop through and add + foreach (string key in items.Keys) + { + ConcurrentList? datItems = items[key]; + if (datItems == null) + continue; + + foreach (DatItem item in datItems) + { + DatStatistics.AddItemStatistics(item); + } + } + } + + #endregion + #region IDictionary Implementations public ICollection?> Values => ((IDictionary?>)items).Values;