Represent possibility of value not existing, which needs to be unwrapped before using @param type of object that could possibly be missing
| 21 | * @param <T> type of object that could possibly be missing |
| 22 | */ |
| 23 | public abstract class Option<T> { |
| 24 | |
| 25 | /** |
| 26 | * Representation of non existing value |
| 27 | */ |
| 28 | @NotNull |
| 29 | public static final None NONE = new None(); |
| 30 | |
| 31 | /** |
| 32 | * Returns of non existing value without getting unchecked warning |
| 33 | * |
| 34 | * @param <T> Type wrapped in {@link Option} |
| 35 | * @return NONE |
| 36 | */ |
| 37 | @SuppressWarnings("unchecked") |
| 38 | @NotNull |
| 39 | public static <T> Option<T> none() { |
| 40 | return NONE; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Indicates if option contains value |
| 45 | * |
| 46 | * @return true if Option is Some, otherwise false |
| 47 | */ |
| 48 | public abstract boolean isSome(); |
| 49 | |
| 50 | /** |
| 51 | * Indicates if option does not contain a value |
| 52 | * |
| 53 | * @return true if Option is None, otherwise false |
| 54 | */ |
| 55 | public abstract boolean isNone(); |
| 56 | |
| 57 | /** |
| 58 | * Runs the action on Option value if exists, otherwise does nothing |
| 59 | * |
| 60 | * @param action Action that is called on the inner value |
| 61 | * @return this {@link Option} |
| 62 | */ |
| 63 | public abstract Option<T> ifSome(@NotNull final Action1<T> action); |
| 64 | |
| 65 | /** |
| 66 | * Runs the action on Option value if does not exist, otherwise does nothing |
| 67 | * |
| 68 | * @param action Action that is called |
| 69 | * @return this {@link Option} |
| 70 | */ |
| 71 | public abstract Option<T> ifNone(@NotNull final Action0 action); |
| 72 | |
| 73 | /** |
| 74 | * Converts inner value with @selector if value exists, otherwise does nothing |
| 75 | * |
| 76 | * @param selector Function that converts inner value |
| 77 | * @param <OUT> Result type |
| 78 | * @return If value exists, returns converted value otherwise does nothing |
| 79 | */ |
| 80 | @NotNull |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…