Class CyclicRange<T>
Represents an inclusive range on a cyclic domain.
public class CyclicRange<T> : IRange<T> where T : IComparable<T>
Type Parameters
TThe value type of the cyclic range.
- Inheritance
-
CyclicRange<T>
- Implements
-
IRange<T>
- Derived
- Inherited Members
- Extension Methods
Remarks
A CyclicRange<T> where Start equals End represents a singleton — a range containing exactly one value. To represent the full cycle (all values from MinValue to MaxValue), use the FullCycle(T, T) factory method instead (#21).
Both Start and End must lie within [MinValue, MaxValue] (#20).
Constructors
CyclicRange(T, T, T, T)
Initializes a new instance of the CyclicRange<T> class.
public CyclicRange(T start, T end, T minValue, T maxValue)
Parameters
startTThe start boundary in the cycle. Must be within [
minValue,maxValue].endTThe end boundary in the cycle. Must be within [
minValue,maxValue].minValueTThe minimum representable value of the cycle.
maxValueTThe maximum representable value of the cycle.
Exceptions
- ArgumentNullException
Thrown when any of the arguments is null (for reference types).
- ArgumentException
Thrown when
minValueexceedsmaxValue, or whenstartorendlies outside [minValue,maxValue] (#20).
Properties
ContainsEnd
Gets a value indicating whether End belongs to the range.
public bool ContainsEnd { get; }
Property Value
ContainsStart
Gets a value indicating whether Start belongs to the range.
public bool ContainsStart { get; }
Property Value
End
Gets the end boundary of the range.
public T End { get; }
Property Value
- T
MaxValue
Gets the maximum representable value in the cycle.
public T MaxValue { get; }
Property Value
- T
MinValue
Gets the minimum representable value in the cycle.
public T MinValue { get; }
Property Value
- T
Start
Gets the start boundary of the range.
public T Start { get; }
Property Value
- T
Methods
Contains(IRange<T>)
Determines whether this range entirely contains another range.
public bool Contains(IRange<T> other)
Parameters
otherIRange<T>The range to test.
Returns
Contains(T)
Determines whether the supplied value belongs to the current range.
public virtual bool Contains(T value)
Parameters
valueTThe value to test.
Returns
FullCycle(T, T)
Creates a CyclicRange<T> that covers the complete cycle from
minValue to maxValue, inclusive (#21).
public static CyclicRange<T> FullCycle(T minValue, T maxValue)
Parameters
minValueTThe minimum representable value of the cycle.
maxValueTThe maximum representable value of the cycle.
Returns
- CyclicRange<T>
A cyclic range spanning the full domain.
Exceptions
- ArgumentException
Thrown when
minValueexceedsmaxValue.
Intersect(IRange<T>)
Computes one or more intersections between this range and another range.
public IRange<T>[] Intersect(IRange<T> other)
Parameters
otherIRange<T>The range to intersect with.
Returns
- IRange<T>[]
An array containing all intersection ranges. The array is empty when ranges are disjoint.
IsCompatibleWith(IRange<T>)
Determines whether the current range model is compatible with another range for aggregation in the same collection.
public bool IsCompatibleWith(IRange<T> other)
Parameters
otherIRange<T>The range to compare with.
Returns
Remarks
Two cyclic ranges are compatible when they share the same cycle bounds, determined by CompareTo(T) so that the ordering relation used for containment and intersection is consistent with the compatibility test (#22).
Overlap(IRange<T>)
Determines whether this range overlaps with another range.
public bool Overlap(IRange<T> other)
Parameters
otherIRange<T>The range to test.