
net.cassite.pure.aop.Generator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pure.ioc Show documentation
Show all versions of pure.ioc Show documentation
Lightweight type and annotation based dependency injection framework
The newest version!
package net.cassite.pure.aop;
import net.cassite.style.interfaces.RFunc0;
/**
* it's an object generator, in which the RFunc0[R] apply() method would only be called at most once, it will store the value, and use it for other invocations
*/
public class Generator {
private final RFunc0 func;
private boolean valueRetrieved = false;
private R r;
public Generator(RFunc0 func) {
this.func = func;
}
/**
* get object retrieved from the function
*
* @return object retrieved from the function
* @throws Throwable exception
*/
public R get() throws Throwable {
if (!valueRetrieved) {
synchronized (func) {
if (!valueRetrieved) {
r = func.apply();
valueRetrieved = true;
}
}
}
return r;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy