| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.flowables; |
| 15 |
|
| 16 |
import io.reactivex.rxjava3.annotations.Nullable; |
| 17 |
import io.reactivex.rxjava3.core.Flowable; |
| 18 |
|
| 19 |
/** |
| 20 |
* A {@link Flowable} that has been grouped by key, the value of which can be obtained with {@link #getKey()}. |
| 21 |
* <p> |
| 22 |
* <em>Note:</em> A {@link GroupedFlowable} will cache the items it is to emit until such time as it |
| 23 |
* is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore those |
| 24 |
* {@code GroupedFlowable}s that do not concern you. Instead, you can signal to them that they |
| 25 |
* may discard their buffers by applying an operator like {@link Flowable#take take}{@code (0)} to them. |
| 26 |
* |
| 27 |
* @param <K> |
| 28 |
* the type of the key |
| 29 |
* @param <T> |
| 30 |
* the type of the items emitted by the {@code GroupedFlowable} |
| 31 |
* @see Flowable#groupBy(io.reactivex.rxjava3.functions.Function) |
| 32 |
* @see <a href="http://reactivex.io/documentation/operators/groupby.html">ReactiveX documentation: GroupBy</a> |
| 33 |
*/ |
| 34 |
public abstract class GroupedFlowable<K, T> extends Flowable<T> { |
| 35 |
|
| 36 |
final K key; |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructs a GroupedFlowable with the given key. |
| 40 |
* @param key the key |
| 41 |
*/ |
| 42 |
protected GroupedFlowable(@Nullable K key) { |
| 43 |
this.key = key; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the key that identifies the group of items emitted by this {@code GroupedFlowable}. |
| 48 |
* |
| 49 |
* @return the key that the items emitted by this {@code GroupedFlowable} were grouped by |
| 50 |
*/ |
| 51 |
@Nullable |
| 52 |
public K getKey() { |
| 53 |
return key; |
| 54 |
} |
| 55 |
} |