@Test public void testAddSourceToActive() { mSource.setValue("flatfoot"); Observer observer = mock(Observer.class); mMediator.addSource(mSource, observer); verify(observer).onChanged("flatfoot"); }
@MainThread public <S> void addSource(LiveData<S> source, Observer<S> onChanged) { Source<S> e = new Source<>(source, onChanged); Source<?> existing = mSources.putIfAbsent(source, e); if (existing != null && existing.mObserver != onChanged) { throw new IllegalArgumentException( "This source was already added with the different observer"); } if (existing != null) { return; } if (hasActiveObservers()) { e.plug(); } }
MediatorLiveData extends MutableLiveData<T> { @MainThread public <S> void addSource(LiveData<S> source, Observer<S> onChanged) { Source<S> e = new Source<>(source, onChanged); Source<?> existing = mSources.putIfAbsent(source, e); if (existing != null && existing.mObserver != onChanged) { throw new IllegalArgumentException( "This source was already added with the different observer"); } if (existing != null) { return; } if (hasActiveObservers()) { e.plug(); } } }
MediatorLiveData extends MutableLiveData<T> { @MainThread public <S> void addSource(LiveData<S> source, Observer<S> onChanged) { Source<S> e = new Source<>(source, onChanged); Source<?> existing = mSources.putIfAbsent(source, e); if (existing != null && existing.mObserver != onChanged) { throw new IllegalArgumentException( "This source was already added with the different observer"); } if (existing != null) { return; } if (hasActiveObservers()) { e.plug(); } }  }
MediatorLiveData extends MutableLiveData<T> { @MainThread public <S> void addSource(LiveData<S> source, Observer<S> onChanged) { Source<S> e = new Source<>(source, onChanged); Source<?> existing = mSources.putIfAbsent(source, e); if (existing != null && existing.mObserver != onChanged) { throw new IllegalArgumentException( "This source was already added with the different observer"); } if (existing != null) { return; } if (hasActiveObservers()) { e.plug(); } }  @MainThread void addSource(LiveData<S> source, Observer<S> onChanged); @MainThread void removeSource(LiveData<S> toRemote); }
MediatorLiveData extends MutableLiveData<T> { @MainThread public <S> void addSource(LiveData<S> source, Observer<S> onChanged) { Source<S> e = new Source<>(source, onChanged); Source<?> existing = mSources.putIfAbsent(source, e); if (existing != null && existing.mObserver != onChanged) { throw new IllegalArgumentException( "This source was already added with the different observer"); } if (existing != null) { return; } if (hasActiveObservers()) { e.plug(); } }  @MainThread void addSource(LiveData<S> source, Observer<S> onChanged); @MainThread void removeSource(LiveData<S> toRemote);  }