热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java.lang.Iterable.iterator()方法的使用及代码示例

本文整理了Java中java.lang.Iterable.iterator()方法的一些代码示例,展示了Iterable.iterator()

本文整理了Java中java.lang.Iterable.iterator()方法的一些代码示例,展示了Iterable.iterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Iterable.iterator()方法的具体详情如下:
包路径:java.lang.Iterable
类名称:Iterable
方法名:iterator

Iterable.iterator介绍

[英]Returns an Iterator for the elements in this object.
[中]返回此对象中元素的迭代器。

代码示例

代码示例来源:origin: iluwatar/java-design-patterns

/**
* Collects all remaining objects of this Iterable into a list.
*
* @return a list with all remaining objects of this Iterable
*/
@Override
public List asList() {
return toList(iterable.iterator());
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public void subscribeActual(Subscriber s) {
Iterator it;
try {
it = source.iterator();
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
EmptySubscription.error(e, s);
return;
}
subscribe(s, it);
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public Integer apply(Integer v) throws Exception {
Observable.just(1).delay(10, TimeUnit.SECONDS).blockingIterable().iterator().next();
return v;
}
})

代码示例来源:origin: ReactiveX/RxJava

@Override
public Integer apply(Integer v) throws Exception {
Observable.just(1).delay(10, TimeUnit.SECONDS).blockingLatest().iterator().hasNext();
return v;
}
})

代码示例来源:origin: ReactiveX/RxJava

@Test
public void interrupted() {
Iterator it = Flowable.never().blockingLatest().iterator();
Thread.currentThread().interrupt();
try {
it.hasNext();
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
Thread.interrupted();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void interrupted() {
Iterator it = Observable.never().blockingLatest().iterator();
Thread.currentThread().interrupt();
try {
it.hasNext();
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
Thread.interrupted();
}

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = UnsupportedOperationException.class)
public void toFlowableIterableRemove() {
@SuppressWarnings("unchecked")
Iterable> f = SingleInternalHelper.iterableToFlowable(Arrays.asList(Single.just(1)));
Iterator> iterator = f.iterator();
iterator.next();
iterator.remove();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void interrupt() {
Iterator it = Flowable.never().blockingNext().iterator();
try {
Thread.currentThread().interrupt();
it.next();
} catch (RuntimeException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
}
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public Integer apply(Integer v) throws Exception {
Flowable.just(1).delay(10, TimeUnit.SECONDS).blockingNext().iterator().hasNext();
return v;
}
})

代码示例来源:origin: ReactiveX/RxJava

@Override
public Integer apply(Integer v) throws Exception {
Flowable.just(1).delay(10, TimeUnit.SECONDS).blockingIterable().iterator().next();
return v;
}
})

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 1000, expected = NoSuchElementException.class)
public void testEmpty() {
Observable source = Observable. empty();
Iterable iter = source.blockingLatest();
Iterator it = iter.iterator();
Assert.assertEquals(false, it.hasNext());
it.next();
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 1000, expected = RuntimeException.class)
public void testNextThrows() {
TestScheduler scheduler = new TestScheduler();
Observable source = Observable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable iter = source.blockingLatest();
Iterator it = iter.iterator();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
it.next();
}

代码示例来源:origin: ReactiveX/RxJava

@Test(/* timeout = 1000, */expected = RuntimeException.class)
public void testHasNextThrows() {
TestScheduler scheduler = new TestScheduler();
Observable source = Observable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable iter = source.blockingLatest();
Iterator it = iter.iterator();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
it.hasNext();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSynchronousNext() {
assertEquals(1, BehaviorProcessor.createDefault(1).take(1).blockingSingle().intValue());
assertEquals(2, BehaviorProcessor.createDefault(2).blockingIterable().iterator().next().intValue());
assertEquals(3, BehaviorProcessor.createDefault(3).blockingNext().iterator().next().intValue());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testToIterator() {
Flowable obs = Flowable.just("one", "two", "three");
Iterator it = obs.blockingIterable().iterator();
assertEquals(true, it.hasNext());
assertEquals("one", it.next());
assertEquals(true, it.hasNext());
assertEquals("two", it.next());
assertEquals(true, it.hasNext());
assertEquals("three", it.next());
assertEquals(false, it.hasNext());
}

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = TestException.class)
public void testMostRecentWithException() {
FlowableProcessor s = PublishProcessor.create();
Iterator it = s.blockingMostRecent("default").iterator();
assertTrue(it.hasNext());
assertEquals("default", it.next());
assertEquals("default", it.next());
s.onError(new TestException());
assertTrue(it.hasNext());
it.next();
}

代码示例来源:origin: ReactiveX/RxJava

@Test(expected = TestException.class)
public void testMostRecentWithException() {
Subject s = PublishSubject.create();
Iterator it = mostRecent(s, "default").iterator();
assertTrue(it.hasNext());
assertEquals("default", it.next());
assertEquals("default", it.next());
s.onError(new TestException());
assertTrue(it.hasNext());
it.next();
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 1000, expected = RuntimeException.class)
public void testNextThrows() {
TestScheduler scheduler = new TestScheduler();
Flowable source = Flowable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable iter = source.blockingLatest();
Iterator it = iter.iterator();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
it.next();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void error2() {
Iterator it = Observable.error(new TestException()).blockingLatest().iterator();
for (int i = 0; i <3; i++) {
try {
it.hasNext();
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
}
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void error2() {
Iterator it = Flowable.error(new TestException()).blockingLatest().iterator();
for (int i = 0; i <3; i++) {
try {
it.hasNext();
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
}
}

推荐阅读
author-avatar
王建毓桂恩佳士
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有