示例#1
0
        private static string ToString(ICut <T> lowerBound, ICut <T> upperBound)
        {
            var builder = new StringBuilder(32);

            lowerBound.DescribeAsLowerBound(builder);
            builder.Append("..");
            upperBound.DescribeAsUpperBound(builder);

            return(builder.ToString());
        }
示例#2
0
        public static int EndpointAsLowerClosed(this ICut <int> lower)
        {
            if (lower == BelowAll <int> .INSTANCE)
            {
                return(int.MinValue);
            }

            switch (lower.TypeAsLowerBound)
            {
            case BoundType.CLOSED: return(lower.Endpoint);

            case BoundType.OPEN: return(lower.Endpoint + 1);

            default: throw new InvalidOperationException();
            }
        }
示例#3
0
        public static long EndpointAsUpperClosed(this ICut <long> upper)
        {
            if (upper == AboveAll <long> .INSTANCE)
            {
                return(long.MaxValue);
            }

            switch (upper.TypeAsUpperBound)
            {
            case BoundType.CLOSED: return(upper.Endpoint);

            case BoundType.OPEN: return(upper.Endpoint - 1);

            default: throw new InvalidOperationException();
            }
        }
示例#4
0
        private Range(ICut <T> lowerBound, ICut <T> upperBound)
        {
            if (lowerBound == null)
            {
                throw new ArgumentNullException(nameof(lowerBound));
            }
            if (upperBound == null)
            {
                throw new ArgumentNullException(nameof(upperBound));
            }

            if (lowerBound.CompareTo(upperBound) > 0 ||
                lowerBound == AboveAll <T> .INSTANCE ||
                upperBound == BelowAll <T> .INSTANCE)
            {
                throw new InvalidOperationException("Invalid range: " + ToString(lowerBound, upperBound));
            }

            _lowerBound = lowerBound ?? throw new ArgumentNullException(nameof(lowerBound));
            _upperBound = upperBound ?? throw new ArgumentNullException(nameof(upperBound));
        }
示例#5
0
        public virtual int CompareTo(ICut <T> other)
        {
            if (other == BelowAll <T> .INSTANCE)
            {
                return(1);
            }
            if (other == AboveAll <T> .INSTANCE)
            {
                return(-1);
            }

            var result = Endpoint.CompareTo(other.Endpoint);

            if (result != 0)
            {
                return(result);
            }

            var thisIsAboveValue  = this as AboveValue <T> != null;
            var otherIsAboveValue = other as AboveValue <T> != null;

            return(thisIsAboveValue.CompareTo(otherIsAboveValue));
        }
示例#6
0
 internal static Range <T> Create(ICut <T> lowerBound, ICut <T> upperBound)
 {
     return(new Range <T>(lowerBound, upperBound));
 }
示例#7
0
 public override int CompareTo(ICut <T> other)
 {
     return(other == this ? 0 : -1);
 }
示例#8
0
 public bool Equals(ICut <T> other)
 {
     return(CompareTo(other) == 0);
 }