Skip to content

Commit 56f88df

Browse files
Remove Redundant Action1 Observer Collection Argument
Since the collection is being returned we don't want to also inject it as an argument, so I migrated to Action0 from Action1 as per discussion at #972 (comment)
1 parent 210df42 commit 56f88df

File tree

6 files changed

+51
-54
lines changed

6 files changed

+51
-54
lines changed

rxjava-core/src/main/java/rx/subjects/AsyncSubject.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import rx.Notification;
2222
import rx.Observer;
23+
import rx.functions.Action0;
2324
import rx.functions.Action1;
2425
import rx.subjects.SubjectSubscriptionManager.SubjectObserver;
2526

@@ -105,11 +106,10 @@ protected AsyncSubject(OnSubscribe<T> onSubscribe, SubjectSubscriptionManager<T>
105106

106107
@Override
107108
public void onCompleted() {
108-
Collection<SubjectObserver<? super T>> observers =
109-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
109+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
110110

111111
@Override
112-
public void call(Collection<SubjectObserver<? super T>> observers) {
112+
public void call() {
113113
}
114114
});
115115
if (observers != null) {
@@ -121,11 +121,10 @@ public void call(Collection<SubjectObserver<? super T>> observers) {
121121

122122
@Override
123123
public void onError(final Throwable e) {
124-
Collection<SubjectObserver<? super T>> observers =
125-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
124+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
126125
@Override
127-
public void call(Collection<SubjectObserver<? super T>> observers) {
128-
lastNotification.set(Notification.<T>createOnError(e));
126+
public void call() {
127+
lastNotification.set(Notification.<T> createOnError(e));
129128
}
130129
});
131130
if (observers != null) {

rxjava-core/src/main/java/rx/subjects/BehaviorSubject.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import rx.Notification;
2222
import rx.Observer;
23+
import rx.functions.Action0;
2324
import rx.functions.Action1;
2425
import rx.subjects.SubjectSubscriptionManager.SubjectObserver;
2526

@@ -67,12 +68,10 @@
6768
public final class BehaviorSubject<T> extends Subject<T, T> {
6869

6970
/**
70-
* Creates a {@link BehaviorSubject} which publishes the last and all subsequent events to each
71-
* {@link Observer} that subscribes to it.
71+
* Creates a {@link BehaviorSubject} which publishes the last and all subsequent events to each {@link Observer} that subscribes to it.
7272
*
7373
* @param defaultValue
74-
* the value which will be published to any {@link Observer} as long as the
75-
* {@link BehaviorSubject} has not yet received any events
74+
* the value which will be published to any {@link Observer} as long as the {@link BehaviorSubject} has not yet received any events
7675
* @return the constructed {@link BehaviorSubject}
7776
* @deprecated use {@link #create(T)} instead
7877
*/
@@ -81,12 +80,10 @@ public static <T> BehaviorSubject<T> createWithDefaultValue(T defaultValue) {
8180
}
8281

8382
/**
84-
* Creates a {@link BehaviorSubject} which publishes the last and all subsequent events to each
85-
* {@link Observer} that subscribes to it.
83+
* Creates a {@link BehaviorSubject} which publishes the last and all subsequent events to each {@link Observer} that subscribes to it.
8684
*
8785
* @param defaultValue
88-
* the value which will be published to any {@link Observer} as long as the
89-
* {@link BehaviorSubject} has not yet received any events
86+
* the value which will be published to any {@link Observer} as long as the {@link BehaviorSubject} has not yet received any events
9087
* @return the constructed {@link BehaviorSubject}
9188
*/
9289
public static <T> BehaviorSubject<T> create(T defaultValue) {
@@ -144,12 +141,11 @@ protected BehaviorSubject(OnSubscribe<T> onSubscribe, SubjectSubscriptionManager
144141

145142
@Override
146143
public void onCompleted() {
147-
Collection<SubjectObserver<? super T>> observers =
148-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
144+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
149145

150146
@Override
151-
public void call(Collection<SubjectObserver<? super T>> observers) {
152-
lastNotification.set(Notification.<T>createOnCompleted());
147+
public void call() {
148+
lastNotification.set(Notification.<T> createOnCompleted());
153149
}
154150
});
155151
if (observers != null) {
@@ -161,12 +157,11 @@ public void call(Collection<SubjectObserver<? super T>> observers) {
161157

162158
@Override
163159
public void onError(final Throwable e) {
164-
Collection<SubjectObserver<? super T>> observers =
165-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
160+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
166161

167162
@Override
168-
public void call(Collection<SubjectObserver<? super T>> observers) {
169-
lastNotification.set(Notification.<T>createOnError(e));
163+
public void call() {
164+
lastNotification.set(Notification.<T> createOnError(e));
170165
}
171166
});
172167
if (observers != null) {

rxjava-core/src/main/java/rx/subjects/PublishSubject.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import rx.Notification;
2222
import rx.Observer;
23+
import rx.functions.Action0;
2324
import rx.functions.Action1;
2425
import rx.subjects.SubjectSubscriptionManager.SubjectObserver;
2526

@@ -95,10 +96,9 @@ protected PublishSubject(OnSubscribe<T> onSubscribe, SubjectSubscriptionManager<
9596

9697
@Override
9798
public void onCompleted() {
98-
Collection<SubjectObserver<? super T>> observers =
99-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
99+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
100100
@Override
101-
public void call(Collection<SubjectObserver<? super T>> observers) {
101+
public void call() {
102102
lastNotification.set(Notification.<T> createOnCompleted());
103103
}
104104
});
@@ -111,12 +111,11 @@ public void call(Collection<SubjectObserver<? super T>> observers) {
111111

112112
@Override
113113
public void onError(final Throwable e) {
114-
Collection<SubjectObserver<? super T>> observers =
115-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
114+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
116115

117116
@Override
118-
public void call(Collection<SubjectObserver<? super T>> observers) {
119-
lastNotification.set(Notification.<T>createOnError(e));
117+
public void call() {
118+
lastNotification.set(Notification.<T> createOnError(e));
120119
}
121120
});
122121
if (observers != null) {

rxjava-core/src/main/java/rx/subjects/ReplaySubject.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import rx.Notification;
2525
import rx.Observer;
26+
import rx.functions.Action0;
2627
import rx.functions.Action1;
2728
import rx.subjects.SubjectSubscriptionManager.SubjectObserver;
2829

@@ -88,7 +89,7 @@ public void call(SubjectObserver<? super T> o) {
8889
// we will finish replaying if there is anything left
8990
replayObserverFromIndex(state.history, idx, o);
9091
}
91-
},
92+
},
9293
new Action1<SubjectObserver<? super T>>() {
9394
@Override
9495
public void call(SubjectObserver<? super T> o) {
@@ -122,12 +123,11 @@ protected ReplaySubject(OnSubscribe<T> onSubscribe, SubjectSubscriptionManager<T
122123

123124
@Override
124125
public void onCompleted() {
125-
Collection<SubjectObserver<? super T>> observers =
126-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
126+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
127127

128128
@Override
129-
public void call(Collection<SubjectObserver<? super T>> observers) {
130-
state.history.complete(Notification.<T>createOnCompleted());
129+
public void call() {
130+
state.history.complete(Notification.<T> createOnCompleted());
131131
}
132132
});
133133
if (observers != null) {
@@ -141,12 +141,11 @@ public void call(Collection<SubjectObserver<? super T>> observers) {
141141

142142
@Override
143143
public void onError(final Throwable e) {
144-
Collection<SubjectObserver<? super T>> observers =
145-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
144+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
146145

147146
@Override
148-
public void call(Collection<SubjectObserver<? super T>> observers) {
149-
state.history.complete(Notification.<T>createOnError(e));
147+
public void call() {
148+
state.history.complete(Notification.<T> createOnError(e));
150149
}
151150
});
152151
if (observers != null) {
@@ -242,10 +241,11 @@ public void complete(Notification<T> n) {
242241
terminalValue.set(n);
243242
}
244243
}
244+
245245
/**
246246
* @return Returns the number of subscribers.
247247
*/
248-
/* Support test.*/ int subscriberCount() {
248+
/* Support test. */int subscriberCount() {
249249
return state.replayState.size();
250250
}
251251
}

rxjava-core/src/main/java/rx/subjects/SubjectSubscriptionManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void call() {
111111
}
112112

113113
@SuppressWarnings({ "unchecked", "rawtypes" })
114-
protected Collection<SubjectObserver<? super T>> terminate(Action1<Collection<SubjectObserver<? super T>>> onTerminate) {
114+
protected Collection<SubjectObserver<? super T>> terminate(Action0 onTerminate) {
115115
State<T> current;
116116
State<T> newState = null;
117117
do {
@@ -128,12 +128,11 @@ protected Collection<SubjectObserver<? super T>> terminate(Action1<Collection<Su
128128
/*
129129
* if we get here then we won setting the state to terminated
130130
* and have a deterministic set of Observers to emit to (concurrent subscribes
131-
* will have failed and will try again and see we are term
132-
* inated)
131+
* will have failed and will try again and see we are terminated)
133132
*/
134133
try {
135134
// had to circumvent type check, we know what the array contains
136-
onTerminate.call(observerCollection);
135+
onTerminate.call();
137136
} finally {
138137
// mark that termination is completed
139138
newState.terminationLatch.countDown();

rxjava-core/src/main/java/rx/subjects/TestSubject.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import rx.Observer;
2424
import rx.Scheduler;
2525
import rx.Scheduler.Inner;
26+
import rx.functions.Action0;
2627
import rx.functions.Action1;
2728
import rx.schedulers.TestScheduler;
2829
import rx.subjects.SubjectSubscriptionManager.SubjectObserver;
@@ -105,16 +106,18 @@ public void onCompleted() {
105106
}
106107

107108
private void _onCompleted() {
108-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
109+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
109110

110111
@Override
111-
public void call(Collection<SubjectObserver<? super T>> observers) {
112+
public void call() {
112113
lastNotification.set(Notification.<T> createOnCompleted());
113-
for (Observer<? super T> o : observers) {
114-
o.onCompleted();
115-
}
116114
}
117115
});
116+
if (observers != null) {
117+
for (Observer<? super T> o : observers) {
118+
o.onCompleted();
119+
}
120+
}
118121
}
119122

120123
public void onCompleted(long timeInMilliseconds) {
@@ -134,16 +137,18 @@ public void onError(final Throwable e) {
134137
}
135138

136139
private void _onError(final Throwable e) {
137-
subscriptionManager.terminate(new Action1<Collection<SubjectObserver<? super T>>>() {
140+
Collection<SubjectObserver<? super T>> observers = subscriptionManager.terminate(new Action0() {
138141

139142
@Override
140-
public void call(Collection<SubjectObserver<? super T>> observers) {
143+
public void call() {
141144
lastNotification.set(Notification.<T> createOnError(e));
142-
for (Observer<? super T> o : observers) {
143-
o.onError(e);
144-
}
145145
}
146146
});
147+
if (observers != null) {
148+
for (Observer<? super T> o : observers) {
149+
o.onError(e);
150+
}
151+
}
147152

148153
}
149154

0 commit comments

Comments
 (0)