本文整理匯總了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));
}