2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.repo;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.Function;
13 import com.google.common.collect.ImmutableList;
14 import java.util.LinkedHashMap;
15 import java.util.List;
17 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
18 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
19 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 final class SourceIdMismatchDetector implements Function<List<YangIRSource>, List<YangIRSource>> {
25 private static final Logger LOG = LoggerFactory.getLogger(SourceIdMismatchDetector.class);
27 private final Set<SourceIdentifier> sourceIdentifiers;
29 SourceIdMismatchDetector(final Set<SourceIdentifier> sourceIdentifiers) {
30 this.sourceIdentifiers = requireNonNull(sourceIdentifiers);
34 public List<YangIRSource> apply(final List<YangIRSource> input) {
35 final var srcIt = sourceIdentifiers.iterator();
36 final var filtered = new LinkedHashMap<SourceIdentifier, YangIRSource>();
37 for (var irSchemaSource : input) {
38 final SourceIdentifier realSId = irSchemaSource.sourceId();
39 if (srcIt.hasNext()) {
40 final SourceIdentifier expectedSId = srcIt.next();
41 if (!expectedSId.equals(realSId)) {
42 LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. "
43 + "Using actual id", expectedSId.name().getLocalName(), expectedSId, realSId);
47 final var prev = filtered.put(realSId, irSchemaSource);
49 LOG.warn("Duplicate source for module {} detected in reactor", realSId);
53 return ImmutableList.copyOf(filtered.values());