Skip to content

Commit 976ef36

Browse files
committed
Added the min and max operators in Observable and comments
1 parent e844de5 commit 976ef36

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
import rx.operators.OperationLast;
5353
import rx.operators.OperationMap;
5454
import rx.operators.OperationMaterialize;
55+
import rx.operators.OperationMax;
5556
import rx.operators.OperationMerge;
5657
import rx.operators.OperationMergeDelayError;
58+
import rx.operators.OperationMin;
5759
import rx.operators.OperationMulticast;
5860
import rx.operators.OperationObserveOn;
5961
import rx.operators.OperationOnErrorResumeNextViaFunction;
@@ -3631,6 +3633,114 @@ public static Observable<Double> averageDoubles(Observable<Double> source) {
36313633
return OperationAverage.averageDoubles(source);
36323634
}
36333635

3636+
/**
3637+
* Returns the minimum element in an observable sequence.
3638+
* For an empty source, it causes an {@link UnsupportedOperationException}.
3639+
*
3640+
* @param source
3641+
* an observable sequence to determine the minimum element of.
3642+
* @return an observable emitting the minimum element.
3643+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229715(v=vs.103).aspx">MSDN: Observable.Min</a>
3644+
*/
3645+
public static <T extends Comparable<T>> Observable<T> min(Observable<T> source) {
3646+
return OperationMin.min(source);
3647+
}
3648+
3649+
/**
3650+
* Returns the minimum element in an observable sequence according to the specified comparator.
3651+
* For an empty source, it causes an {@link UnsupportedOperationException}.
3652+
*
3653+
* @param comparator
3654+
* the comparer used to compare elements.
3655+
* @return an observable emitting the minimum value according to the specified comparator.
3656+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229095(v=vs.103).aspx">MSDN: Observable.Min</a>
3657+
*/
3658+
public Observable<T> min(Comparator<T> comparator) {
3659+
return OperationMin.min(this, comparator);
3660+
}
3661+
3662+
/**
3663+
* Returns the elements in an observable sequence with the minimum key value.
3664+
* For an empty source, it returns an observable emitting an empty List.
3665+
*
3666+
* @param selector
3667+
* the key selector function.
3668+
* @return an observable emitting a List of the elements with the minimum key value.
3669+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh228970(v=vs.103).aspx">MSDN: Observable.MinBy</a>
3670+
*/
3671+
public <R extends Comparable<R>> Observable<List<T>> minBy(Func1<T, R> selector) {
3672+
return OperationMin.minBy(this, selector);
3673+
}
3674+
3675+
/**
3676+
* Returns the elements in an observable sequence with the minimum key value according to the specified comparator.
3677+
* For an empty source, it returns an observable emitting an empty List.
3678+
*
3679+
* @param selector
3680+
* the key selector function.
3681+
* @param comparator
3682+
* the comparator used to compare key values.
3683+
* @return an observable emitting a List of the elements with the minimum key value according to the specified comparator.
3684+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh228970(v=vs.103).aspx">MSDN: Observable.MinBy</a>
3685+
*/
3686+
public <R> Observable<List<T>> minBy(Func1<T, R> selector, Comparator<R> comparator) {
3687+
return OperationMin.minBy(this, selector, comparator);
3688+
}
3689+
3690+
/**
3691+
* Returns the maximum element in an observable sequence.
3692+
* For an empty source, it causes an {@link UnsupportedOperationException}.
3693+
*
3694+
* @param source
3695+
* an observable sequence to determine the maximum element of.
3696+
* @return an observable emitting the maximum element.
3697+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211837(v=vs.103).aspx">MSDN: Observable.Max</a>
3698+
*/
3699+
public static <T extends Comparable<T>> Observable<T> max(Observable<T> source) {
3700+
return OperationMax.max(source);
3701+
}
3702+
3703+
/**
3704+
* Returns the maximum element in an observable sequence according to the specified comparator.
3705+
* For an empty source, it causes an {@link UnsupportedOperationException}.
3706+
*
3707+
* @param comparator
3708+
* the comparer used to compare elements.
3709+
* @return an observable emitting the maximum value according to the specified comparator.
3710+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211635(v=vs.103).aspx">MSDN: Observable.Max</a>
3711+
*/
3712+
public Observable<T> max(Comparator<T> comparator) {
3713+
return OperationMax.max(this, comparator);
3714+
}
3715+
3716+
/**
3717+
* Returns the elements in an observable sequence with the maximum key value.
3718+
* For an empty source, it returns an observable emitting an empty List.
3719+
*
3720+
* @param selector
3721+
* the key selector function.
3722+
* @return an observable emitting a List of the elements with the maximum key value.
3723+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229058(v=vs.103).aspx">MSDN: Observable.MaxBy</a>
3724+
*/
3725+
public <R extends Comparable<R>> Observable<List<T>> maxBy(Func1<T, R> selector) {
3726+
return OperationMax.maxBy(this, selector);
3727+
}
3728+
3729+
/**
3730+
* Returns the elements in an observable sequence with the maximum key value according to the specified comparator.
3731+
* For an empty source, it returns an observable emitting an empty List.
3732+
*
3733+
* @param selector
3734+
* the key selector function.
3735+
* @param comparator
3736+
* the comparator used to compare key values.
3737+
* @return an observable emitting a List of the elements with the maximum key value according to the specified comparator.
3738+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh244330(v=vs.103).aspx">MSDN: Observable.MaxBy</a>
3739+
*/
3740+
public <R> Observable<List<T>> maxBy(Func1<T, R> selector, Comparator<R> comparator) {
3741+
return OperationMax.maxBy(this, selector, comparator);
3742+
}
3743+
36343744
/**
36353745
* Returns a {@link ConnectableObservable} that shares a single subscription to the underlying
36363746
* Observable that will replay all of its items and notifications to any future {@link Observer}.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import rx.util.functions.Func1;
3434
import rx.util.functions.Func2;
3535

36+
/**
37+
* Returns the maximum element in an observable sequence.
38+
*/
3639
public class OperationMax {
3740

3841
public static <T extends Comparable<T>> Observable<T> max(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import rx.util.functions.Func1;
3434
import rx.util.functions.Func2;
3535

36+
/**
37+
* Returns the minimum element in an observable sequence.
38+
*/
3639
public class OperationMin {
3740

3841
public static <T extends Comparable<T>> Observable<T> min(

0 commit comments

Comments
 (0)