|
using System;
using System.Collections.Generic;
using System.Text;
namespace Idaligo.Time
{
public class OverAreaSequence : ISequence
{
private ISequence sequence;
private IArea area;
public OverAreaSequence(ISequence sequence, IArea area)
{
if (sequence == null) throw new ArgumentNullException("sequence");
if (area == null) throw new ArgumentNullException("area");
this.sequence = sequence;
this.area = area;
}
public bool AtPoint(DateTime at)
{
return this.sequence.AtPoint(at) && this.area.Hit(at);
}
public IEnumerable<DateTime> Walk(DateTime from)
{
IEnumerator<TimeRange> iteratorForArea = this.area.Walk(from).GetEnumerator();
if (iteratorForArea.MoveNext())
{
TimeRange area = iteratorForArea.Current;
DateTime start = (iteratorForArea.Current.From < from) ? from : iteratorForArea.Current.From;
IEnumerator<DateTime> iteratorForSequence = this.sequence.Walk(start).GetEnumerator();
while (iteratorForSequence.MoveNext())
{
DateTime at = iteratorForSequence.Current;
if (at < area.Till)
{
yield return at;
}
else
{
break;
}
}
while (iteratorForArea.MoveNext())
{
area = iteratorForArea.Current;
iteratorForSequence = this.sequence.Walk(area.From).GetEnumerator();
while (iteratorForSequence.MoveNext())
{
DateTime at = iteratorForSequence.Current;
if (at < area.Till)
{
yield return at;
}
else
{
break;
}
}
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.