All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.qudtlib.nodedef.SettableBuilderBase Maven / Gradle / Ivy

There is a newer version: 6.7.0
Show newest version
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