package io.github.suzp1984.rx.demos;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;

/**
 * Created by jacobsu on 3/23/16.
 */
public class ObservableCreatRunner implements IRxRunner {
    public void run() {
        System.out.println( "--- Observable from an array ---" );
        final Integer[] intArray = new Integer[] {1, 2, 3, 4, 5};
        Observable.from(intArray).subscribe(new Observer<Integer>() {
            public void onCompleted() {
                System.out.println("completed.");
            }

            public void onError(Throwable throwable) {
                System.out.println(throwable.toString());
            }

            public void onNext(Integer integer) {
                System.out.println(integer);
            }
        });

        System.out.println("--- Observable create from OnSubscribe class ---");
        Observable.create(new Observable.OnSubscribe<Integer>() {
            public void call(Subscriber<? super Integer> subscriber) {
                for (Integer i : intArray) {
                    subscriber.onNext(i);
                }

                subscriber.onCompleted();
            }
        }).subscribe(new Observer<Integer>() {
            public void onCompleted() {
                System.out.println("completed.");
            }

            public void onError(Throwable throwable) {
                System.out.println(throwable.toString());
            }

            public void onNext(Integer integer) {
                System.out.println(integer);
            }
        });
    }
}

@@ -96,16 +96,97 @@
 riber;%0A%0A
+import java.lang.reflect.Array;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A
 /**%0A * C
@@ -328,17 +328,16 @@
 println(
- 
 %22--- Obs
@@ -362,17 +362,16 @@
 ray ---%22
- 
 );%0A     
@@ -856,16 +856,560 @@
    %7D);%0A%0A
+        System.out.println(%22--- Observable from a list ---%22);%0A        List%3CInteger%3E intList = Arrays.asList(intArray);%0A%0A        Observable.from(intList).subscribe(new Observer%3CInteger%3E() %7B%0A            public void onCompleted() %7B%0A                System.out.println(%22completed.%22);%0A            %7D%0A%0A            public void onError(Throwable throwable) %7B%0A                System.out.println(throwable.toString());%0A            %7D%0A%0A            public void onNext(Integer integer) %7B%0A                System.out.println(integer);%0A            %7D%0A        %7D);%0A%0A
         
@@ -2101,32 +2101,32 @@
 eger integer) %7B%0A
-
                 
@@ -2179,16 +2179,503 @@
      %7D);
+%0A%0A        System.out.println(%22--- Observable just  ---%22);%0A        Observable.just(intArray).subscribe(new Observer%3CInteger%5B%5D%3E() %7B%0A            public void onCompleted() %7B%0A                System.out.println(%22completed.%22);%0A            %7D%0A%0A            public void onError(Throwable throwable) %7B%0A                System.out.println(throwable.toString());%0A            %7D%0A%0A            public void onNext(Integer%5B%5D integers) %7B%0A                System.out.println(integers);%0A            %7D%0A        %7D);
 %0A    %7D%0A%7D

add Observable.just method