mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
feat: Util methods for inserting items into a sorted list by a predicate
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.Comparers;
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Extensions
|
namespace ICD.Common.Utils.Extensions
|
||||||
{
|
{
|
||||||
@@ -50,6 +51,30 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
items.ForEach(i => extends.AddSorted(i, comparer));
|
items.ForEach(i => extends.AddSorted(i, comparer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the items into a sorted list.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="TProp"></typeparam>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <param name="items"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
[PublicAPI]
|
||||||
|
public static void AddSorted<T, TProp>(this List<T> extends, IEnumerable<T> items, Func<T, TProp> predicate)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
|
if (items == null)
|
||||||
|
throw new ArgumentNullException("items");
|
||||||
|
|
||||||
|
if (predicate == null)
|
||||||
|
throw new ArgumentNullException("predicate");
|
||||||
|
|
||||||
|
PredicateComparer<T, TProp> comparer = new PredicateComparer<T, TProp>(predicate);
|
||||||
|
extends.AddSorted(items, comparer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the item into a sorted list.
|
/// Adds the item into a sorted list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -106,6 +131,27 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
extends.Insert(index, item);
|
extends.Insert(index, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the item into a sorted list.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="TProp"></typeparam>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
[PublicAPI]
|
||||||
|
public static void AddSorted<T, TProp>(this List<T> extends, T item, Func<T, TProp> predicate)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
|
if (predicate == null)
|
||||||
|
throw new ArgumentNullException("predicate");
|
||||||
|
|
||||||
|
PredicateComparer<T, TProp> comparer = new PredicateComparer<T, TProp>(predicate);
|
||||||
|
extends.AddSorted(item, comparer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pads the list to the given total length.
|
/// Pads the list to the given total length.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user