-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace nulls by Optional
#327
Comments
I am not sure that we actually want to do it because Optional is not available on Android versions before the quite new 7.0. |
Even
These methods just have to return public interface Ambiguous<T> extends List<T> {
static Ambiguous<T> empty();
static Ambiguous<T> of(T value);
static Ambiguous<T> ofNullable(T value);
static Ambiguous<T> of(T... values);
boolean isPresent(); // 1 or more
boolean isUnique(); // 0 or 1
boolean isAmbiguous(); // 2 or more
boolean isSingle(); // exactly 1
Optional<T> unique(); // throws if there are 2+ items
Optional<T> uniqueOrElse(T fallback); // fallback if there are 2+ items
Optional<T> uniqueOrElseGet(Supplier<? extends T> supplier);
T single(); // throws if there are 0 or 2+ items
T singleOrElse(T fallback); // fallback if there are 0 or 2+ items
T singleOrElseGet(Supplier<? extends T> supplier);
} Application interested in picking one of the values could just use So methods that query values guaranteed to be unique would return |
To ensure the type safety of the code it may be nice to use the Java 8
Optional
construction where it is relevant.The text was updated successfully, but these errors were encountered: