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()); }
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(); } }
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(); } }
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)); }
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)); }
internal static Range <T> Create(ICut <T> lowerBound, ICut <T> upperBound) { return(new Range <T>(lowerBound, upperBound)); }
public override int CompareTo(ICut <T> other) { return(other == this ? 0 : -1); }
public bool Equals(ICut <T> other) { return(CompareTo(other) == 0); }