Class Interval<T>
- Namespace
- Arc4u
- Assembly
- Arc4u.dll
Represents an interval of values delimited by a LowerBound and an UpperBound, giving support for set theory operations. Provides the base class for types requiring support of set theory operations, such as the Period class.
public class Interval<T> : IEquatable<Interval<T>>, IComparable<Interval<T>>
Type Parameters
TThe type of the interval.
- Inheritance
-
Interval<T>
- Implements
-
IEquatable<Interval<T>>IComparable<Interval<T>>
- Derived
- Inherited Members
Constructors
Interval()
Initializes a new instance of the Interval<T> class.
protected Interval()
Interval(BoundDirection, T, T, BoundDirection)
Initializes a new instance of the Interval<T> class.
public Interval(BoundDirection lowerDirection, T lowerValue, T upperValue, BoundDirection upperDirection)
Parameters
lowerDirectionBoundDirectionThe lower direction.
lowerValueTThe lower value.
upperValueTThe upper value.
upperDirectionBoundDirectionThe upper direction.
Interval(Bound<T>?, Bound<T>?)
Initializes a new instance of the Interval<T> class.
[JsonConstructor]
public Interval(Bound<T>? lowerBound, Bound<T>? upperBound)
Parameters
Properties
Complement
Gets the complement of this instance.
[JsonIgnore]
public IntervalCollection<T> Complement { get; }
Property Value
- IntervalCollection<T>
An IntervalCollection<T> that contains elements not in this instance.
- See Also
IsEmpty
Gets a value indicating whether this instance represents an empty Interval<T>.
[JsonIgnore]
public bool IsEmpty { get; }
Property Value
- bool
trueif this instance contains no element; otherwise,false.
- See Also
-
Empty<T>()
IsSingleton
Gets a value indicating whether this instance represents a singleton.
[JsonIgnore]
public bool IsSingleton { get; }
Property Value
- bool
trueif this instance contains only one element; otherwise,false.
- See Also
-
SingletonOf<T>(T)
IsUniverse
Gets a value indicating whether this instance represents an universe.
[JsonIgnore]
public bool IsUniverse { get; }
Property Value
- bool
trueif this instance represents an universe; otherwise,false.
- See Also
LowerBound
Gets the lower bound.
public Bound<T> LowerBound { get; }
Property Value
- Bound<T>
The lower bound.
Remarks
The set operation is not private to let the Silverlight runtime accessing the property during serializing/deserializing operations.
UpperBound
Gets the upper bound.
public Bound<T> UpperBound { get; }
Property Value
- Bound<T>
The upper bound.
Remarks
The set operation is not private to let the Silverlight runtime accessing the property during serializing/deserializing operations.
Methods
CompareTo(Interval<T>?)
Compares this instance to a specified Interval<T> and returns an indication of their relative values.
public int CompareTo(Interval<T>? other)
Parameters
otherInterval<T>A Interval<T> to compare to this instance.
Returns
- int
A signed number indicating the relative values of this instance and the
other.Value Type Condition Less than zero This instance is less than the other.Zero This instance is equal to the other.Greater than zero This instance is greater than the other.
Remarks
Comparison does not rely on the number of elements contained in the Interval<T> but it is rather based on first the LowerBound and then the UpperBound.
Exceptions
- ArgumentNullException
otheris null.
Contains(T)
Determines whether this instance contains the specified value.
public bool Contains(T value)
Parameters
valueTThe value to search for.
Returns
- bool
trueif this instance contains the specifiedvalue; otherwise,false.
DifferenceWith(Interval<T>)
Determines the difference this instance with the other one.
public IntervalCollection<T> DifferenceWith(Interval<T> other)
Parameters
otherInterval<T>Another Interval<T>.
Returns
- IntervalCollection<T>
An IntervalCollection<T> that contains elements in this instance but not in
otherone.
- See Also
Equals(Interval<T>?)
Returns a value indicating whether this instance is equal to a specified Interval<T>.
public bool Equals(Interval<T>? other)
Parameters
otherInterval<T>A Interval<T> to compare to this instance.
Returns
- bool
true if this instance equals the
other; otherwise, false.
Equals(object?)
Returns a value indicating whether this instance is equal to a specified object.
public override bool Equals(object? obj)
Parameters
objobjectAn object to compare to this instance.
Returns
- bool
true if this instance equals the
obj; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer hash code.
IntersectionWith(Interval<T>)
Determines the intersection of this instance with the other one.
public Interval<T> IntersectionWith(Interval<T> other)
Parameters
otherInterval<T>Another Interval<T>.
Returns
- Interval<T>
An Interval<T> that contains all elements of this instance that also belong to the
otherone (or equivalently, all elements of theotherone that also belong to this instance), but no other elements.
- See Also
IntersectsWith(Interval<T>)
Determines whether this instance intersects the other one.
public bool IntersectsWith(Interval<T> other)
Parameters
otherInterval<T>Another Interval<T>.
Returns
- bool
trueif this instance intersects theotherone; otherwise,false.
IsEmptyOf(T)
Gets a value indicating whether this instance represents an empty Interval<T> of the specified element.
protected bool IsEmptyOf(T value)
Parameters
valueTThe element value.
Returns
- bool
trueif this instance contains no element; otherwise,false.
- See Also
-
Empty<T>()EmptyOf<T>(T)
IsSingletonOf(T)
Gets a value indicating whether this instance represents a singleton of the specified element.
public bool IsSingletonOf(T value)
Parameters
valueTThe element value.
Returns
- bool
trueif this instance contains only the specifiedvalue; otherwise,false.
- See Also
-
SingletonOf<T>(T)
OverrideBounds(T, T)
Overrides the default bound values of Interval<T>.
public static void OverrideBounds(T lowestValue, T upmostValue)
Parameters
lowestValueTThe lowest value.
upmostValueTThe upmost value.
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
TryIntersectionWith(Interval<T>, out Interval<T>)
Determines the intersection of this instance with the other one.
public bool TryIntersectionWith(Interval<T> other, out Interval<T> intersection)
Parameters
otherInterval<T>Another Interval<T>.
intersectionInterval<T>When this method returns, contains the Interval<T> that contains all elements of this instance that also belong to the
otherone; otherwise, an Empty<T>() interval.
Returns
- bool
true if the intersection is not empty; otherwise, false.
UnionWith(Interval<T>)
Determines the union of this instance with the other one.
public IntervalCollection<T> UnionWith(Interval<T> other)
Parameters
otherInterval<T>Another Interval<T>.
Returns
- IntervalCollection<T>
An IntervalCollection<T> that contains all distinct elements of this instance and the
otherone.
- See Also
UnionWith(UnionDenominator, Interval<T>)
Determines the union of this instance with the other one according to the specified denominator.
public IntervalCollection<T> UnionWith(UnionDenominator denominator, Interval<T> other)
Parameters
denominatorUnionDenominatorThe denominator considered while performing the union.
otherInterval<T>Another Interval<T>.
Returns
- IntervalCollection<T>
An IntervalCollection<T> that contains all distinct elements of this instance and the
otherone.
Remarks
While performing an UnionOf intervals, depending of the specified UnionDenominator, the result will be different. If you consider the following intervals:
| a | ]∞ ; 3[ |
| b | ]0 ; 5[ |
| c | [1 ; 2] |
The union with the Highest denominator will return an IntervalCollection<T> of 1 element as shown below:
| i | ]∞ ; 5[ |
The union with the Lowest denominator will return an IntervalCollection<T> of 5 element as shown below:
| i | ]∞ ; 0] |
| j | ]0 ; 1[ |
| k | [1 ; 2] |
| l | ]2 ; 3[ |
| m | [3 ; 5[ |
Operators
operator ==(Interval<T>?, Interval<T>?)
Implements the operator ==.
public static bool operator ==(Interval<T>? left, Interval<T>? right)
Parameters
leftInterval<T>The left Interval<T>.
rightInterval<T>The right Interval<T>.
Returns
- bool
The result of the operator.
operator ==(Interval<T>, object)
Implements the operator ==.
public static bool operator ==(Interval<T> left, object right)
Parameters
Returns
- bool
The result of the operator.
operator ==(object?, Interval<T>?)
Implements the operator ==.
public static bool operator ==(object? left, Interval<T>? right)
Parameters
Returns
- bool
The result of the operator.
operator !=(Interval<T>?, Interval<T>?)
Implements the operator !=.
public static bool operator !=(Interval<T>? left, Interval<T>? right)
Parameters
leftInterval<T>The left Interval<T>.
rightInterval<T>The right Interval<T>.
Returns
- bool
The result of the operator.
operator !=(Interval<T>, object)
Implements the operator ==.
public static bool operator !=(Interval<T> left, object right)
Parameters
Returns
- bool
The result of the operator.
operator !=(object, Interval<T>)
Implements the operator !=.
public static bool operator !=(object left, Interval<T> right)
Parameters
Returns
- bool
The result of the operator.