本文整理汇总了C#中Iterator.Next方法的典型用法代码示例。如果您正苦于以下问题:C# Iterator.Next方法的具体用法?C# Iterator.Next怎么用?C# Iterator.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Iterator
的用法示例。
在下文中一共展示了Iterator.Next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNext
public void TestNext()
{
IEnumerable<DayOfWeek> collection = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Friday };
var iterator = new Iterator<DayOfWeek>(collection.GetEnumerator());
Assert.AreEqual(DayOfWeek.Monday, iterator.Next());
Assert.AreEqual(DayOfWeek.Friday, iterator.Next());
ExceptionAssert.Throws<InvalidOperationException>(() => iterator.Next());
}
示例2: DisplayMemberList
public static void DisplayMemberList(Iterator.IIterator iterator)
{
while (!iterator.IsDone())
{
Console.WriteLine(iterator.Next());
}
}
示例3: A_GroupedWithin_must_group_elements_within_the_duration
public void A_GroupedWithin_must_group_elements_within_the_duration()
{
this.AssertAllStagesStopped(() =>
{
var input = new Iterator<int>(Enumerable.Range(1, 10000));
var p = TestPublisher.CreateManualProbe<int>(this);
var c = TestSubscriber.CreateManualProbe<IEnumerable<int>>(this);
Source.FromPublisher(p)
.GroupedWithin(1000, TimeSpan.FromSeconds(1))
.To(Sink.FromSubscriber(c))
.Run(Materializer);
var pSub = p.ExpectSubscription();
var cSub = c.ExpectSubscription();
cSub.Request(100);
var demand1 = (int)pSub.ExpectRequest();
for (var i = 1; i <= demand1; i++)
pSub.SendNext(input.Next());
var demand2 = (int)pSub.ExpectRequest();
for (var i = 1; i <= demand2; i++)
pSub.SendNext(input.Next());
var demand3 = (int)pSub.ExpectRequest();
c.ExpectNext().ShouldAllBeEquivalentTo(Enumerable.Range(1, demand1 + demand2));
for (var i = 1; i <= demand3; i++)
pSub.SendNext(input.Next());
c.ExpectNoMsg(TimeSpan.FromMilliseconds(300));
c.ExpectNext()
.ShouldAllBeEquivalentTo(Enumerable.Range(demand1 + demand2 + 1, demand3));
c.ExpectNoMsg(TimeSpan.FromMilliseconds(300));
pSub.ExpectRequest();
var last = input.Next();
pSub.SendNext(last);
pSub.SendComplete();
c.ExpectNext().Should().HaveCount(1).And.HaveElementAt(0, last);
c.ExpectComplete();
c.ExpectNoMsg(TimeSpan.FromMilliseconds(200));
}, Materializer);
}
示例4: TestHasNext
public void TestHasNext()
{
var collection = Enum.GetValues(typeof(DayOfWeek)).Cast<DayOfWeek>();
var iterator = new Iterator<DayOfWeek>(collection.GetEnumerator());
for (int i = 0; i < collection.Count(); i++)
{
Assert.IsTrue(iterator.HasNext);
iterator.Next();
}
Assert.IsFalse(iterator.HasNext);
}
示例5: PrintMenu
public string PrintMenu(Iterator iterator)
{
StringBuilder sb = new StringBuilder();
while(iterator.HasNext())
{
MenuItem menuItem = (MenuItem)iterator.Next();
sb.Append(menuItem.Name + ", ");
sb.Append(menuItem.Price + " -- ");
sb.Append(menuItem.Description + "\n");
}
return sb.ToString();
}
示例6: TestForwardIteration
public void TestForwardIteration()
{
List<string> list = new List<string>();
list.Add("1");
list.Add("2");
list.Add("3");
int index = 0;
Iterator<string> iter = new Iterator<string>(list);
while (iter.HasNext())
{
Assert.AreEqual(list[index++], iter.Next());
}
Assert.AreEqual(list.Count, index);
}
示例7: Main
public static void Main(string[] args)
{
// Build a collection
Collection collection = new Collection();
collection[0] = new Item( "Item 0" );
collection[1] = new Item( "Item 1" );
collection[2] = new Item( "Item 2" );
collection[3] = new Item( "Item 3" );
collection[4] = new Item( "Item 4" );
collection[5] = new Item( "Item 5" );
collection[6] = new Item( "Item 6" );
collection[7] = new Item( "Item 7" );
collection[8] = new Item( "Item 8" );
// Create iterator
Iterator iterator = new Iterator( collection );
// Skip every other item
iterator.Step = 2;
// Loop using iterator
for( Item item = iterator.First();
!iterator.IsDone(); item = iterator.Next() )
{
Console.WriteLine( item.Name );
}
Console.Read();
}
示例8: A_GroupedWithin_must_reset_time_window_when_max_elements_reached
public void A_GroupedWithin_must_reset_time_window_when_max_elements_reached()
{
var input = new Iterator<int>(Enumerable.Range(1, 10000));
var upstream = TestPublisher.CreateProbe<int>(this);
var downstream = TestSubscriber.CreateProbe<IEnumerable<int>>(this);
Source.FromPublisher(upstream)
.GroupedWithin(3, TimeSpan.FromSeconds(2))
.To(Sink.FromSubscriber(downstream))
.Run(Materializer);
downstream.Request(2);
downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(1000));
Enumerable.Range(1,4).ForEach(_=>upstream.SendNext(input.Next()));
downstream.Within(TimeSpan.FromMilliseconds(1000), () =>
{
downstream.ExpectNext().ShouldAllBeEquivalentTo(new[] {1, 2, 3});
return NotUsed.Instance;
});
downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(1500));
downstream.Within(TimeSpan.FromMilliseconds(1000), () =>
{
downstream.ExpectNext().ShouldAllBeEquivalentTo(new[] {4});
return NotUsed.Instance;
});
upstream.SendComplete();
downstream.ExpectComplete();
downstream.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
}
示例9: A_GroupedWithin_must_buffer_groups_until_requested_from_downstream
public void A_GroupedWithin_must_buffer_groups_until_requested_from_downstream()
{
var input = new Iterator<int>(Enumerable.Range(1, 10000));
var p = TestPublisher.CreateManualProbe<int>(this);
var c = TestSubscriber.CreateManualProbe<IEnumerable<int>>(this);
Source.FromPublisher(p)
.GroupedWithin(1000, TimeSpan.FromSeconds(1))
.To(Sink.FromSubscriber(c))
.Run(Materializer);
var pSub = p.ExpectSubscription();
var cSub = c.ExpectSubscription();
cSub.Request(1);
var demand1 = (int)pSub.ExpectRequest();
for (var i = 1; i <= demand1; i++)
pSub.SendNext(input.Next());
c.ExpectNext().ShouldAllBeEquivalentTo(Enumerable.Range(1, demand1));
var demand2 = (int)pSub.ExpectRequest();
for (var i = 1; i <= demand2; i++)
pSub.SendNext(input.Next());
c.ExpectNoMsg(TimeSpan.FromMilliseconds(300));
cSub.Request(1);
c.ExpectNext().ShouldAllBeEquivalentTo(Enumerable.Range(demand1 + 1, demand2));
pSub.SendComplete();
c.ExpectComplete();
c.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
}
示例10: NextArg
public static string NextArg(Iterator<string> iter)
{
if (iter.HasNext())
{
string arg = StringUtils.UnArg(iter.Next());
if (!IsValidArg(arg))
{
throw new CCommandException("Invalid arg: " + arg);
}
return arg;
}
throw new CCommandException("Unexpected end of args");
}
示例11: CompileError
public CompileError(String message, Iterator<Token> at)
: base(message + " " + (at.AtEnd() ? "NULL" : at.Next().ToString()))
{
}
示例12: PrintVegetarianMenu
private void PrintVegetarianMenu(Iterator iterator)
{
while (iterator.HasNext())
{
MenuItem menuItem = (MenuItem)iterator.Next();
if (menuItem.Vegetarian)
{
Console.WriteLine(menuItem.Name);
Console.WriteLine("\t\t" + menuItem.Price);
Console.WriteLine("\t" + menuItem.Description);
}
}
}
示例13: getSuggestedOptions
private static string[] getSuggestedOptions(Iterator<string> iter, CCommand cmd, string optNameToken, string prefix)
{
List<Option> optionsList = new List<Option>(); // TODO: reuse list
// list options
bool useShort = prefix.Equals("-");
if (useShort)
{
cmd.ListShortOptions(optionsList, optNameToken);
optionsList.Sort(delegate(Option op1, Option op2) {
return op1.ShortName.CompareTo(op2.ShortName);
});
}
else
{
cmd.ListOptions(optionsList, optNameToken);
optionsList.Sort(delegate(Option op1, Option op2) {
return op1.Name.CompareTo(op2.Name);
});
}
if (optionsList.Count > 1) // multiple options available
{
return getSuggestedOptions(optionsList, useShort);
}
if (optionsList.Count == 1) // single option available
{
Option opt = optionsList[0];
if (isOptionNameMatch(opt, optNameToken, useShort)) // option name already matched - try values
{
if (opt.HasValues()) // option has predefined values?
{
if (iter.HasNext()) // has value token?
{
return opt.ListValues(iter.Next());
}
return opt.Values;
}
if (iter.HasNext())
{
return EMPTY_SUGGESTIONS; // don't suggest option value
}
}
return singleSuggestion(getSuggestedOption(opt, useShort)); // suggest option`s name
}
return EMPTY_SUGGESTIONS;
}
示例14: IsVegetarian
private bool IsVegetarian(string name, Iterator iterator)
{
while (iterator.HasNext())
{
MenuItem menuItem = (MenuItem)iterator.Next();
if (menuItem.Name.Equals(name))
{
if (menuItem.Vegetarian)
{
return true;
}
}
}
return false;
}
示例15: TestSkipMultiple
public void TestSkipMultiple()
{
List<string> list = new List<string>();
list.Add("1");
list.Add("2");
list.Add("3");
Iterator<string> iter = new Iterator<string>(list);
iter.Skip(2);
Assert.IsTrue(iter.HasNext());
Assert.AreEqual(list[2], iter.Next());
}