class MergedMdcsValidator implements AnnotationUsageValidator<Collection<Mdc>> {

    @Override
    public void validate(Method method, Collection<Mdc> target) throws AnnotationUsageException {
        // validate uniqueness of not empty MDC keys
        target.stream().collect(groupingBy(Mdc::key))
                .entrySet().stream()
                .filter(entry -> !entry.getKey().isEmpty())
                .filter(entry -> entry.getValue().size() > 1)
                .findFirst()
                .ifPresent(entry -> {
                    throw new AnnotationUsageException(method,
                            format("%s annotations with 'key = %s' on the method", entry.getValue().size(), entry.getKey()),
                            "Use unique 'key' per method");
                });
    }

}