2 * Copyright (c) 2016 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 java.util.Collection;
12 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
13 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
14 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
15 import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
17 final class RevisionDependencyResolver extends DependencyResolver {
19 protected RevisionDependencyResolver(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
23 protected static SourceIdentifier findWildcard(final Iterable<SourceIdentifier> haystack, final String needle) {
24 for (final SourceIdentifier r : haystack) {
25 if (needle.equals(r.getName())) {
34 protected boolean isKnown(final Collection<SourceIdentifier> haystack, final ModuleImport mi) {
35 final SourceIdentifier msi = RevisionSourceIdentifier.create(mi.getModuleName(), mi.getRevision());
38 if (haystack.contains(msi)) {
42 // Slow revision-less walk
43 return !mi.getRevision().isPresent() && findWildcard(haystack, mi.getModuleName()) != null;
46 public static RevisionDependencyResolver create(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
47 return new RevisionDependencyResolver(depInfo);