1919import javax .annotation .Nullable ;
2020
2121import io .objectbox .annotation .apihint .Internal ;
22+ import io .objectbox .query .Query ;
2223
2324/**
2425 * Builds a {@link DataSubscription} for a {@link DataObserver} passed via {@link #observer(DataObserver)}.
2526 * Note that the call to {@link #observer(DataObserver)} is mandatory to create the subscription -
2627 * if you forget it, nothing will happen.
2728 * <p>
28- * When subscribing to a data source such as {@link io.objectbox.query. Query}, this builder allows to configure:
29+ * When subscribing to a data source such as {@link Query}, this builder allows to configure:
2930 * <ul>
3031 * <li>weakly referenced observer via {@link #weak()}</li>
3132 * <li>a data transform operation via {@link #transform(DataTransformer)}</li>
@@ -78,11 +79,21 @@ public SubscriptionBuilder<T> weak() {
7879 return this ;
7980 }
8081
82+ /**
83+ * Only deliver the latest data once, do not subscribe for data changes.
84+ *
85+ * @see #onlyChanges()
86+ */
8187 public SubscriptionBuilder <T > single () {
8288 single = true ;
8389 return this ;
8490 }
8591
92+ /**
93+ * Upon subscribing do not deliver the latest data, only once there are changes.
94+ *
95+ * @see #single()
96+ */
8697 public SubscriptionBuilder <T > onlyChanges () {
8798 onlyChanges = true ;
8899 return this ;
@@ -94,14 +105,12 @@ public SubscriptionBuilder<T> onlyChanges() {
94105 // }
95106
96107 /**
97- * Transforms the original data from the publisher to something that is more helpful to your application.
98- * The transformation is done in an asynchronous thread.
99- * The observer will be called in the same asynchronous thread unless a Scheduler is defined using
100- * {@link #on(Scheduler)}.
108+ * Transforms the original data from the publisher to some other type.
109+ * All transformations run sequentially in an asynchronous thread owned by the publisher.
101110 * <p>
102- * This is roughly equivalent to the map operator as known in Rx and Kotlin.
111+ * This is similar to the map operator of Rx and Kotlin.
103112 *
104- * @param <TO> The class the data is transformed to
113+ * @param <TO> The type data is transformed to.
105114 */
106115 public <TO > SubscriptionBuilder <TO > transform (final DataTransformer <T , TO > transformer ) {
107116 if (this .transformer != null ) {
@@ -139,11 +148,16 @@ public SubscriptionBuilder<T> on(Scheduler scheduler) {
139148 }
140149
141150 /**
142- * The given observer is subscribed to the publisher. This method MUST be called to complete a subscription.
151+ * Sets the observer for this subscription and requests the latest data to be delivered immediately
152+ * and subscribes to the publisher for data updates, unless configured differently
153+ * using {@link #single()} or {@link #onlyChanges()}.
154+ * <p>
155+ * Results are delivered on a background thread owned by the publisher,
156+ * unless a scheduler was set using {@link #on(Scheduler)}.
143157 * <p>
144- * Note: you must keep the returned {@link DataSubscription} to cancel it .
158+ * The returned {@link DataSubscription} must be canceled once the observer should no longer receive notifications .
145159 *
146- * @return an subscription object used for canceling further notifications to the observer
160+ * @return A {@link DataSubscription} to cancel further notifications to the observer.
147161 */
148162 public DataSubscription observer (DataObserver <T > observer ) {
149163 WeakDataObserver <T > weakObserver = null ;
0 commit comments