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

io.atleon.core.PresentAlo Maven / Gradle / Ivy

package io.atleon.core;

import java.util.Optional;
import java.util.function.Function;

/**
 * A {@link DelegatingAlo} that adapts from an {@link Alo} exposing an {@link Optional} that is
 * known to be non-empty to an Alo exposing that Optional's data type.
 *
 * @param  The type referenced by the wrapped Alo's Optional
 */
public final class PresentAlo extends AbstractDelegatingAlo> {

    private PresentAlo(Alo> delegate) {
        super(delegate);
    }

    static  PresentAlo wrap(Alo> delegate) {
        return new PresentAlo<>(delegate);
    }

    @Override
    public  Alo map(Function mapper) {
        return delegate.map(mapper.compose(Optional::get));
    }

    @Override
    public T get() {
        return delegate.get().orElseThrow(PresentAlo::newAbsentDelegateException);
    }

    private static IllegalStateException newAbsentDelegateException() {
        return new IllegalStateException("Something bad happened. Wrapped Alo is absent.");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy