本文整理汇总了Java中rx.observables.BlockingObservable.from方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingObservable.from方法的具体用法?Java BlockingObservable.from怎么用?Java BlockingObservable.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.observables.BlockingObservable
的用法示例。
在下文中一共展示了BlockingObservable.from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testToIterableNextOnlyTwice
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testToIterableNextOnlyTwice() {
BlockingObservable<Integer> obs = BlockingObservable.from(Observable.just(1, 2, 3));
Iterator<Integer> it = obs.toIterable().iterator();
Assert.assertEquals((Integer) 1, it.next());
Assert.assertEquals((Integer) 2, it.next());
Assert.assertEquals((Integer) 3, it.next());
boolean exc = false;
try {
it.next();
} catch (NoSuchElementException ex) {
exc = true;
}
Assert.assertEquals(true, exc);
it.next();
}
示例2: testToIterableManyTimes
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testToIterableManyTimes() {
BlockingObservable<Integer> obs = BlockingObservable.from(Observable.just(1, 2, 3));
Iterable<Integer> iter = obs.toIterable();
for (int j = 0; j < 3; j++) {
Iterator<Integer> it = iter.iterator();
Assert.assertTrue(it.hasNext());
Assert.assertEquals((Integer) 1, it.next());
Assert.assertTrue(it.hasNext());
Assert.assertEquals((Integer) 2, it.next());
Assert.assertTrue(it.hasNext());
Assert.assertEquals((Integer) 3, it.next());
Assert.assertFalse(it.hasNext());
}
}
示例3: testToIterableWithException
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test(expected = TestException.class)
public void testToIterableWithException() {
BlockingObservable<String> obs = BlockingObservable.from(Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> observer) {
observer.onNext("one");
observer.onError(new TestException());
}
}));
Iterator<String> it = obs.toIterable().iterator();
assertEquals(true, it.hasNext());
assertEquals("one", it.next());
assertEquals(true, it.hasNext());
it.next();
}
示例4: testLastOrDefault
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testLastOrDefault() {
BlockingObservable<Integer> observable = BlockingObservable.from(Observable.just(1, 0, -1));
int last = observable.lastOrDefault(-100, new Function<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
return args >= 0;
}
});
assertEquals(0, last);
}
示例5: testFirstOrDefaultWithPredicateAndEmpty
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testFirstOrDefaultWithPredicateAndEmpty() {
BlockingObservable<String> observable = BlockingObservable.from(Observable.just("one", "two", "three"));
String first = observable.firstOrDefault("default", new Function<String, Boolean>() {
@Override
public Boolean call(String args) {
return args.length() > 5;
}
});
assertEquals("default", first);
}
示例6: testLastOrDefaultWithPredicate
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testLastOrDefaultWithPredicate() {
BlockingObservable<Integer> observable = BlockingObservable.from(Observable.just(1, 0, -1));
int last = observable.lastOrDefault(0, new Function<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
return args < 0;
}
});
assertEquals(-1, last);
}
示例7: testFirstWithPredicateAndEmpty
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testFirstWithPredicateAndEmpty() {
BlockingObservable<String> observable = BlockingObservable.from(Observable.just("one", "two", "three"));
observable.first(new Function<String, Boolean>() {
@Override
public Boolean call(String args) {
return args.length() > 5;
}
});
}
示例8: testLastWithPredicate
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testLastWithPredicate() {
BlockingObservable<String> obs = BlockingObservable.from(Observable.just("one", "two", "three"));
assertEquals("two", obs.last(new Function<String, Boolean>() {
@Override
public Boolean call(String s) {
return s.length() == 3;
}
}));
}
示例9: testFirstWithPredicate
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testFirstWithPredicate() {
BlockingObservable<String> observable = BlockingObservable.from(Observable.just("one", "two", "three"));
String first = observable.first(new Function<String, Boolean>() {
@Override
public Boolean call(String args) {
return args.length() > 3;
}
});
assertEquals("three", first);
}
示例10: testSingleDefaultPredicateMatchesNothing
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testSingleDefaultPredicateMatchesNothing() {
BlockingObservable<String> observable = BlockingObservable.from(Observable.just("one", "two"));
String result = observable.singleOrDefault("default", new Function<String, Boolean>() {
@Override
public Boolean call(String args) {
return args.length() == 4;
}
});
assertEquals("default", result);
}
示例11: testSingleWrongPredicate
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testSingleWrongPredicate() {
BlockingObservable<Integer> observable = BlockingObservable.from(Observable.just(-1));
observable.single(new Function<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
return args > 0;
}
});
}
示例12: testToIterableNextOnly
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testToIterableNextOnly() {
BlockingObservable<Integer> obs = BlockingObservable.from(Observable.just(1, 2, 3));
Iterator<Integer> it = obs.toIterable().iterator();
Assert.assertEquals((Integer) 1, it.next());
Assert.assertEquals((Integer) 2, it.next());
Assert.assertEquals((Integer) 3, it.next());
it.next();
}
示例13: toBlocking
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
public final BlockingObservable<T> toBlocking() {
return BlockingObservable.from(this);
}
示例14: testLast
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test
public void testLast() {
BlockingObservable<String> obs = BlockingObservable.from(Observable.just("one", "two", "three"));
assertEquals("three", obs.last());
}
示例15: testLastEmptyObservable
import rx.observables.BlockingObservable; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testLastEmptyObservable() {
BlockingObservable<Object> obs = BlockingObservable.from(Observable.empty());
obs.last();
}