-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from phirSOFT/AccumulatedTopologicalComparer
AccumulatedTopologicalComparer
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
phirSOFT.ConstraintedComparison/AccumulatedTopologicalComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |