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

com.qwlabs.test.builders.BuilderAware Maven / Gradle / Ivy

The newest version!
package com.qwlabs.test.builders;

import com.qwlabs.cdi.SafeCDI;

public final class BuilderAware {
    private BuilderAware() {
    }

    public static  B getBuilder(Class builderClazz) {
        return SafeCDI.current()
                .map(cdi -> cdi.select(builderClazz).get())
                .orElseGet(() -> {
                    try {
                        return builderClazz.newInstance();
                    } catch (Exception e) {
                        throw new RuntimeException("Can not found builder. class=" + builderClazz.getName());
                    }
                });
    }
}