} // ToString public virtual int CompareTo(TInterval <TFinite> other) { if (ReferenceEquals(other, null)) { throw new ArgumentNullException(); } return(Left.CompareTo(other.Left)); } // CompareTo
} // constructor protected virtual TInterval <TFinite> Intersection(TInterval <TFinite> other) { if (!Intersects(other)) { return(null); } return(new TInterval <TFinite>(Left.Max(other.Left), Right.Min(other.Right))); } // Intersection
} // operator - public virtual bool Intersects(TInterval <TFinite> other) { if (ReferenceEquals(this, other)) { return(true); } if (ReferenceEquals(other, null)) { return(false); } return(Contains(other.Left) || Contains(other.Right) || other.Contains(this)); } // Intersects
} // constructor public new virtual TDisjointIntervals <TFinite> Add(TInterval <TFinite> oInterval) { if (oInterval == null) { return(this); } if (this.Any(i => i.Intersects(oInterval))) { throw new ArgumentException("Interval to add intersects with an interval in the set."); } base.Add(oInterval); return(this); } // Add
} // Intersection protected virtual TDisjointIntervals <TFinite> Difference(TInterval <TFinite> other) { if (ReferenceEquals(this, other)) { return(null); } if (!Intersects(other)) { return(new TDisjointIntervals <TFinite>(new TInterval <TFinite>(this))); } if (other.Contains(this)) { return(null); } if (Contains(other)) { return(new TDisjointIntervals <TFinite>( new TInterval <TFinite>(Left, other.Left.Previous()), new TInterval <TFinite>(other.Right.Next(), Right) )); } // if if (Contains(other.Left)) { return(new TDisjointIntervals <TFinite>( new TInterval <TFinite>(Left, other.Left.Previous()) )); } // if return(new TDisjointIntervals <TFinite>( new TInterval <TFinite>(other.Right.Next(), Right) )); } // Difference
} // constructor public TDisjointIntervals(TInterval <TFinite> a, TInterval <TFinite> b) : this(a) { Add(b); } // constructor
} // constructor public TDisjointIntervals(TInterval <TFinite> a) : this() { Add(a); } // constructor
} // constructor protected TInterval(TInterval <TFinite> other) : this(other.Left, other.Right) { } // constructor
} // Contains public virtual bool Contains(TInterval <TFinite> other) { return((Left <= other.Left) && (other.Right <= Right)); } // Contains
} // operator - protected virtual DateInterval Intersection(DateInterval other) { TInterval <DateTime> oEdges = base.Intersection(other); return(oEdges == null ? null : new DateInterval(oEdges)); } // Intersection
} // constructor protected DateInterval(TInterval <DateTime> other) : base(other.Left, other.Right) { } // constructor