@@ -7011,9 +7011,25 @@ public final <T2> Observable<T2> dematerialize() {
7011
7011
}
7012
7012
7013
7013
/**
7014
- * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct.
7014
+ * Returns an Observable that emits all items emitted by the source ObservableSource that are distinct
7015
+ * based on {@link Object#equals(Object)} comparison.
7015
7016
* <p>
7016
7017
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/distinct.png" alt="">
7018
+ * <p>
7019
+ * It is recommended the elements' class {@code T} in the flow overrides the default {@code Object.equals()}
7020
+ * and {@link Object#hashCode()} to provide meaningful comparison between items as the default Java
7021
+ * implementation only considers reference equivalence.
7022
+ * <p>
7023
+ * By default, {@code distinct()} uses an internal {@link java.util.HashSet} per Observer to remember
7024
+ * previously seen items and uses {@link java.util.Set#add(Object)} returning {@code false} as the
7025
+ * indicator for duplicates.
7026
+ * <p>
7027
+ * Note that this internal {@code HashSet} may grow unbounded as items won't be removed from it by
7028
+ * the operator. Therefore, using very long or infinite upstream (with very distinct elements) may lead
7029
+ * to {@code OutOfMemoryError}.
7030
+ * <p>
7031
+ * Customizing the retention policy can happen only by providing a custom {@link java.util.Collection} implementation
7032
+ * to the {@link #distinct(Function, Callable)} overload.
7017
7033
* <dl>
7018
7034
* <dt><b>Scheduler:</b></dt>
7019
7035
* <dd>{@code distinct} does not operate by default on a particular {@link Scheduler}.</dd>
@@ -7022,6 +7038,8 @@ public final <T2> Observable<T2> dematerialize() {
7022
7038
* @return an Observable that emits only those items emitted by the source ObservableSource that are distinct from
7023
7039
* each other
7024
7040
* @see <a href="http://reactivex.io/documentation/operators/distinct.html">ReactiveX operators documentation: Distinct</a>
7041
+ * @see #distinct(Function)
7042
+ * @see #distinct(Function, Callable)
7025
7043
*/
7026
7044
@CheckReturnValue
7027
7045
@SchedulerSupport(SchedulerSupport.NONE)
@@ -7031,9 +7049,25 @@ public final Observable<T> distinct() {
7031
7049
7032
7050
/**
7033
7051
* Returns an Observable that emits all items emitted by the source ObservableSource that are distinct according
7034
- * to a key selector function.
7052
+ * to a key selector function and based on {@link Object#equals(Object)} comparison of the objects
7053
+ * returned by the key selector function.
7035
7054
* <p>
7036
7055
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/distinct.key.png" alt="">
7056
+ * <p>
7057
+ * It is recommended the keys' class {@code K} overrides the default {@code Object.equals()}
7058
+ * and {@link Object#hashCode()} to provide meaningful comparison between the key objects as the default
7059
+ * Java implementation only considers reference equivalence.
7060
+ * <p>
7061
+ * By default, {@code distinct()} uses an internal {@link java.util.HashSet} per Observer to remember
7062
+ * previously seen keys and uses {@link java.util.Set#add(Object)} returning {@code false} as the
7063
+ * indicator for duplicates.
7064
+ * <p>
7065
+ * Note that this internal {@code HashSet} may grow unbounded as keys won't be removed from it by
7066
+ * the operator. Therefore, using very long or infinite upstream (with very distinct keys) may lead
7067
+ * to {@code OutOfMemoryError}.
7068
+ * <p>
7069
+ * Customizing the retention policy can happen only by providing a custom {@link java.util.Collection} implementation
7070
+ * to the {@link #distinct(Function, Callable)} overload.
7037
7071
* <dl>
7038
7072
* <dt><b>Scheduler:</b></dt>
7039
7073
* <dd>{@code distinct} does not operate by default on a particular {@link Scheduler}.</dd>
@@ -7045,6 +7079,7 @@ public final Observable<T> distinct() {
7045
7079
* is distinct from another one or not
7046
7080
* @return an Observable that emits those items emitted by the source ObservableSource that have distinct keys
7047
7081
* @see <a href="http://reactivex.io/documentation/operators/distinct.html">ReactiveX operators documentation: Distinct</a>
7082
+ * @see #distinct(Function, Callable)
7048
7083
*/
7049
7084
@CheckReturnValue
7050
7085
@SchedulerSupport(SchedulerSupport.NONE)
@@ -7054,9 +7089,14 @@ public final <K> Observable<T> distinct(Function<? super T, K> keySelector) {
7054
7089
7055
7090
/**
7056
7091
* Returns an Observable that emits all items emitted by the source ObservableSource that are distinct according
7057
- * to a key selector function.
7092
+ * to a key selector function and based on {@link Object#equals(Object)} comparison of the objects
7093
+ * returned by the key selector function.
7058
7094
* <p>
7059
7095
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/distinct.key.png" alt="">
7096
+ * <p>
7097
+ * It is recommended the keys' class {@code K} overrides the default {@code Object.equals()}
7098
+ * and {@link Object#hashCode()} to provide meaningful comparison between the key objects as
7099
+ * the default Java implementation only considers reference equivalence.
7060
7100
* <dl>
7061
7101
* <dt><b>Scheduler:</b></dt>
7062
7102
* <dd>{@code distinct} does not operate by default on a particular {@link Scheduler}.</dd>
@@ -7082,9 +7122,18 @@ public final <K> Observable<T> distinct(Function<? super T, K> keySelector, Call
7082
7122
7083
7123
/**
7084
7124
* Returns an Observable that emits all items emitted by the source ObservableSource that are distinct from their
7085
- * immediate predecessors.
7125
+ * immediate predecessors based on {@link Object#equals(Object)} comparison .
7086
7126
* <p>
7087
7127
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/distinctUntilChanged.png" alt="">
7128
+ * <p>
7129
+ * It is recommended the elements' class {@code T} in the flow overrides the default {@code Object.equals()} to provide
7130
+ * meaningful comparison between items as the default Java implementation only considers reference equivalence.
7131
+ * Alternatively, use the {@link #distinctUntilChanged(BiPredicate)} overload and provide a comparison function
7132
+ * in case the class {@code T} can't be overridden with custom {@code equals()} or the comparison itself
7133
+ * should happen on different terms or properties of the class {@code T}.
7134
+ * <p>
7135
+ * Note that the operator always retains the latest item from upstream regardless of the comparison result
7136
+ * and uses it in the next comparison with the next upstream item.
7088
7137
* <dl>
7089
7138
* <dt><b>Scheduler:</b></dt>
7090
7139
* <dd>{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.</dd>
@@ -7093,6 +7142,7 @@ public final <K> Observable<T> distinct(Function<? super T, K> keySelector, Call
7093
7142
* @return an Observable that emits those items from the source ObservableSource that are distinct from their
7094
7143
* immediate predecessors
7095
7144
* @see <a href="http://reactivex.io/documentation/operators/distinct.html">ReactiveX operators documentation: Distinct</a>
7145
+ * @see #distinctUntilChanged(BiPredicate)
7096
7146
*/
7097
7147
@CheckReturnValue
7098
7148
@SchedulerSupport(SchedulerSupport.NONE)
@@ -7102,9 +7152,20 @@ public final Observable<T> distinctUntilChanged() {
7102
7152
7103
7153
/**
7104
7154
* Returns an Observable that emits all items emitted by the source ObservableSource that are distinct from their
7105
- * immediate predecessors, according to a key selector function.
7155
+ * immediate predecessors, according to a key selector function and based on {@link Object#equals(Object)} comparison
7156
+ * of those objects returned by the key selector function.
7106
7157
* <p>
7107
7158
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/distinctUntilChanged.key.png" alt="">
7159
+ * <p>
7160
+ * It is recommended the keys' class {@code K} overrides the default {@code Object.equals()} to provide
7161
+ * meaningful comparison between the key objects as the default Java implementation only considers reference equivalence.
7162
+ * Alternatively, use the {@link #distinctUntilChanged(BiPredicate)} overload and provide a comparison function
7163
+ * in case the class {@code K} can't be overridden with custom {@code equals()} or the comparison itself
7164
+ * should happen on different terms or properties of the item class {@code T} (for which the keys can be
7165
+ * derived via a similar selector).
7166
+ * <p>
7167
+ * Note that the operator always retains the latest key from upstream regardless of the comparison result
7168
+ * and uses it in the next comparison with the next key derived from the next upstream item.
7108
7169
* <dl>
7109
7170
* <dt><b>Scheduler:</b></dt>
7110
7171
* <dd>{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.</dd>
@@ -7130,6 +7191,9 @@ public final <K> Observable<T> distinctUntilChanged(Function<? super T, K> keySe
7130
7191
* immediate predecessors when compared with each other via the provided comparator function.
7131
7192
* <p>
7132
7193
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/distinctUntilChanged.png" alt="">
7194
+ * <p>
7195
+ * Note that the operator always retains the latest item from upstream regardless of the comparison result
7196
+ * and uses it in the next comparison with the next upstream item.
7133
7197
* <dl>
7134
7198
* <dt><b>Scheduler:</b></dt>
7135
7199
* <dd>{@code distinctUntilChanged} does not operate by default on a particular {@link Scheduler}.</dd>
0 commit comments