private static @NotNull Constructor<?> getGreediestSatisfiableConstructor(@Nullable ComponentAdapter adapter,
                                                                            @NotNull DefaultPicoContainer container,
                                                                            @NotNull Class<?> componentImplementation) throws
                                                                                                                       PicoIntrospectionException {
    Set<Constructor<?>> conflicts = new HashSet<>();
    Set<Class<?>[]> unsatisfiableDependencyTypes = new HashSet<>();
    // filter out all constructors that will definitely not match
    Constructor<?>[] constructors = componentImplementation.getDeclaredConstructors();
    // optimize list of constructors moving the longest at the beginning
    Arrays.sort(constructors, (arg0, arg1) -> arg1.getParameterCount() - arg0.getParameterCount());
    Constructor<?> greediestConstructor = null;
    int lastSatisfiableConstructorSize = -1;
    Class<?> unsatisfiedDependencyType = null;
    for (Constructor<?> constructor : constructors) {
      if (constructor.isSynthetic() || isNonInjectable(constructor)) {
        continue;
      }

      boolean failedDependency = false;
      Class<?>[] parameterTypes = constructor.getParameterTypes();
      // remember: all constructors with less arguments than the given parameters are filtered out already
      for (Class<?> type : parameterTypes) {
        // check whether this constructor is satisfiable
        if (ComponentParameter.resolveAdapter(container, adapter, type) != null) {
          continue;
        }
        unsatisfiableDependencyTypes.add(parameterTypes);
        unsatisfiedDependencyType = type;
        failedDependency = true;
        break;
      }

      if (greediestConstructor != null && parameterTypes.length != lastSatisfiableConstructorSize) {
        if (conflicts.isEmpty()) {
          // we found our match [aka. greedy and satisfied]
          return greediestConstructor;
        }
        else {
          // fits although not greedy
          conflicts.add(constructor);
        }
      }
      else if (!failedDependency && lastSatisfiableConstructorSize == parameterTypes.length) {
        // satisfied and same size as previous one?
        conflicts.add(constructor);
        conflicts.add(greediestConstructor);
      }
      else if (!failedDependency) {
        greediestConstructor = constructor;
        lastSatisfiableConstructorSize = parameterTypes.length;
      }
    }

    if (!conflicts.isEmpty()) {
      throw new TooManySatisfiableConstructorsException(conflicts);
    }

    if (greediestConstructor == null && !unsatisfiableDependencyTypes.isEmpty()) {
      @NotNull Class<?> componentImplementation1 = componentImplementation;
      throw new PicoIntrospectionException(componentImplementation1.getName() + " has unsatisfied dependency: " + unsatisfiedDependencyType
                                           + " among unsatisfiable dependencies: " +
                                           unsatisfiableDependencyTypes + " where " + container
                                           + " was the leaf container being asked for dependencies.");
    }
    if (greediestConstructor == null) {
      // be nice to the user, show all constructors that were filtered out
      Set<Constructor<?>> nonMatching = new HashSet<>(Arrays.asList(componentImplementation.getDeclaredConstructors()));
      throw new PicoInitializationException("Either do the specified parameters not match any of the following constructors: " +
                                            nonMatching + " or the constructors were not accessible for '" + componentImplementation + "'");
    }
    return greediestConstructor;
  }
private static @NotNull Constructor<?> getGreediestSatisfiableConstructor(@Nullable ComponentAdapter adapter,
                                                                            @NotNull DefaultPicoContainer container,
                                                                            @NotNull Class<?> componentImplementation)