net.yudichev.jiotty.common.lang.Optionals Maven / Gradle / Ivy
package net.yudichev.jiotty.common.lang;
import java.util.Optional;
import java.util.function.Consumer;
public final class Optionals {
private Optionals() {
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") // as designed
public static OrElse ifPresent(Optional extends T> optional,
Consumer super T> presentValueConsumer) {
if (optional.isPresent()) {
presentValueConsumer.accept(optional.get());
return action -> {};
} else {
return Runnable::run;
}
}
public interface OrElse {
void orElse(Runnable action);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy