mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
Merge remote-tracking branch 'origin/ConnectPro_v1.7' into ConnectPro_v1.8
This commit is contained in:
@@ -62,6 +62,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- Fixed a bug where IcdCultureInfo would fail to load on Crestron 4-series processors
|
||||
- Clarifying which culture failed to load when IcdCultureInfo throws an exception
|
||||
|
||||
## [11.1.1] - 2020-08-21
|
||||
### Removed
|
||||
- Removed the OnItemTrimmed event from the ScrollQueue due to deadlocks
|
||||
|
||||
## [11.1.0] - 2020-05-19
|
||||
### Added
|
||||
- ScrollQueue - Added OnItemTrimmed event
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using ICD.Common.Properties;
|
||||
using ICD.Common.Utils.EventArguments;
|
||||
using ICD.Common.Utils.Extensions;
|
||||
|
||||
namespace ICD.Common.Utils.Collections
|
||||
{
|
||||
@@ -17,11 +15,6 @@ namespace ICD.Common.Utils.Collections
|
||||
private readonly LinkedList<TContents> m_Collection;
|
||||
private int m_MaxSize;
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an item is trimmed from the end of the queue.
|
||||
/// </summary>
|
||||
public event EventHandler<GenericEventArgs<TContents>> OnItemTrimmed;
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +31,8 @@ namespace ICD.Common.Utils.Collections
|
||||
|
||||
m_MaxSize = value;
|
||||
|
||||
Trim();
|
||||
TContents unused;
|
||||
Trim(out unused);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +80,13 @@ namespace ICD.Common.Utils.Collections
|
||||
/// Appends the item to the queue, trims old items that exceed max length.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="removed"></param>
|
||||
/// <returns>Returns true if an item was dequeued.</returns>
|
||||
[PublicAPI]
|
||||
public void Enqueue(TContents item)
|
||||
public bool Enqueue(TContents item, out TContents removed)
|
||||
{
|
||||
m_Collection.AddLast(item);
|
||||
Trim();
|
||||
return Trim(out removed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,14 +141,17 @@ namespace ICD.Common.Utils.Collections
|
||||
/// <summary>
|
||||
/// Removes items that fall outside of the max size.
|
||||
/// </summary>
|
||||
private void Trim()
|
||||
private bool Trim(out TContents removed)
|
||||
{
|
||||
while (Count > MaxSize)
|
||||
{
|
||||
TContents removed = m_Collection.First.Value;
|
||||
removed = default(TContents);
|
||||
|
||||
if (Count <= MaxSize)
|
||||
return false;
|
||||
|
||||
removed = m_Collection.First.Value;
|
||||
m_Collection.RemoveFirst();
|
||||
OnItemTrimmed.Raise(this, new GenericEventArgs<TContents>(removed));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user