package com.trade.common.utils.bean;

import java.util.function.BiConsumer;

public class Builder<T> {

    private final T instance;

    private Builder(T instance){
        this.instance = instance;
    }

    public static <T> Builder<T> of(Class<T> clazz) {
        T instance = null;
        try {
            instance = clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return new Builder<T>(instance);
    }

    public <U> Builder<T> with(BiConsumer<T, U> setter, U value) {
        setter.accept(instance, value);
        return this;
    }

    public T build() {
        return instance;
    }
}
