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

graphql.util.MemoizedSupplier Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.util;

import java.util.function.Supplier;

import static graphql.Assert.assertNotNull;

class MemoizedSupplier implements Supplier {
    private final static Object SENTINEL = new Object() {
    };

    @SuppressWarnings("unchecked")
    private T value = (T) SENTINEL;
    private final Supplier delegate;

    MemoizedSupplier(Supplier delegate) {
        this.delegate = assertNotNull(delegate);
    }

    @Override
    public T get() {
        T t = value;
        if (t == SENTINEL) {
            t = delegate.get();
            value = t;
        }
        return t;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy