56
56
import rx .operators .OperationOnErrorResumeNextViaFunction ;
57
57
import rx .operators .OperationOnErrorResumeNextViaObservable ;
58
58
import rx .operators .OperationOnErrorReturn ;
59
+ import rx .operators .OperationSample ;
59
60
import rx .operators .OperationScan ;
60
61
import rx .operators .OperationSkip ;
61
62
import rx .operators .OperationSubscribeOn ;
@@ -252,13 +253,15 @@ public Subscription subscribe(final Map<String, Object> callbacks) {
252
253
*/
253
254
return protectivelyWrapAndSubscribe (new Observer () {
254
255
256
+ @ Override
255
257
public void onCompleted () {
256
258
Object onComplete = callbacks .get ("onCompleted" );
257
259
if (onComplete != null ) {
258
260
Functions .from (onComplete ).call ();
259
261
}
260
262
}
261
263
264
+ @ Override
262
265
public void onError (Exception e ) {
263
266
handleError (e );
264
267
Object onError = callbacks .get ("onError" );
@@ -267,6 +270,7 @@ public void onError(Exception e) {
267
270
}
268
271
}
269
272
273
+ @ Override
270
274
public void onNext (Object args ) {
271
275
onNext .call (args );
272
276
}
@@ -298,15 +302,18 @@ public Subscription subscribe(final Object o) {
298
302
*/
299
303
return protectivelyWrapAndSubscribe (new Observer () {
300
304
305
+ @ Override
301
306
public void onCompleted () {
302
307
// do nothing
303
308
}
304
309
310
+ @ Override
305
311
public void onError (Exception e ) {
306
312
handleError (e );
307
313
// no callback defined
308
314
}
309
315
316
+ @ Override
310
317
public void onNext (Object args ) {
311
318
onNext .call (args );
312
319
}
@@ -327,15 +334,18 @@ public Subscription subscribe(final Action1<T> onNext) {
327
334
*/
328
335
return protectivelyWrapAndSubscribe (new Observer <T >() {
329
336
337
+ @ Override
330
338
public void onCompleted () {
331
339
// do nothing
332
340
}
333
341
342
+ @ Override
334
343
public void onError (Exception e ) {
335
344
handleError (e );
336
345
// no callback defined
337
346
}
338
347
348
+ @ Override
339
349
public void onNext (T args ) {
340
350
if (onNext == null ) {
341
351
throw new RuntimeException ("onNext must be implemented" );
@@ -365,17 +375,20 @@ public Subscription subscribe(final Object onNext, final Object onError) {
365
375
*/
366
376
return protectivelyWrapAndSubscribe (new Observer () {
367
377
378
+ @ Override
368
379
public void onCompleted () {
369
380
// do nothing
370
381
}
371
382
383
+ @ Override
372
384
public void onError (Exception e ) {
373
385
handleError (e );
374
386
if (onError != null ) {
375
387
Functions .from (onError ).call (e );
376
388
}
377
389
}
378
390
391
+ @ Override
379
392
public void onNext (Object args ) {
380
393
onNextFunction .call (args );
381
394
}
@@ -396,17 +409,20 @@ public Subscription subscribe(final Action1<T> onNext, final Action1<Exception>
396
409
*/
397
410
return protectivelyWrapAndSubscribe (new Observer <T >() {
398
411
412
+ @ Override
399
413
public void onCompleted () {
400
414
// do nothing
401
415
}
402
416
417
+ @ Override
403
418
public void onError (Exception e ) {
404
419
handleError (e );
405
420
if (onError != null ) {
406
421
onError .call (e );
407
422
}
408
423
}
409
424
425
+ @ Override
410
426
public void onNext (T args ) {
411
427
if (onNext == null ) {
412
428
throw new RuntimeException ("onNext must be implemented" );
@@ -436,19 +452,22 @@ public Subscription subscribe(final Object onNext, final Object onError, final O
436
452
*/
437
453
return protectivelyWrapAndSubscribe (new Observer () {
438
454
455
+ @ Override
439
456
public void onCompleted () {
440
457
if (onComplete != null ) {
441
458
Functions .from (onComplete ).call ();
442
459
}
443
460
}
444
461
462
+ @ Override
445
463
public void onError (Exception e ) {
446
464
handleError (e );
447
465
if (onError != null ) {
448
466
Functions .from (onError ).call (e );
449
467
}
450
468
}
451
469
470
+ @ Override
452
471
public void onNext (Object args ) {
453
472
onNextFunction .call (args );
454
473
}
@@ -469,17 +488,20 @@ public Subscription subscribe(final Action1<T> onNext, final Action1<Exception>
469
488
*/
470
489
return protectivelyWrapAndSubscribe (new Observer <T >() {
471
490
491
+ @ Override
472
492
public void onCompleted () {
473
493
onComplete .call ();
474
494
}
475
495
496
+ @ Override
476
497
public void onError (Exception e ) {
477
498
handleError (e );
478
499
if (onError != null ) {
479
500
onError .call (e );
480
501
}
481
502
}
482
503
504
+ @ Override
483
505
public void onNext (T args ) {
484
506
if (onNext == null ) {
485
507
throw new RuntimeException ("onNext must be implemented" );
@@ -516,10 +538,12 @@ public void forEach(final Action1<T> onNext) {
516
538
* See https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline 6.4: Protect calls to user code from within an operator"
517
539
*/
518
540
protectivelyWrapAndSubscribe (new Observer <T >() {
541
+ @ Override
519
542
public void onCompleted () {
520
543
latch .countDown ();
521
544
}
522
545
546
+ @ Override
523
547
public void onError (Exception e ) {
524
548
/*
525
549
* If we receive an onError event we set the reference on the outer thread
@@ -531,6 +555,7 @@ public void onError(Exception e) {
531
555
latch .countDown ();
532
556
}
533
557
558
+ @ Override
534
559
public void onNext (T args ) {
535
560
onNext .call (args );
536
561
}
@@ -582,6 +607,7 @@ public void forEach(final Object o) {
582
607
583
608
forEach (new Action1 () {
584
609
610
+ @ Override
585
611
public void call (Object args ) {
586
612
onNext .call (args );
587
613
}
@@ -2743,6 +2769,7 @@ public Observable<T> filter(final Object callback) {
2743
2769
final FuncN _f = Functions .from (callback );
2744
2770
return filter (this , new Func1 <T , Boolean >() {
2745
2771
2772
+ @ Override
2746
2773
public Boolean call (T t1 ) {
2747
2774
return (Boolean ) _f .call (t1 );
2748
2775
}
@@ -2913,6 +2940,7 @@ public <R> Observable<R> map(final Object callback) {
2913
2940
final FuncN _f = Functions .from (callback );
2914
2941
return map (this , new Func1 <T , R >() {
2915
2942
2943
+ @ Override
2916
2944
@ SuppressWarnings ("unchecked" )
2917
2945
public R call (T t1 ) {
2918
2946
return (R ) _f .call (t1 );
@@ -2963,6 +2991,7 @@ public <R> Observable<R> mapMany(final Object callback) {
2963
2991
final FuncN _f = Functions .from (callback );
2964
2992
return mapMany (this , new Func1 <T , Observable <R >>() {
2965
2993
2994
+ @ Override
2966
2995
@ SuppressWarnings ("unchecked" )
2967
2996
public Observable <R > call (T t1 ) {
2968
2997
return (Observable <R >) _f .call (t1 );
@@ -3071,6 +3100,7 @@ public Observable<T> onErrorResumeNext(final Object resumeFunction) {
3071
3100
final FuncN _f = Functions .from (resumeFunction );
3072
3101
return onErrorResumeNext (this , new Func1 <Exception , Observable <T >>() {
3073
3102
3103
+ @ Override
3074
3104
@ SuppressWarnings ("unchecked" )
3075
3105
public Observable <T > call (Exception e ) {
3076
3106
return (Observable <T >) _f .call (e );
@@ -3152,6 +3182,7 @@ public Observable<T> onErrorReturn(final Object resumeFunction) {
3152
3182
final FuncN _f = Functions .from (resumeFunction );
3153
3183
return onErrorReturn (this , new Func1 <Exception , T >() {
3154
3184
3185
+ @ Override
3155
3186
@ SuppressWarnings ("unchecked" )
3156
3187
public T call (Exception e ) {
3157
3188
return (T ) _f .call (e );
@@ -3288,6 +3319,34 @@ public Observable<T> scan(Func2<T, T, T> accumulator) {
3288
3319
return scan (this , accumulator );
3289
3320
}
3290
3321
3322
+ /**
3323
+ * Samples the observable sequence at each interval.
3324
+ *
3325
+ * @param period
3326
+ * The period of time that defines the sampling rate.
3327
+ * @param unit
3328
+ * The time unit for the sampling rate time period.
3329
+ * @return An observable sequence whose elements are the results of sampling the current observable sequence.
3330
+ */
3331
+ public Observable <T > sample (long period , TimeUnit unit ) {
3332
+ return create (OperationSample .sample (this , period , unit ));
3333
+ }
3334
+
3335
+ /**
3336
+ * Samples the observable sequence at each interval.
3337
+ *
3338
+ * @param period
3339
+ * The period of time that defines the sampling rate.
3340
+ * @param unit
3341
+ * The time unit for the sampling rate time period.
3342
+ * @param scheduler
3343
+ * The scheduler to use for sampling.
3344
+ * @return An observable sequence whose elements are the results of sampling the current observable sequence.
3345
+ */
3346
+ public Observable <T > sample (long period , TimeUnit unit , Scheduler scheduler ) {
3347
+ return create (OperationSample .sample (this , period , unit , scheduler ));
3348
+ }
3349
+
3291
3350
/**
3292
3351
* Returns an Observable that applies a function of your choosing to the first item emitted by a
3293
3352
* source Observable, then feeds the result of that function along with the second item emitted
0 commit comments