net.sf.javagimmicks.util8.AbstractLazySupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.util8;
import java.util.function.Supplier;
abstract class AbstractLazySupplier implements Supplier
{
private final Supplier _baseSupplier;
protected AbstractLazySupplier(final Supplier baseSupplier)
{
_baseSupplier = baseSupplier;
}
@Override
public final E get()
{
E instance = getInstance();
if (instance != null)
{
return instance;
}
synchronized (this)
{
instance = getInstance();
if (instance == null)
{
instance = _baseSupplier.get();
setInstance(instance);
}
}
return instance;
}
abstract protected E getInstance();
abstract protected void setInstance(E instance);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy