本文整理汇总了Java中io.reactivex.Observable.range方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.range方法的具体用法?Java Observable.range怎么用?Java Observable.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.range方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test2
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void test2() {
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
Observable.fromIterable(words)
.flatMap(word -> Observable.fromArray(word.split("")))
.sorted()
.distinct()
.zipWith(range, (word, line) -> line + ":" + word)
.subscribe(System.out::println);
}
示例2: testReactive
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testReactive() {
Observable.just("Hello", "World")
.subscribe(System.out::println);
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Observable<String> wordsObs = Observable.fromIterable(words);
wordsObs.subscribe(System.out::println);
Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
// range.subscribe(System.out::println);
wordsObs.zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
.subscribe(System.out::println);
wordsObs.flatMap(word -> Observable.fromArray(word.split("")))
.sorted()
.distinct()
.zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
.subscribe(System.out::println);
}
示例3: test2
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void test2() {
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
Observable.fromIterable(words)
.flatMap(word -> Observable.fromArray(word.split("")))
.sorted()
.distinct()
.zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
.subscribe(System.out::println);
}
示例4: test8
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void test8() {
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Observable<String> wordsObs = Observable.fromIterable(words)
.flatMap(word -> Observable.fromArray(word.split("")));
wordsObs.subscribe(System.out::println);
Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
wordsObs
.distinct()
.sorted()
.zipWith(range, (word, row) -> row + ":" + word)
.subscribe(System.out::println);
}
示例5: test12
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void test12() {
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
Observable.fromIterable(words)
.flatMap(word -> Observable.fromArray(word.split("")))
.sorted()
.distinct()
.zipWith(range, (word, row)->row + ":" + word)
.subscribe(System.out::println);
}
示例6: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<String> source1 =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
Observable<Integer> source2 = Observable.range(1, 6);
Observable.zip(source1, source2, (s, i) -> s + "-" + i)
.subscribe(System.out::println);
}
示例7: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Integer> source = Observable.range(1, 1000);
source.toFlowable(BackpressureStrategy.BUFFER)
.observeOn(Schedulers.io())
.subscribe(System.out::println);
sleep(10000);
}
示例8: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Integer> source = Observable.range(start, count);
source.subscribe(i -> System.out.println("Observer 1: " + i));
//modify count
count = 10;
source.subscribe(i -> System.out.println("Observer 2: " + i));
}
示例9: filterAndReduceShouldResultIn19
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* OK, it's time for a challenge! Given the range below and what we've
* learned of rxjava so far, how can we produce an mSum equal to 19?? Hint:
* Use a Predicate to filter all values small then 9 and use the reduce operator to combine the emitted values
*/
@Test
public void filterAndReduceShouldResultIn19() {
Observable<Integer> range = Observable.range(1, 10);
// TODO use range and reduce on range and subscribe testObservable to it
assertThat(testObservable.values().get(0)).isEqualTo(19);
}
开发者ID:vogellacompany,项目名称:code-examples-android-expert,代码行数:12,代码来源:lessonC_BooleanLogicAndErrorHandling.java
示例10: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Observable<Integer> observable = Observable.range(1, 50);
observable.take(5).subscribe(new Observer<Integer>() {
@Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName() + " finished reading of items");
}
@Override
public void onError(Throwable throwable) {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName() + " finished with exception");
}
@Override
public void onNext(Integer value) {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName() + " read item:-"+value);
}
@Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
}
});
}
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:36,代码来源:Demo_take_no_threading.java
示例11: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer[] numbers = { 1, 2, 13, 34, 12, 10 };
String[] fruits = { "mango", "pineapple", "apple", "mango", "papaya" };
Observable<Integer> source1 = Observable.fromArray(numbers);
Observable<String> source2 = Observable.fromArray(fruits);
Observable<Integer> source3 = Observable.range(30, 3);
Observable.zip(source1, source2, source3, (value1, value2, value3) -> {
return value1 + ":" + value2 + "*" + value3;
}).subscribe(new Observer<String>() {
@Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("zipping completed successfully");
}
@Override
public void onError(Throwable throwable) {
// TODO Auto-generated method stub
throwable.printStackTrace();
}
@Override
public void onNext(String value) {
// TODO Auto-generated method stub
System.out.println(value);
}
@Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
}
});
}
示例12: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Observable source1= Observable.range(1,5);
Observable source2=Observable.just(10,20,30);
Observable.concat(source1,source2).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer value) throws Exception {
// TODO Auto-generated method stub
System.out.println(value);
}
});
}
示例13: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Observable<Integer> observable = Observable.range(10, 9);
observable.take(3).count().subscribe(item -> System.out.println("emitted " + item + " items"));
observable.take(3).subscribe(new Observer<Integer>() {
@Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("collected items successfully");
}
@Override
public void onError(Throwable throwable) {
// TODO Auto-generated method stub
throwable.printStackTrace();
}
@Override
public void onNext(Integer value) {
// TODO Auto-generated method stub
System.out.println("collected item: " + value);
}
@Override
public void onSubscribe(Disposable disposable) {
// TODO Auto-generated method stub
}
});
}
示例14: test
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void test() {
Observable.just("Hello", "World")
.subscribe(System.out::println);
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Observable.fromIterable(words)
.subscribe(System.out::println);
Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
// range.subscribe(System.out::println);
Observable.fromIterable(words)
.flatMap(word -> Observable.fromArray(word.split("")))
.sorted()
.distinct()
.zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
.subscribe(System.out::println);
}
示例15: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Integer> threeIntegers = Observable.range(1, 3);
threeIntegers.subscribe(i -> System.out.println("Observer One: " + i));
threeIntegers.subscribe(i -> System.out.println("Observer Two: " + i));
}