com.g2forge.alexandria.java.function.cache.FixedCachingSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.function.cache;
import java.util.function.Supplier;
public class FixedCachingSupplier implements Supplier {
/** The supplier to cache. Set to null
after use to indicate that we already have the result. */
protected Supplier extends T> supplier;
protected T value;
public FixedCachingSupplier(Supplier extends T> supplier) {
this.supplier = supplier;
this.value = null;
}
@Override
public T get() {
if (supplier != null) {
value = supplier.get();
supplier = null;
}
return value;
}
}