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

net.rakugakibox.spring.boot.logback.access.AbstractOverridenAttribute Maven / Gradle / Ivy

package net.rakugakibox.spring.boot.logback.access;

import java.io.Serializable;
import java.util.Optional;

/**
 * The base class that indicates the overridden attribute.
 * The value is optional and it is lazily evaluated.
 * If the evaluated value is present, caches it. Otherwise, returns the original value.
 *
 * @param  the type of value.
 */
public abstract class AbstractOverridenAttribute implements Serializable {

    /**
     * Whether was evaluated.
     */
    private boolean evaluated;

    /**
     * The evaluated value.
     */
    private T value;

    /**
     * Returns the value.
     *
     * @return the value.
     */
    public T get() {
        if (!evaluated) {
            value = evaluateValueToOverride().orElse(null);
            evaluated = true;
        }
        return Optional.ofNullable(value).orElseGet(this::getOriginalValue);
    }

    /**
     * Evaluates the value to override.
     *
     * @return the value to override.
     */
    protected abstract Optional evaluateValueToOverride();

    /**
     * Returns the original value.
     *
     * @return the original value.
     */
    protected abstract T getOriginalValue();

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy