From 791116fd6a69d289920ffb3b5d5bf82bd29c9623 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Sun, 22 Dec 2013 23:32:30 +0100 Subject: [PATCH] Empty, Error and Never overloads with type witness --- rxjava-core/src/main/java/rx/Observable.java | 90 +++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/rxjava-core/src/main/java/rx/Observable.java b/rxjava-core/src/main/java/rx/Observable.java index 04fa8e5132..de5bda85b6 100644 --- a/rxjava-core/src/main/java/rx/Observable.java +++ b/rxjava-core/src/main/java/rx/Observable.java @@ -675,6 +675,36 @@ public static Observable empty(Scheduler scheduler) { return Observable. empty().subscribeOn(scheduler); } + /** + * Returns an Observable that emits no items to the {@link Observer} and + * immediately invokes its {@link Observer#onCompleted onCompleted} method. + * @param the result type + * @param witness the witness to help the compiler infer the result type + * @return an Observable that returns no data to the {@link Observer} and + * immediately invokes the {@link Observer}'s + * {@link Observer#onCompleted() onCompleted} method + */ + public static Observable empty(T witness) { + return empty(); + } + + /** + * Returns an Observable that emits no items to the {@link Observer} and + * immediately invokes its {@link Observer#onCompleted onCompleted} method + * with the specified scheduler. + * @param the result type + * @param scheduler the scheduler to call the + {@link Observer#onCompleted onCompleted} method + * @param witness the witness to help the compiler infer the result type + * @return an Observable that returns no data to the {@link Observer} and + * immediately invokes the {@link Observer}'s + * {@link Observer#onCompleted() onCompleted} method with the + * specified scheduler + */ + public static Observable empty(Scheduler scheduler, T witness) { + return empty(scheduler); + } + /** * Returns an Observable that invokes an {@link Observer}'s * {@link Observer#onError onError} method when the Observer subscribes to @@ -714,6 +744,47 @@ public static Observable error(Throwable exception, Scheduler scheduler) return Observable. error(exception).subscribeOn(scheduler); } + /** + * Returns an Observable that invokes an {@link Observer}'s + * {@link Observer#onError onError} method when the Observer subscribes to + * it. + *

+ * + * + * @param exception the particular error to report + * @param witness the value to help the compiler infer the value type + * @param the type of the items (ostensibly) emitted by the Observable + * @return an Observable that invokes the {@link Observer}'s + * {@link Observer#onError onError} method when the Observer + * subscribes to it + * @see RxJava Wiki: error() + * @see MSDN: Observable.Throw Method + */ + public static Observable error(Throwable exception, T witness) { + return new ThrowObservable(exception); + } + + /** + * Returns an Observable that invokes an {@link Observer}'s + * {@link Observer#onError onError} method with the specified scheduler. + *

+ * + * + * @param exception the particular error to report + * @param scheduler the scheduler to call the + * {@link Observer#onError onError} method + * @param witness the value to help the compiler infer the value type + * @param the type of the items (ostensibly) emitted by the Observable + * @return an Observable that invokes the {@link Observer}'s + * {@link Observer#onError onError} method with the specified + * scheduler + * @see RxJava Wiki: error() + * @see MSDN: Observable.Throw Method + */ + public static Observable error(Throwable exception, Scheduler scheduler, T witness) { + return Observable. error(exception).subscribeOn(scheduler); + } + /** * Converts an {@link Iterable} sequence into an Observable. *

@@ -1888,7 +1959,24 @@ public static Observable mergeDelayError(Observable t1, Obse public static Observable never() { return new NeverObservable(); } - + + /** + * Returns an Observable that never sends any items or notifications to an + * {@link Observer}. + *

+ * + *

+ * This Observable is useful primarily for testing purposes. + * + * @param the type of items (not) emitted by the Observable + * @param witness the value to help the compiler infer the item type + * @return an Observable that never emits any items or sends any + * notifications to an {@link Observer} + * @see RxJava Wiki: never() + */ + public static Observable never(T witness) { + return new NeverObservable(); + } /** * Given an Observable that emits Observables, returns an Observable that * emits the items emitted by the most recently emitted of those