mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
refactor: Using EqualityComparer instead of Comparer for equality...
This commit is contained in:
@@ -537,7 +537,7 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
[Test]
|
||||
public void ConsolidateComparerTest()
|
||||
{
|
||||
string[] sequence = new[] {"A", "B", "B", "C"}.Consolidate(Comparer<string>.Default).ToArray();
|
||||
string[] sequence = new[] {"A", "B", "B", "C"}.Consolidate(EqualityComparer<string>.Default).ToArray();
|
||||
|
||||
Assert.AreEqual(3, sequence.Length, StringUtils.ArrayFormat(sequence));
|
||||
Assert.AreEqual("A", sequence[0]);
|
||||
|
||||
@@ -1539,7 +1539,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
return Consolidate(extends, Comparer<T>.Default);
|
||||
return Consolidate(extends, EqualityComparer<T>.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1555,7 +1555,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static IEnumerable<T> Consolidate<T>([NotNull] this IEnumerable<T> extends,
|
||||
[NotNull] IComparer<T> comparer)
|
||||
[NotNull] IEqualityComparer<T> comparer)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
@@ -1578,14 +1578,14 @@ namespace ICD.Common.Utils.Extensions
|
||||
/// <param name="comparer"></param>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<T> ConsolidateIterator<T>([NotNull] IEnumerable<T> sequence,
|
||||
[NotNull] IComparer<T> comparer)
|
||||
[NotNull] IEqualityComparer<T> comparer)
|
||||
{
|
||||
bool first = true;
|
||||
T last = default(T);
|
||||
|
||||
foreach (T item in sequence)
|
||||
{
|
||||
if (!first && comparer.Compare(last, item) == 0)
|
||||
if (!first && comparer.Equals(last, item))
|
||||
continue;
|
||||
|
||||
first = false;
|
||||
|
||||
Reference in New Issue
Block a user