本文整理了Java中java.lang.Iterable.iterator()
方法的一些代码示例,展示了Iterable.iterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Iterable.iterator()
方法的具体详情如下:
包路径:java.lang.Iterable
类名称: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<E> asList() {
return toList(iterable.iterator());
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribeActual(Subscriber<? super T> s) {
Iterator<? extends T> 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<Object> 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<Object> 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<? extends Flowable<Integer>> f = SingleInternalHelper.iterableToFlowable(Arrays.asList(Single.just(1)));
Iterator<? extends Flowable<Integer>> iterator = f.iterator();
iterator.next();
iterator.remove();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void interrupt() {
Iterator<Object> 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<Long> source = Observable.<Long> empty();
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> 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<Long> source = Observable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> 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<Long> source = Observable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> 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<String> obs = Flowable.just("one", "two", "three");
Iterator<String> 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<String> s = PublishProcessor.create();
Iterator<String> 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<String> s = PublishSubject.create();
Iterator<String> 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<Long> source = Flowable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> it = iter.iterator();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
it.next();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void error2() {
Iterator<Object> 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<Object> 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
}
}
}
内容来源于网络,如有侵权,请联系作者删除!