/// <summary> /// Finds the contiguous time series entry that is the most close to the lower interval boundary. /// </summary> /// <param name="interval">The interface to the lower interval boundary to find the lower entry.</param> /// <param name="origin">The origin lower entry position to start the search from.</param> /// <returns>The contiguous time series entry if found; otherwise, null.</returns> public T FindLower(IInterval <DateTime> interval, T origin) { if (interval != null) { var entry = origin = origin ?? Head; if (entry != null) { if (origin.Parent == this) { var reference = interval.IsLowerLimit(entry.Sample); while (entry != null) { switch (reference) { case bool last when last: entry = origin.Prev; if (entry != null) { switch (interval.IsLowerLimit(entry.Sample)) { case bool next when next: origin = entry; reference = next; break; default: entry = null; break; } } break; case bool last when !last: entry = origin = origin.Next; if (entry != null) { switch (interval.IsLowerLimit(entry.Sample)) { case bool next when !next: reference = next; break; default: entry = null; break; } } break; } } if (origin != null && !interval.IsUpperLimit(origin.Sample)) { origin = null; } } else { throw new ArgumentException($"The origin time series entry is bound to other container: {origin}", nameof(origin)); } } return(origin); } else { throw new ArgumentNullException(nameof(interval)); } }