All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.yudichev.jiotty.common.lang.Optionals Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
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 optional,
                                       Consumer 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