Indicates that a task or resource can be cancelled/disposed. Call to the dispose method is/should be idempotent.
| 26 | * <p>Call to the dispose method is/should be idempotent. |
| 27 | */ |
| 28 | @FunctionalInterface |
| 29 | public interface Disposable { |
| 30 | |
| 31 | /** |
| 32 | * Cancel or dispose the underlying task or resource. |
| 33 | * <p> |
| 34 | * Implementations are required to make this method idempotent. |
| 35 | */ |
| 36 | void dispose(); |
| 37 | |
| 38 | /** |
| 39 | * Optionally return {@literal true} when the resource or task is disposed. |
| 40 | * <p> |
| 41 | * Implementations are not required to track disposition and as such may never |
| 42 | * return {@literal true} even when disposed. However, they MUST only return true |
| 43 | * when there's a guarantee the resource or task is disposed. |
| 44 | * |
| 45 | * @return {@literal true} when there's a guarantee the resource or task is disposed. |
| 46 | */ |
| 47 | default boolean isDisposed() { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * A {@link Disposable} container that allows updating/replacing its inner Disposable |
| 53 | * atomically and with respect of disposing the container itself. |
| 54 | * |
| 55 | * @author Simon Baslé |
| 56 | */ |
| 57 | interface Swap extends Disposable, Supplier<Disposable> { |
| 58 | |
| 59 | /** |
| 60 | * Atomically set the next {@link Disposable} on this container and dispose the previous |
| 61 | * one (if any). If the container has been disposed, fall back to disposing {@code next}. |
| 62 | * |
| 63 | * @param next the {@link Disposable} to set, may be null |
| 64 | * @return true if the operation succeeded, false if the container has been disposed |
| 65 | * @see #replace(Disposable) |
| 66 | */ |
| 67 | boolean update(@Nullable Disposable next); |
| 68 | |
| 69 | /** |
| 70 | * Atomically set the next {@link Disposable} on this container but don't dispose the previous |
| 71 | * one (if any). If the container has been disposed, fall back to disposing {@code next}. |
| 72 | * |
| 73 | * @param next the {@link Disposable} to set, may be null |
| 74 | * @return true if the operation succeeded, false if the container has been disposed |
| 75 | * @see #update(Disposable) |
| 76 | */ |
| 77 | boolean replace(@Nullable Disposable next); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * A container of {@link Disposable} that is itself {@link Disposable}. Accumulate |
| 82 | * disposables and dispose them all in one go by using {@link #dispose()}. Using |
| 83 | * the {@link #add(Disposable)} methods give ownership to the container, which is now |
| 84 | * responsible for disposing them. You can however retake ownership of individual |
| 85 | * elements by keeping a reference and using {@link #remove(Disposable)}, which puts |
no outgoing calls
no test coverage detected
searching dependent graphs…