net.jbock.common.Suppliers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbock-compiler Show documentation
Show all versions of jbock-compiler Show documentation
jbock annotation processor
package net.jbock.common;
import java.util.function.Supplier;
public final class Suppliers {
public static Supplier memoize(Supplier delegate) {
return new Cache<>(delegate);
}
private static final class Cache implements Supplier {
boolean initialized;
T value;
final Supplier delegate;
Cache(Supplier delegate) {
this.delegate = delegate;
}
@Override
public T get() {
if (!initialized) {
initialized = true;
value = delegate.get();
}
return value;
}
}
private Suppliers() {
}
}