com.vital.api.core.Suppliers Maven / Gradle / Ivy
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.vital.api.core;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
public final class Suppliers {
private Suppliers() {}
public static Supplier memoize(Supplier delegate) {
AtomicReference value = new AtomicReference<>();
return () -> {
T val = value.get();
if (val == null) {
val = value.updateAndGet(cur -> cur == null ? Objects.requireNonNull(delegate.get()) : cur);
}
return val;
};
}
}