|
13 | 13 |
|
14 | 14 | package io.reactivex.internal.fuseable;
|
15 | 15 |
|
16 |
| -import io.reactivex.annotations.Nullable; |
| 16 | +import io.reactivex.annotations.*; |
17 | 17 |
|
18 | 18 | /**
|
19 | 19 | * A minimalist queue interface without the method bloat of java.util.Collection and java.util.Queue.
|
|
22 | 22 | */
|
23 | 23 | public interface SimpleQueue<T> {
|
24 | 24 |
|
25 |
| - boolean offer(T value); |
| 25 | + /** |
| 26 | + * Atomically enqueue a single. |
| 27 | + * @param value the value to enqueue, not null |
| 28 | + * @return true if successful, false if the value was not enqueued |
| 29 | + * likely due to reaching the queue capacity) |
| 30 | + */ |
| 31 | + boolean offer(@NonNull T value); |
26 | 32 |
|
27 |
| - boolean offer(T v1, T v2); |
| 33 | + /** |
| 34 | + * Atomically enqueue two values. |
| 35 | + * @param v1 the first value to enqueue, not null |
| 36 | + * @param v2 the second value to enqueue, not null |
| 37 | + * @return true if successful, false if the value was not enqueued |
| 38 | + * likely due to reaching the queue capacity) |
| 39 | + */ |
| 40 | + boolean offer(@NonNull T v1, @NonNull T v2); |
28 | 41 |
|
29 | 42 | /**
|
30 |
| - * @return null to indicate an empty queue |
| 43 | + * Tries to dequeue a value (non-null) or returns null if |
| 44 | + * the queue is empty. |
| 45 | + * <p> |
| 46 | + * If the producer uses {@link #offer(Object, Object)} and |
| 47 | + * when polling in pairs, if the first poll() returns a non-null |
| 48 | + * item, the second poll() is guaranteed to return a non-null item |
| 49 | + * as well. |
| 50 | + * @return the item or null to indicate an empty queue |
| 51 | + * @throws Exception if some pre-processing of the dequeued |
| 52 | + * item (usually through fused functions) throws. |
31 | 53 | */
|
32 | 54 | @Nullable
|
33 | 55 | T poll() throws Exception;
|
34 | 56 |
|
| 57 | + /** |
| 58 | + * Returns true if the queue is empty. |
| 59 | + * <p> |
| 60 | + * Note however that due to potential fused functions in {@link #poll()} |
| 61 | + * it is possible this method returns false but then poll() returns null |
| 62 | + * because the fused function swallowed the available item(s). |
| 63 | + * @return true if the queue is empty |
| 64 | + */ |
35 | 65 | boolean isEmpty();
|
36 | 66 |
|
| 67 | + /** |
| 68 | + * Removes all enqueued items from this queue. |
| 69 | + */ |
37 | 70 | void clear();
|
38 | 71 | }
|
0 commit comments