Field (@NotNull List<Pair<Field, YamlMetaType>> pairs) { switch (pairs.size()) { case 0 -> { return null; } case 1 -> { return pairs.get(0).getFirst(); } } Set<String> allNames = pairs.stream().map(fieldAndType -> fieldAndType.getFirst().getName()).collect(Collectors.toSet()); assert allNames.size() == 1 : "Can't merge fields with different names: " + allNames; String theName = pairs.get(0).getFirst().getName(); boolean isMany = mergeIsMany(theName, pairs); List<Field> fields = ContainerUtil.map(pairs, pair -> pair.getFirst()); // we will assume that "positive" field qualities are merged by ANY while "negative" qualities are merged by ALL boolean required = ContainerUtil.and(fields, f -> f.isRequired()); boolean deprecated = ContainerUtil.and(fields, f -> f.isDeprecated()); boolean editable = ContainerUtil.exists(fields, f -> f.isEditable()); boolean emptyAllowed = ContainerUtil.exists(fields, f -> f.isEmptyValueAllowed()); boolean anyName = ContainerUtil.exists(fields, f -> f.isAnyNameAllowed()); YamlMetaType type = composeTypes(pairs.stream().map(p -> p.getSecond()).toArray(YamlMetaType[]::new)); Field result = new Field(theName, type); result.withMultiplicityManyNotOne(isMany); if (required) { result.setRequired(); } if (deprecated) { result.setDeprecated(); } if (!editable) { result.setNonEditable(); } result.withEmptyValueAllowed(emptyAllowed); if (anyName) { result.withAnyName(); } return result; }