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

com.artipie.asto.misc.UncheckedScalar Maven / Gradle / Ivy

/*
 * The MIT License (MIT) Copyright (c) 2020-2023 artipie.com
 * https://github.com/artipie/artipie/blob/master/LICENSE.txt
 */
package com.artipie.asto.misc;

import com.artipie.ArtipieException;

/**
 * Scalar that throws {@link com.artipie.ArtipieException} on error.
 * @param  Return value type
 * @param  Error type
 * @since 1.3
 */
public final class UncheckedScalar implements Scalar {

    /**
     * Original origin.
     */
    private final Checked origin;

    /**
     * Ctor.
     * @param origin Encapsulated origin
     */
    public UncheckedScalar(final Checked origin) {
        this.origin = origin;
    }

    @Override
    @SuppressWarnings("PMD.AvoidCatchingGenericException")
    public T value() {
        try {
            return this.origin.value();
        } catch (final Exception ex) {
            throw new ArtipieException(ex);
        }
    }

    /**
     * Checked version of scalar.
     * @param  Return type
     * @param  Error type
     * @since 1.1
     */
    @FunctionalInterface
    public interface Checked {

        /**
         * Return value.
         * @return Result
         * @throws E On error
         */
        R value() throws E;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy