//-----------------------------------------------------------------------
// <copyright file="IsGreaterThanFilterRule.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Management.UI.Internal
{
    using System;
    using System.Diagnostics;

    /// <summary>
    /// The IsGreaterThanFilterRule class evaluates an IComparable item to
    /// check if it is greater than its value.
    /// </summary>
    /// <typeparam name="T">
    /// The generic parameter.
    /// </typeparam>
    [Serializable]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
    public class IsGreaterThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
    {
        /// <summary>
        /// Initializes a new instance of the IsGreaterThanFilterRule class.
        /// </summary>
        public IsGreaterThanFilterRule()
        {
            this.DisplayName = UICultureResources.FilterRule_GreaterThanOrEqual;
        }

        /// <summary>
        /// Determines if item is greater than Value.
        /// </summary>
        /// <param name="data">
        /// The data to compare against.
        /// </param>
        /// <returns>
        /// Returns true if data is greater than Value.
        /// </returns>
        protected override bool Evaluate(T data)
        {
            Debug.Assert(this.IsValid);

            int result = CustomTypeComparer.Compare<T>(this.Value.GetCastValue(), data);
            return (result <= 0);
        }
    }
}
