2008-07-17 21:19:41 +00:00
|
|
|
|
#region CPL License
|
|
|
|
|
/*
|
|
|
|
|
Nuclex Framework
|
2014-07-19 09:13:36 +00:00
|
|
|
|
Copyright (C) 2002-2014 Nuclex Development Labs
|
2008-07-17 21:19:41 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the IBM Common Public License as
|
|
|
|
|
published by the IBM Corporation; either version 1.0 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
IBM Common Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the IBM Common Public
|
|
|
|
|
License along with this library
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2008-07-17 20:44:40 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Nuclex.Support.Collections {
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Compares two values in reverse or reverses the output of another comparer
|
|
|
|
|
/// </summary>
|
2012-03-14 15:47:31 +00:00
|
|
|
|
/// <typeparam name="TCompared">Type of values to be compared</typeparam>
|
|
|
|
|
public class ReverseComparer<TCompared> : IComparer<TCompared> {
|
2008-07-17 20:44:40 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>Initializes a new reverse comparer</summary>
|
2012-03-14 15:47:31 +00:00
|
|
|
|
public ReverseComparer() : this(Comparer<TCompared>.Default) { }
|
2008-07-17 20:44:40 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes the comparer to provide the inverse results of another comparer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="comparerToReverse">Comparer whose results will be inversed</param>
|
2012-03-14 15:47:31 +00:00
|
|
|
|
public ReverseComparer(IComparer<TCompared> comparerToReverse) {
|
2008-07-17 20:44:40 +00:00
|
|
|
|
this.comparer = comparerToReverse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Compares the left value to the right value</summary>
|
|
|
|
|
/// <param name="left">Value on the left side</param>
|
|
|
|
|
/// <param name="right">Value on the right side</param>
|
|
|
|
|
/// <returns>The relationship of the two values</returns>
|
2012-03-14 15:47:31 +00:00
|
|
|
|
public int Compare(TCompared left, TCompared right) {
|
2008-07-17 20:44:40 +00:00
|
|
|
|
return this.comparer.Compare(right, left); // intentionally reversed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The default comparer from the .NET framework</summary>
|
2012-03-14 15:47:31 +00:00
|
|
|
|
private IComparer<TCompared> comparer;
|
2008-07-17 20:44:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Nuclex.Support.Collections
|