@@ -61,30 +61,36 @@ public void call(Subscriber<? super R> t1) {
61
61
}
62
62
63
63
/** Manage the left and right sources. */
64
- final class ResultSink {
64
+ final class ResultSink extends HashMap <Integer ,TLeft > {
65
+ //HashMap aspect of `this` refers to the `leftMap`
66
+
67
+ private static final long serialVersionUID = 3491669543549085380L ;
68
+
65
69
final CompositeSubscription group ;
66
70
final Subscriber <? super R > subscriber ;
67
- final Object guard = new Object ();
68
- /** Guarded by guard. */
71
+ /** Guarded by this. */
69
72
boolean leftDone ;
70
- /** Guarded by guard . */
73
+ /** Guarded by this . */
71
74
int leftId ;
72
- /** Guarded by guard. */
73
- final Map <Integer , TLeft > leftMap ;
74
- /** Guarded by guard. */
75
+ /** Guarded by this. */
75
76
boolean rightDone ;
76
- /** Guarded by guard . */
77
+ /** Guarded by this . */
77
78
int rightId ;
78
- /** Guarded by guard . */
79
+ /** Guarded by this . */
79
80
final Map <Integer , TRight > rightMap ;
80
81
81
82
public ResultSink (Subscriber <? super R > subscriber ) {
83
+ super ();
82
84
this .subscriber = subscriber ;
83
85
this .group = new CompositeSubscription ();
84
- this . leftMap = new HashMap < Integer , TLeft >();
86
+ //` leftMap` is `this`
85
87
this .rightMap = new HashMap <Integer , TRight >();
86
88
}
87
89
90
+ HashMap <Integer , TLeft > leftMap () {
91
+ return this ;
92
+ }
93
+
88
94
public void run () {
89
95
subscriber .add (group );
90
96
@@ -103,8 +109,8 @@ final class LeftSubscriber extends Subscriber<TLeft> {
103
109
104
110
protected void expire (int id , Subscription resource ) {
105
111
boolean complete = false ;
106
- synchronized (guard ) {
107
- if (leftMap .remove (id ) != null && leftMap .isEmpty () && leftDone ) {
112
+ synchronized (ResultSink . this ) {
113
+ if (leftMap () .remove (id ) != null && leftMap () .isEmpty () && leftDone ) {
108
114
complete = true ;
109
115
}
110
116
}
@@ -121,9 +127,9 @@ public void onNext(TLeft args) {
121
127
int id ;
122
128
int highRightId ;
123
129
124
- synchronized (guard ) {
130
+ synchronized (ResultSink . this ) {
125
131
id = leftId ++;
126
- leftMap .put (id , args );
132
+ leftMap () .put (id , args );
127
133
highRightId = rightId ;
128
134
}
129
135
@@ -137,7 +143,7 @@ public void onNext(TLeft args) {
137
143
duration .unsafeSubscribe (d1 );
138
144
139
145
List <TRight > rightValues = new ArrayList <TRight >();
140
- synchronized (guard ) {
146
+ synchronized (ResultSink . this ) {
141
147
for (Map .Entry <Integer , TRight > entry : rightMap .entrySet ()) {
142
148
if (entry .getKey () < highRightId ) {
143
149
rightValues .add (entry .getValue ());
@@ -162,9 +168,9 @@ public void onError(Throwable e) {
162
168
@ Override
163
169
public void onCompleted () {
164
170
boolean complete = false ;
165
- synchronized (guard ) {
171
+ synchronized (ResultSink . this ) {
166
172
leftDone = true ;
167
- if (rightDone || leftMap .isEmpty ()) {
173
+ if (rightDone || leftMap () .isEmpty ()) {
168
174
complete = true ;
169
175
}
170
176
}
@@ -211,7 +217,7 @@ final class RightSubscriber extends Subscriber<TRight> {
211
217
212
218
void expire (int id , Subscription resource ) {
213
219
boolean complete = false ;
214
- synchronized (guard ) {
220
+ synchronized (ResultSink . this ) {
215
221
if (rightMap .remove (id ) != null && rightMap .isEmpty () && rightDone ) {
216
222
complete = true ;
217
223
}
@@ -228,7 +234,7 @@ void expire(int id, Subscription resource) {
228
234
public void onNext (TRight args ) {
229
235
int id ;
230
236
int highLeftId ;
231
- synchronized (guard ) {
237
+ synchronized (ResultSink . this ) {
232
238
id = rightId ++;
233
239
rightMap .put (id , args );
234
240
highLeftId = leftId ;
@@ -247,8 +253,8 @@ public void onNext(TRight args) {
247
253
248
254
249
255
List <TLeft > leftValues = new ArrayList <TLeft >();
250
- synchronized (guard ) {
251
- for (Map .Entry <Integer , TLeft > entry : leftMap .entrySet ()) {
256
+ synchronized (ResultSink . this ) {
257
+ for (Map .Entry <Integer , TLeft > entry : leftMap () .entrySet ()) {
252
258
if (entry .getKey () < highLeftId ) {
253
259
leftValues .add (entry .getValue ());
254
260
}
@@ -274,7 +280,7 @@ public void onError(Throwable e) {
274
280
@ Override
275
281
public void onCompleted () {
276
282
boolean complete = false ;
277
- synchronized (guard ) {
283
+ synchronized (ResultSink . this ) {
278
284
rightDone = true ;
279
285
if (leftDone || rightMap .isEmpty ()) {
280
286
complete = true ;
0 commit comments