Skip to content

Commit 4cb4fed

Browse files
committed
Rename Subject to PublishSubject
1 parent f1c54b5 commit 4cb4fed

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

rxjava-core/src/main/java/rx/operators/OperationTake.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
import rx.Observable;
2727
import rx.Observer;
2828
import rx.Subscription;
29+
import rx.subjects.PublishSubject;
2930
import rx.util.AtomicObservableSubscription;
3031
import rx.util.functions.Func1;
3132
import rx.util.functions.Func2;
32-
import rx.subjects.Subject;
33+
3334
/**
3435
* Returns a specified number of contiguous values from the start of an observable sequence.
3536
*/
@@ -181,11 +182,13 @@ public Boolean call(Integer input) {
181182

182183
@Test
183184
public void testTakeWhileOnSubject1() {
184-
Subject<Integer> s = Subject.create();
185+
PublishSubject<Integer> s = PublishSubject.create();
185186
Observable<Integer> w = (Observable<Integer>)s;
186-
Observable<Integer> take = Observable.create(takeWhile(w, new Func1<Integer, Boolean>() {
187+
Observable<Integer> take = Observable.create(takeWhile(w, new Func1<Integer, Boolean>()
188+
{
187189
@Override
188-
public Boolean call(Integer input) {
190+
public Boolean call(Integer input)
191+
{
189192
return input < 3;
190193
}
191194
}));
@@ -213,9 +216,11 @@ public Boolean call(Integer input) {
213216
@Test
214217
public void testTakeWhile2() {
215218
Observable<String> w = Observable.toObservable("one", "two", "three");
216-
Observable<String> take = Observable.create(takeWhileWithIndex(w, new Func2<String, Integer, Boolean>() {
219+
Observable<String> take = Observable.create(takeWhileWithIndex(w, new Func2<String, Integer, Boolean>()
220+
{
217221
@Override
218-
public Boolean call(String input, Integer index) {
222+
public Boolean call(String input, Integer index)
223+
{
219224
return index < 2;
220225
}
221226
}));

rxjava-core/src/main/java/rx/subjects/Subject.java renamed to rxjava-core/src/main/java/rx/subjects/PublishSubject.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import rx.util.functions.Action1;
2020
import rx.util.functions.Func1;
2121

22-
public class Subject<T> extends Observable<T> implements Observer<T> {
23-
public static <T> Subject<T> create() {
22+
public class PublishSubject<T> extends Observable<T> implements Observer<T> {
23+
public static <T> PublishSubject<T> create() {
2424
final ConcurrentHashMap<Subscription, Observer<T>> observers = new ConcurrentHashMap<Subscription, Observer<T>>();
2525

2626
Func1<Observer<T>, Subscription> onSubscribe = new Func1<Observer<T>, Subscription>() {
@@ -42,12 +42,12 @@ public void unsubscribe() {
4242
}
4343
};
4444

45-
return new Subject<T>(onSubscribe, observers);
45+
return new PublishSubject<T>(onSubscribe, observers);
4646
}
4747

4848
private final ConcurrentHashMap<Subscription, Observer<T>> observers;
4949

50-
protected Subject(Func1<Observer<T>, Subscription> onSubscribe, ConcurrentHashMap<Subscription, Observer<T>> observers) {
50+
protected PublishSubject(Func1<Observer<T>, Subscription> onSubscribe, ConcurrentHashMap<Subscription, Observer<T>> observers) {
5151
super(onSubscribe);
5252
this.observers = observers;
5353
}
@@ -76,10 +76,10 @@ public void onNext(T args) {
7676
public static class UnitTest {
7777
@Test
7878
public void test() {
79-
Subject<Integer> subject = Subject.create();
79+
PublishSubject<Integer> publishSubject = PublishSubject.create();
8080
final AtomicReference<List<Notification<String>>> actualRef = new AtomicReference<List<Notification<String>>>();
8181

82-
Observable<List<Notification<Integer>>> wNotificationsList = subject.materialize().toList();
82+
Observable<List<Notification<Integer>>> wNotificationsList = publishSubject.materialize().toList();
8383
wNotificationsList.subscribe(new Action1<List<Notification<String>>>() {
8484
@Override
8585
public void call(List<Notification<String>> actual) {
@@ -108,10 +108,10 @@ public void unsubscribe() {
108108
}
109109
};
110110
}
111-
}).subscribe(subject);
112-
// the subject has received an onComplete from the first subscribe because
111+
}).subscribe(publishSubject);
112+
// the publishSubject has received an onComplete from the first subscribe because
113113
// it is synchronous and the next subscribe won't do anything.
114-
Observable.toObservable(-1, -2, -3).subscribe(subject);
114+
Observable.toObservable(-1, -2, -3).subscribe(publishSubject);
115115

116116
List<Notification<Integer>> expected = new ArrayList<Notification<Integer>>();
117117
expected.add(new Notification<Integer>(-1));

0 commit comments

Comments
 (0)