@SuppressWarnings("unchecked") // safe covariant cast @Override Optional<T> or(Optional<? extends T> secondChoice) { return (Optional<T>) checkNotNull(secondChoice); }
@Override Optional<T> or(Optional<? extends T> secondChoice) { checkNotNull(secondChoice); return this; }
@Override T or(T defaultValue) { return checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)"); }
@Override T or(T defaultValue) { checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)"); return reference; }
@SuppressWarnings("unchecked") // safe covariant cast @Override Optional<T> or(Optional<? extends T> secondChoice) { return (Optional<T>) checkNotNull(secondChoice); }
@Override T or(T defaultValue) { checkNotNull(defaultValue, "use Optional.orNull() instead of Optional.or(null)"); return reference; }
static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException { checkNotNull(file); checkNotNull(charset); return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); }
static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException { checkNotNull(file); checkNotNull(charset); return new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); }
static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException { checkNotNull(file); checkNotNull(charset); return new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); }
static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException { checkNotNull(file); checkNotNull(charset); return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); }
static <T> boolean all(Iterator<T> iterator, Predicate<? super T> predicate) { checkNotNull(predicate); while (iterator.hasNext()) { T element = iterator.next(); if (!predicate.apply(element)) { return false; } } return true; } }
@Override <V> Optional<V> transform(Function<? super T, V> function) { checkNotNull(function); return Optional.absent(); }
@Override <V> Optional<V> transform(Function<? super T, V> function) { return new Present<>( checkNotNull( function.apply(reference), "the Function passed to Optional.transform() must not return null.")); }
static <T> int indexOf(Iterator<T> iterator, Predicate<? super T> predicate) { checkNotNull(predicate, "predicate"); for (int i = 0; iterator.hasNext(); i++) { T current = iterator.next(); if (predicate.apply(current)) { return i; } } return -1; }
@Override <V> Optional<V> transform(Function<? super T, V> function) { checkNotNull(function); return Optional.absent(); }
static <T> int indexOf(Iterator<T> iterator, Predicate<? super T> predicate) { checkNotNull(predicate, "predicate"); for (int i = 0; iterator.hasNext(); i++) { T current = iterator.next(); if (predicate.apply(current)) { return i; } } return -1; }
static <T> boolean all(Iterator<T> iterator, Predicate<? super T> predicate) { checkNotNull(predicate); while (iterator.hasNext()) { T element = iterator.next(); if (!predicate.apply(element)) { return false; } } return true; } }
/** * Returns an {@code Optional} instance containing the given non-null reference. To have {@code * null} treated as {@link #absent}, use {@link #fromNullable} instead. * <p> * <p><b>Comparison to {@code java.util.Optional}:</b> no differences. * * @throws NullPointerException if {@code reference} is null */ static <T> Optional<T> of(T reference) { return new Present<T>(checkNotNull(reference)); }
@Override <V> Optional<V> transform(Function<? super T, V> function) { return new Present<>( checkNotNull( function.apply(reference), "the Function passed to Optional.transform() must not return null.")); }
/** * Returns an {@code Optional} instance containing the given non-null reference. To have {@code * null} treated as {@link #absent}, use {@link #fromNullable} instead. * <p> * <p><b>Comparison to {@code java.util.Optional}:</b> no differences. * * @throws NullPointerException if {@code reference} is null */ static <T> Optional<T> of(T reference) { return new Present<T>(checkNotNull(reference)); }