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

edu.hm.hafner.analysis.util.Deferred Maven / Gradle / Ivy

Go to download

This library provides a Java object model to read, aggregate, filter, and query static analysis reports. It is used by Jenkins' warnings next generation plug-in to visualize the warnings of individual builds. Additionally, this library is used by a GitHub action to autograde student software projects based on a given set of metrics (unit tests, code and mutation coverage, static analysis warnings).

There is a newer version: 13.3.0
Show newest version
package edu.hm.hafner.analysis.util;

import java.util.function.Supplier;

import edu.umd.cs.findbugs.annotations.CheckForNull;

/**
 * Deferred element wrapper of a singleton instance. Creates a constant instance when it is accessed the first time.
 *
 * @param 
 *         type of the instance
 */
public final class Deferred {
    private final Supplier supplier;

    @SuppressWarnings("PMD.AvoidUsingVolatile")
    @CheckForNull
    private volatile T object;

    /**
     * Creates a new instance that creates a singleton when it is accessed the first time.
     *
     * @param supplier
     *         the supplier to create the instance
     */
    public Deferred(final Supplier supplier) {
        this.supplier = supplier;
    }

    /**
     * Returns the instance. If not yet created the instance will be created.
     *
     * @return the instance
     */
    public T get() {
        T tmp = object;
        if (tmp == null) {
            tmp = supplier.get();
        }
        object = tmp;
        return tmp;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy