List<PyRequirement> (@NotNull List<PyRequirement> requirementsFromRequires, @NotNull List<PyRequirement> requirementsFromLinks) { if (!requirementsFromLinks.isEmpty()) { final Map<String, List<PyRequirement>> nameToRequirements = requirementsFromRequires.stream().collect(Collectors.groupingBy(PyRequirement::getName, LinkedHashMap::new, Collectors.toList())); for (PyRequirement requirementFromLinks : requirementsFromLinks) { nameToRequirements.replace(requirementFromLinks.getName(), Collections.singletonList(requirementFromLinks)); } return nameToRequirements.values().stream().flatMap(Collection::stream).collect(Collectors.toCollection(ArrayList::new)); } return requirementsFromRequires; }