@Override public void call() { mapSubject.get(arg).first.clear(); } })
/** * Creates a {@link ClearableBehaviorSubject} without a default item. * * @param <T> * the type of item the Subject will emit * @return the constructed {@link ClearableBehaviorSubject} */ public static <T> ClearableBehaviorSubject<T> create() { return create(null, false); } /**
private void initialiseMockedObservable(Method method, Object[] args) { ClearableBehaviorSubject<Notification> subject = ClearableBehaviorSubject.create(); PublishSubject<Notification> notificationSubject = PublishSubject.create(); final String keyForArgs = getKeyFor(method, args); final Observable observable = subject .dematerialize() .doOnEach(new NotifyDataEvent(notificationSubject)) .lift(new SwallowUnsubscribe()); observableHashMap.put(keyForArgs, observable); mapSubject.put(observable, new Pair<>(subject, notificationSubject)); }
private static <T> ClearableBehaviorSubject<T> create(T defaultValue, boolean hasDefault) { final SubjectSubscriptionManager<T> state = new SubjectSubscriptionManager<T>(); if (hasDefault) { state.set(NotificationLite.instance().next(defaultValue)); } state.onAdded = new Action1<SubjectObserver<T>>() { @Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); } }; state.onTerminated = state.onAdded; return new ClearableBehaviorSubject<T>(state, state); }
/** * Creates a {@link ClearableBehaviorSubject} that emits the last item it observed and all subsequent items to each * {@link rx.Observer} that subscribes to it. * * @param <T> * the type of item the Subject will emit * @param defaultValue * the item that will be emitted first to any {@link rx.Observer} as long as the * {@link ClearableBehaviorSubject} has not yet observed any items from its source {@code Observable} * @return the constructed {@link ClearableBehaviorSubject} */ public static <T> ClearableBehaviorSubject<T> create(T defaultValue) { return create(defaultValue, true); } private static <T> ClearableBehaviorSubject<T> create(T defaultValue, boolean hasDefault) {