org.opendaylight.yangtools.yang.parser.repo.RevisionDependencyResolver Maven / Gradle / Ivy
/*
* Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.parser.repo;
import java.util.Collection;
import java.util.Map;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
final class RevisionDependencyResolver extends DependencyResolver {
protected RevisionDependencyResolver(final Map depInfo) {
super(depInfo);
}
protected static SourceIdentifier findWildcard(final Iterable haystack, final String needle) {
for (final SourceIdentifier r : haystack) {
if (needle.equals(r.getName())) {
return r;
}
}
return null;
}
@Override
protected boolean isKnown(final Collection haystack, final ModuleImport mi) {
final SourceIdentifier msi = RevisionSourceIdentifier.create(mi.getModuleName(), mi.getRevision());
// Quick lookup
if (haystack.contains(msi)) {
return true;
}
// Slow revision-less walk
return !mi.getRevision().isPresent() && findWildcard(haystack, mi.getModuleName()) != null;
}
public static RevisionDependencyResolver create(final Map depInfo) {
return new RevisionDependencyResolver(depInfo);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy