Skip to content

Commit

Permalink
Merge pull request #2 from phirSOFT/AccumulatedTopologicalComparer
Browse files Browse the repository at this point in the history
AccumulatedTopologicalComparer
  • Loading branch information
Pretasoc authored Mar 5, 2018
2 parents d226c47 + 2992d95 commit fab1b4d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions phirSOFT.ConstraintedComparison/AccumulatedTopologicalComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;


namespace phirSOFT.TopologicalComparison
{
/// <inheritdoc cref="ITopologicalComparer{T}"/>
/// <summary>
/// A topological comparer that wraps multiple <see cref="ITopologicalComparer{T}"/> into one.
/// </summary>
/// <typeparam name="T">The type to compare</typeparam>
/// <remarks>
/// The comparers are applied in ascending index order.
/// </remarks>
public class AccumulatedTopologicalComparer<T> : Collection<ITopologicalComparer<T>>, ITopologicalComparer<T>
{
/// <inheritdoc cref="IComparer{T}.Compare"/>
public int Compare(T x, T y)
{
return this.First(item => item.CanCompare(x, y)).Compare(x, y);
}

/// <inheritdoc cref="ITopologicalComparer{T}.CanCompare"/>
public bool CanCompare(T x, T y)
{
return this.Any(item => item.CanCompare(x, y));
}
}
}

0 comments on commit fab1b4d

Please sign in to comment.