﻿using System.Collections.Generic;
using Hydra.Framework.Extensions;

namespace Hydra.Framework
{
    /// <summary>
    /// Reverse Compare for a given object T
    /// </summary>
    /// <typeparam name="T">Object to implement the compare</typeparam>
    public class ReverseComparer<T>
        : IComparer<T>
    {
        #region Member Variables
        /// <summary>
        /// Original Compare Implementation
        /// </summary>
        readonly IComparer<T> originalComparer;
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="ReverseComparer&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="original">The original.</param>
        public ReverseComparer(IComparer<T> original)
        {
            original.MustNotBeNull("original");
            originalComparer = original;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the original comparer.
        /// </summary>
        /// <value>The original comparer.</value>
        public IComparer<T> OriginalComparer
        {
            get
            {
                return originalComparer;
            }
        }
        #endregion

        #region Compare
        /// <summary>
        /// Compares the specified object T.
        /// </summary>
        /// <param name="x">The type to compare from</param>
        /// <param name="y">The type to compare to</param>
        /// <returns>Compare results</returns>
        public int Compare(T x, T y)
        {
            return originalComparer.Compare(y, x);
        }
        #endregion
    }
}