From d914b7cd2773cbdeff3d0d25f95dbdb092287f8b Mon Sep 17 00:00:00 2001 From: akarnokd Date: Mon, 23 Dec 2013 23:20:02 +0100 Subject: [PATCH] Operation AsObservable --- rxjava-core/src/main/java/rx/Observable.java | 9 +++++ .../rx/operators/OperationAsObservable.java | 37 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 rxjava-core/src/main/java/rx/operators/OperationAsObservable.java diff --git a/rxjava-core/src/main/java/rx/Observable.java b/rxjava-core/src/main/java/rx/Observable.java index f9dd5b9428..989247ea61 100644 --- a/rxjava-core/src/main/java/rx/Observable.java +++ b/rxjava-core/src/main/java/rx/Observable.java @@ -35,6 +35,7 @@ import rx.operators.OperationAll; import rx.operators.OperationAmb; import rx.operators.OperationAny; +import rx.operators.OperationAsObservable; import rx.operators.OperationAverage; import rx.operators.OperationBuffer; import rx.operators.OperationCache; @@ -511,6 +512,14 @@ public Subscription subscribe(final Action1 onNext, final Action1 asObservable() { + return create(new OperationAsObservable(this)); + } + /** * Returns a {@link ConnectableObservable} that upon connection causes the * source Observable to push results into the specified subject. diff --git a/rxjava-core/src/main/java/rx/operators/OperationAsObservable.java b/rxjava-core/src/main/java/rx/operators/OperationAsObservable.java new file mode 100644 index 0000000000..e753bb395e --- /dev/null +++ b/rxjava-core/src/main/java/rx/operators/OperationAsObservable.java @@ -0,0 +1,37 @@ +/** + * Copyright 2013 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx.operators; + +import rx.Observable; +import rx.Observable.OnSubscribeFunc; +import rx.Observer; +import rx.Subscription; + +/** + * Hides the identity of another observable. + * @param the return value type of the wrapped observable. + */ +public final class OperationAsObservable implements OnSubscribeFunc { + private final Observable source; + + public OperationAsObservable(Observable source) { + this.source = source; + } + @Override + public Subscription onSubscribe(Observer t1) { + return source.subscribe(t1); + } +}