@OnClick(R.id.btn_start_operation)
  public void startOperation() {

    _logs.clear();
    _log("Button Clicked");

    Observable.fromIterable(
            Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l")) //
        .flatMap(
            s1 -> {
              _log(s1 + "start");

              if (s1.equalsIgnoreCase("b") && _attempt < 5) {
                _attempt++;
                return Observable.error(
                    new Throwable("b can't be processed (" + (_attempt - 1) + ")"));
              }

              if (s1.equalsIgnoreCase("c") || s1.equalsIgnoreCase("f")) {
                return Observable.just(s1);
              } else {
                return Observable.timer(2, TimeUnit.SECONDS).map(l -> s1);
              }
            })
        .retryWhen(source -> source.delay(8, TimeUnit.SECONDS))
        .doOnNext(s -> _log(s + "stop"))
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe();
  }
 public Observable<OrderEvent> observeClose(final ClosePositionParams closePositionParams) {
   return Observable.defer(
       () -> {
         final Collection<IOrder> ordersToClose =
             ordersForPositionClose.forMode(closePositionParams);
         return ordersToClose.size() > 0
             ? batchChangeTask.close(ordersToClose, closePositionParams)
             : Observable.empty();
       });
 }
 private Observable<OrderEvent> observeMergeForFilledOrders(
     final ClosePositionParams closePositionParams) {
   return Observable.defer(
       () -> {
         final Collection<IOrder> filledOrders =
             ordersForPositionClose.filled(closePositionParams.instrument());
         return filledOrders.size() > 1
             ? mergePositionTask.merge(filledOrders, closePositionParams.mergePositionParams())
             : Observable.empty();
       });
 }
  @Override
  public Observable<Boolean> updateGroupList(List<GroupList> groupLists) {
    final Observable<Boolean> localResult = mGroupManageLocalDataSource.updateGroupList(groupLists);
    Observable<Boolean> remoteResult = mGroupManageRemoteDataSource.updateGroupList(groupLists);

    return remoteResult.flatMap(
        new Function<Boolean, Observable<Boolean>>() {
          @Override
          public Observable<Boolean> apply(Boolean isSuccess) {
            if (isSuccess) {
              return localResult;
            }
            return ObservableHelper.just(false);
          }
        });
  }
  /**
   * groupBy the mod of 5, thus the values into those who can starting at 0-4 respectively into
   * groups
   *
   * <p>Must reason about the logic that is going on here.
   */
  public static void groupedObserv() {

    Observable.fromIterable(ints)
        // Function<Input, Output>;
        .groupBy(
            (Function<Integer, Integer>)
                new Function<Integer, Integer>() {
                  @Override
                  public Integer apply(Integer integer) throws Exception {
                    return integer % 5;
                  }
                })
        .flatMap(
            new Function<GroupedObservable<Integer, Integer>, ObservableSource<?>>() {
              @Override
              public ObservableSource<?> apply( // each group is now a stream
                  GroupedObservable<Integer, Integer> integerIntegerGroupedObservable)
                  throws Exception {
                return integerIntegerGroupedObservable.toList().toObservable();
              }
            })
        .toList() // to list is important as it is the Single<List<Object>>
        .subscribe(
            new Consumer<List<Object>>() {
              @Override
              public void accept(List<Object> objects) throws Exception {
                for (Object o : objects) {
                  System.out.println(o.toString());
                }
              }
            });
  }
  @Test
  public void dependencies() {
    Runnable run = () -> System.out.print("Hello ");

    run.run();

    Observable.just("world").subscribe(System.out::println);
  }
  @Test
  public void testHidingError() {
    PublishSubject<Integer> src = PublishSubject.create();

    Observable<Integer> dst = src.asObservable();

    assertFalse(dst instanceof PublishSubject);

    @SuppressWarnings("unchecked")
    Observer<Object> o = mock(Observer.class);

    dst.subscribe(o);

    src.onError(new TestException());

    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
    verify(o).onError(any(TestException.class));
  }
  @Test
  public void testHiding() {
    PublishSubject<Integer> src = PublishSubject.create();

    Observable<Integer> dst = src.asObservable();

    assertFalse(dst instanceof PublishSubject);

    Subscriber<Object> o = TestHelper.mockSubscriber();

    dst.subscribe(o);

    src.onNext(1);
    src.onComplete();

    verify(o).onNext(1);
    verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
  }
Example #9
0
 public Observable<ThemePage> getPage(final String url, boolean generateHtml) {
   return Observable.fromCallable(() -> _getPage(url, generateHtml));
 }
Example #10
0
 public Observable<String> changeReputation(int postId, int userId, boolean type, String message) {
   return Observable.fromCallable(() -> _changeReputation(postId, userId, type, message));
 }
Example #11
0
 public Observable<String> votePost(int postId, boolean type) {
   return Observable.fromCallable(() -> _votePost(postId, type));
 }
Example #12
0
 public Observable<String> deletePost(int postId) {
   return Observable.fromCallable(() -> _deletePost(postId));
 }
Example #13
0
 public Observable<String> reportPost(int themeId, int postId, String message) {
   return Observable.fromCallable(() -> _reportPost(themeId, postId, message));
 }
 public Observable<OrderEvent> observeMerge(final ClosePositionParams closePositionParams) {
   return closePositionParams.closeExecutionMode() == CloseExecutionMode.CloseOpened
       ? Observable.empty()
       : observeMergeForFilledOrders(closePositionParams);
 }