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.Iterator;
15 import java.util.LinkedHashMap;
16 import java.util.List;
19 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
20 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 final class SourceIdMismatchDetector implements Function<List<IRSchemaSource>, List<IRSchemaSource>> {
27 private static final Logger LOG = LoggerFactory.getLogger(SourceIdMismatchDetector.class);
29 private final Set<SourceIdentifier> sourceIdentifiers;
31 SourceIdMismatchDetector(final Set<SourceIdentifier> sourceIdentifiers) {
32 this.sourceIdentifiers = requireNonNull(sourceIdentifiers);
36 public List<IRSchemaSource> apply(final List<IRSchemaSource> input) {
37 final Iterator<SourceIdentifier> srcIt = sourceIdentifiers.iterator();
38 final Iterator<IRSchemaSource> it = input.iterator();
40 final Map<SourceIdentifier, IRSchemaSource> filtered = new LinkedHashMap<>();
41 while (it.hasNext()) {
42 final IRSchemaSource irSchemaSource = it.next();
43 final SourceIdentifier realSId = irSchemaSource.getIdentifier();
44 if (srcIt.hasNext()) {
45 final SourceIdentifier expectedSId = srcIt.next();
46 if (!expectedSId.equals(realSId)) {
47 LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. "
48 + "Using actual id", expectedSId.getName(), expectedSId, realSId);
52 final IRSchemaSource prev = filtered.put(realSId, irSchemaSource);
54 LOG.warn("Duplicate source for module {} detected in reactor", realSId);
58 return ImmutableList.copyOf(filtered.values());