hu.akarnokd.rxjava2.subjects.nbp.NbpPublishSubject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava2-backport Show documentation
Show all versions of rxjava2-backport Show documentation
rxjava2-backport developed by David Karnok
/**
* Copyright 2015 David Karnok and 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 hu.akarnokd.rxjava2.subjects.nbp;
import java.util.concurrent.atomic.*;
import hu.akarnokd.rxjava2.disposables.*;
import hu.akarnokd.rxjava2.internal.disposables.EmptyDisposable;
import hu.akarnokd.rxjava2.internal.util.NotificationLite;
import hu.akarnokd.rxjava2.plugins.RxJavaPlugins;
public final class NbpPublishSubject extends NbpSubject {
public static NbpPublishSubject create() {
State state = new State();
return new NbpPublishSubject(state);
}
final State state;
protected NbpPublishSubject(State state) {
super(state);
this.state = state;
}
@Override
public void onSubscribe(Disposable d) {
if (state.done) {
d.dispose();
}
}
@Override
public void onNext(T value) {
state.onNext(value);
}
@Override
public void onError(Throwable e) {
state.onError(e);
}
@Override
public void onComplete() {
state.onComplete();
}
@Override
public boolean hasSubscribers() {
return state.subscribers.length != 0;
}
@Override
public Throwable getThrowable() {
Object o = state.get();
if (NotificationLite.isError(o)) {
return NotificationLite.getError(o);
}
return null;
}
@Override
public T getValue() {
return null;
}
@Override
public T[] getValues(T[] array) {
if (array.length != 0) {
array[0] = null;
}
return array;
}
@Override
public boolean hasComplete() {
Object o = state.get();
return o != null && !NotificationLite.isError(o);
}
@Override
public boolean hasThrowable() {
return NotificationLite.isError(state.get());
}
@Override
public boolean hasValue() {
return false;
}
static final class State extends AtomicReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy