zoukankan      html  css  js  c++  java
  • c# 多数值区间判断是否有重叠

    /// <summary>
        /// 金额区间判断帮助类 
        /// </summary>
        public static class DecimalRangeHelper
        {
            /// <summary>
            /// 是否有交集
            /// </summary>
            /// <param name="currentRange"></param>
            /// <param name="otherRange"></param>
            /// <returns></returns>
            public static bool IsIntersectionWith(this DecimalRange currentRange, DecimalRange otherRange)
            {
                return currentRange.Min.In(otherRange.Min, otherRange.Max) || currentRange.Max.In(otherRange.Min, otherRange.Max) && otherRange.Min != currentRange.Max;
            }
    
            /// <summary>
            /// 判断金额区间存在交集
            /// </summary>
            /// <param name="currentRanges"></param>
            /// <returns></returns>
            public static bool ExistsIntersectionRange(this List<DecimalRange> currentRanges)
            {
                return currentRanges.Any(p => currentRanges.Where(q => !object.ReferenceEqual(p,q)).Any(z => p.IsIntersectionWith(z)));
            }
        }
    /// <summary>
        /// 金额区间对应类 
        /// </summary>
        public class DecimalRange
        {
            /// <summary>
            /// 最大
            /// </summary>
            private decimal max;
    
            /// <summary>
            /// 最小值
            /// </summary>
            public decimal Min { get; set; }
    
            /// <summary>
            /// 最大值
            /// </summary>
            public decimal Max
            {
                get
                {
                    return (max == 0) ? Decimal.MaxValue : max;
                }
                set
                {
                    max = value;
                }
            }
    
            /// <summary>
            /// ToString
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                return Min.ToString()+"-"+Max.ToString();
            }
        }
     /// <summary>
        /// 金额帮助类
        /// </summary>
        public static class DecimalHelper
        {
            /// <summary>
            /// 判断指定金额是否在指定金额范围内
            /// </summary>
            public static readonly Func<decimal, decimal, decimal, bool> IsInDecimalPeriodByMomney = (current, min, max) => min <= current && max > current;
    
            /// <summary>
            /// 判断指定金额是否在指定金额范围内
            /// </summary>
            public static bool In(this decimal current, decimal min, decimal max)
            {
                return IsInDecimalPeriodByMomney(current, min, max);
            }
    
            /// <summary>
            /// 判断指定金额范围是否包含指定金额范围内(max=0时表示不限制)
            /// </summary>
            public static bool InSpecial(this decimal currentMin, decimal currentMax, decimal min, decimal max)
            {
                if (max == 0)
                {
                    max = Decimal.MaxValue;
                }
                if (currentMax == 0)
                {
                    currentMax = Decimal.MaxValue;
                }
                return currentMin.In(min, max);
            }
        }
  • 相关阅读:
    实现基于C++的动态事件机制(转)
    D3D HLSL 一段代码注释
    directx加载ms3d动画模型
    几种空间分割算法研究之bsp
    IxEngine开发笔记
    使用UVAtlas技术管理贴图
    八叉树
    c#调用C++写的dll导出类,包含继承,重载等详细介绍(转载)
    给自己毕业前的一点任务
    大小端问题
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/8393387.html
Copyright © 2011-2022 走看看