Table of Contents

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

T

The type of the interval.

Inheritance
Interval<T>
Implements
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

lowerDirection BoundDirection

The lower direction.

lowerValue T

The lower value.

upperValue T

The upper value.

upperDirection BoundDirection

The 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

lowerBound Bound<T>

The lower bound.

upperBound Bound<T>

The upper bound.

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

true if 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

true if this instance contains only one element; otherwise, false.

See Also

IsUniverse

Gets a value indicating whether this instance represents an universe.

[JsonIgnore]
public bool IsUniverse { get; }

Property Value

bool

true if 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

other Interval<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 TypeCondition
Less than zeroThis instance is less than the other.
ZeroThis instance is equal to the other.
Greater than zeroThis 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

other is null.

Contains(T)

Determines whether this instance contains the specified value.

public bool Contains(T value)

Parameters

value T

The value to search for.

Returns

bool

true if this instance contains the specified value; otherwise, false.

DifferenceWith(Interval<T>)

Determines the difference this instance with the other one.

public IntervalCollection<T> DifferenceWith(Interval<T> other)

Parameters

other Interval<T>

Another Interval<T>.

Returns

IntervalCollection<T>

An IntervalCollection<T> that contains elements in this instance but not in other one.

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

other Interval<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

obj object

An 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

other Interval<T>

Another Interval<T>.

Returns

Interval<T>

An Interval<T> that contains all elements of this instance that also belong to the other one (or equivalently, all elements of the other one 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

other Interval<T>

Another Interval<T>.

Returns

bool

true if this instance intersects the other one; 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

value T

The element value.

Returns

bool

true if 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

value T

The element value.

Returns

bool

true if this instance contains only the specified value; otherwise, false.

See Also

OverrideBounds(T, T)

Overrides the default bound values of Interval<T>.

public static void OverrideBounds(T lowestValue, T upmostValue)

Parameters

lowestValue T

The lowest value.

upmostValue T

The upmost value.

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.

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

other Interval<T>

Another Interval<T>.

intersection Interval<T>

When this method returns, contains the Interval<T> that contains all elements of this instance that also belong to the other one; 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

other Interval<T>

Another Interval<T>.

Returns

IntervalCollection<T>

An IntervalCollection<T> that contains all distinct elements of this instance and the other one.

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

denominator UnionDenominator

The denominator considered while performing the union.

other Interval<T>

Another Interval<T>.

Returns

IntervalCollection<T>

An IntervalCollection<T> that contains all distinct elements of this instance and the other one.

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

left Interval<T>

The left Interval<T>.

right Interval<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

left Interval<T>

The left.

right object

The right.

Returns

bool

The result of the operator.

operator ==(object?, Interval<T>?)

Implements the operator ==.

public static bool operator ==(object? left, Interval<T>? right)

Parameters

left object

The left.

right Interval<T>

The right.

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

left Interval<T>

The left Interval<T>.

right Interval<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

left Interval<T>

The left.

right object

The right.

Returns

bool

The result of the operator.

operator !=(object, Interval<T>)

Implements the operator !=.

public static bool operator !=(object left, Interval<T> right)

Parameters

left object

The left.

right Interval<T>

The right.

Returns

bool

The result of the operator.