private static Constructor<?> bestConstructor(Class<?> clazz) {
        Constructor<?>[] publicConstructors = clazz.getConstructors();

        Constructor<?> annotated = null;
        for (Constructor<?> ctor : publicConstructors) {
            Annotation annotation = ctor.getAnnotation(com.google.inject.Inject.class);
            if (annotation == null) annotation = ctor.getAnnotation(com.yahoo.component.annotation.Inject.class);
            if (annotation != null) {
                if (annotated == null) {
                    annotated = ctor;
                } else {
                    throw componentConstructorException("Multiple constructor annotated with @Inject in class " + clazz.getName());
                }
            }
        }
        if (annotated != null) {
            return annotated;
        }

        if (publicConstructors.length == 0) {
            throw componentConstructorException("No public constructors in class " + clazz.getName());
        } else if (publicConstructors.length == 1) {
            return publicConstructors[0];
        } else {
            log.warning(String.format("Multiple public constructors found in class %s, there should only be one. "
                    + "If more than one public constructor is needed, the primary one must be annotated with @Inject.", clazz.getName()));
            List<Pair<Constructor<?>, Integer>> withParameterCount = new ArrayList<>();
            for (Constructor<?> ctor : publicConstructors) {
                long count = Arrays.stream(ctor.getParameterTypes()).filter(ConfigInstance.class::isAssignableFrom).count();
                withParameterCount.add(new Pair<>(ctor, (int) count));
            }
            withParameterCount.sort(Comparator.comparingInt(Pair::getSecond));
            return withParameterCount.get(withParameterCount.size() - 1).getFirst();
        }
    }
@author Tony Vaagenes
@author gjoranv
@author ollivir
container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java