boolean (@NotNull List<? extends Attribute> l1, @NotNull List<? extends Attribute> l2, @NotNull Element base, @NotNull List<MergeAttribute> mergeByAttributes) { Set<String> attributes = mergeByAttributes.stream() .filter(o -> o.elementName.equals(base.getName())) .map(o -> o.attributeName) .collect(Collectors.toSet()); if (attributes.isEmpty()) { return isAttributesEqual(l1, l2, false); } Map<String, String> secondMap = l2.stream().collect(Collectors.toMap(Attribute::getName, Attribute::getValue)); return l1.stream() .filter(o -> attributes.contains(o.getName())) .allMatch(o -> o.getValue().equals(secondMap.get(o.getName()))); }