@@ -0,0 +1,2015 @@
+/**%0A * Copyright 2016 Netflix, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage rx.javafx.sources;%0A%0Aimport javafx.collections.FXCollections;%0Aimport javafx.collections.ObservableList;%0Aimport rx.Observable;%0Aimport rx.observables.JavaFxObservable;%0A%0A/**%0A * A CompositeObservable can merge multiple Observables that can be added/removed at any time,%0A * affecting all Subscribers regardless of when they subscribed. This is especailly helpful for merging%0A * multiple UI event sources.%0A * @param %3CT%3E%0A */%0Apublic final class CompositeObservable%3CT%3E %7B%0A%0A    private final ObservableList%3CObservable%3CT%3E%3E sources;%0A    private final Observable%3CT%3E observable;%0A%0A    public CompositeObservable() %7B%0A        this(-1);%0A    %7D%0A%0A    public CompositeObservable(int initialCapacity) %7B%0A        sources = FXCollections.synchronizedObservableList(FXCollections.observableArrayList());%0A%0A        Observable%3CT%3E observable = JavaFxObservable.fromObservableList(sources)%0A                .switchMap(list -%3E Observable.from(list).flatMap((Observable%3CT%3E obs) -%3E obs));%0A%0A        if (initialCapacity %3E 0) %7B%0A            this.observable = observable.cacheWithInitialCapacity(initialCapacity);%0A        %7D%0A        else %7B%0A            this.observable = observable;%0A        %7D%0A    %7D%0A%0A    public Observable%3CT%3E toObservable() %7B%0A        return observable;%0A    %7D%0A%0A    public void add(Observable%3CT%3E observable) %7B%0A        sources.add(observable);%0A    %7D%0A    public void remove(Observable%3CT%3E observable) %7B%0A        sources.remove(observable);%0A    %7D%0A%7D%0A

Implement CompositeObservable