hu.akarnokd.rxjava2.math.MathFlowable Java Examples

The following examples show how to use hu.akarnokd.rxjava2.math.MathFlowable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Demo_average.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	MathFlowable.averageDouble(Flowable.range(10, 9)).subscribe(new FlowableSubscriber() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("completed successfully");
		}

		@Override
		public void onError(Throwable arg0) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onNext(Object value) {
			// TODO Auto-generated method stub
			System.out.println("average:-" + value);
		}

		@Override
		public void onSubscribe(Subscription subscription) {
			// TODO Auto-generated method stub
			subscription.request(1);
		}
	});
}
 
Example #2
Source File: Demo_sum.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// TODO Auto-generated method stub
	MathFlowable.sumInt(Flowable.range(10, 9)).subscribe(new 
		      Subscriber<Integer>() {

					@Override
					public void onComplete() {
						// TODO Auto-generated method stub
						System.out.println("completed 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(value);
					}

					@Override
					public void onSubscribe(Subscription subscription) {
						// TODO Auto-generated method stub
						subscription.request(1);
					}
				});


}
 
Example #3
Source File: Demo_min_max.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	MathFlowable.min(Flowable.range(10, 9))
			.subscribe(item -> System.out.println("minimum number from the sequence is:-" + item));
	MathFlowable.max(Flowable.range(10,9))
			.subscribe(item -> System.out.println("maximum number from the sequence is:- " + item));

}
 
Example #4
Source File: ExponentialBackoffFragment.java    From RxJava-Android-Samples with Apache License 2.0 4 votes vote down vote up
@OnClick(R.id.btn_eb_delay)
public void startExecutingWithExponentialBackoffDelay() {

  _logs = new ArrayList<>();
  _adapter.clear();

  DisposableSubscriber<Integer> disposableSubscriber =
      new DisposableSubscriber<Integer>() {
        @Override
        public void onNext(Integer integer) {
          Timber.d("executing Task %d [xx:%02d]", integer, _getSecondHand());
          _log(String.format("executing Task %d  [xx:%02d]", integer, _getSecondHand()));
        }

        @Override
        public void onError(Throwable e) {
          Timber.d(e, "arrrr. Error");
          _log("Error");
        }

        @Override
        public void onComplete() {
          Timber.d("onCompleted");
          _log("Completed");
        }
      };

  Flowable.range(1, 4)
      .delay(
          integer -> {
            // Rx-y way of doing the Fibonnaci :P
            return MathFlowable.sumInt(Flowable.range(1, integer))
                .flatMap(
                    targetSecondDelay ->
                        Flowable.just(integer).delay(targetSecondDelay, TimeUnit.SECONDS));
          })
      .doOnSubscribe(
          s ->
              _log(
                  String.format(
                      "Execute 4 tasks with delay - time now: [xx:%02d]", _getSecondHand())))
      .subscribe(disposableSubscriber);

  _disposables.add(disposableSubscriber);
}
 
Example #5
Source File: Demo_Mathematical_Operators.java    From Reactive-Programming-With-Java-9 with MIT License 3 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
	// TODO Auto-generated method stub
	MathFlowable.averageDouble(Flowable.range(10, 9)).subscribe(item->System.out.println("average is:-"+item));
	MathFlowable.sumInt(Flowable.range(10,9)).subscribe(item->System.out.println("sum is:-"+item));
	MathFlowable.min(Flowable.range(10,9)).subscribe(item->System.out.println("minimum number from the sequence is:-"+item));
	MathFlowable.max(Flowable.range(10,9)).subscribe(item->System.out.println("maximum number from the sequence is:-"+item));
	
	
	
}