io.github.qudtlib.nodedef.SettableBuilderBase Maven / Gradle / Ivy
package io.github.qudtlib.nodedef;
import java.util.Objects;
import java.util.function.Consumer;
public abstract class SettableBuilderBase implements SettableBuilder {
private volatile T product;
public SettableBuilderBase(T presetProduct) {
Objects.requireNonNull(presetProduct);
this.product = presetProduct;
}
public SettableBuilderBase() {}
protected void resetProduct() {
this.product = null;
}
@Override
public void setProduct(T product) {
this.product = product;
}
protected abstract T doBuild();
protected T getProduct() {
return product;
}
protected void doIfPresent(T val, Consumer setter) {
if (val != null) {
setter.accept(val);
}
}
@Override
public T build() {
if (this.product == null) {
this.product = doBuild();
}
return product;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy