- static private method
- reduce use of ChoiceSchemaNode.getCaseNodeByName()
- QNameWithPredicateBuilder(QName)
Change-Id: I9cf97ba4c6ef667e39212f511e17bb18b4002bc3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
ef795628f150556ddc8c93b865d1c3c0b9b0109c)
return schemaContext.findModule(moduleName, revision).map(Module::getQNameModule);
}
return schemaContext.findModule(moduleName, revision).map(Module::getQNameModule);
}
- private ModuleImport getModuleImport(final Module targetModule, final String prefix) {
+ private static ModuleImport getModuleImport(final Module targetModule, final String prefix) {
return targetModule.getImports().stream()
.filter(imp -> prefix.equals(imp.getPrefix())).findFirst().orElse(null);
}
return targetModule.getImports().stream()
.filter(imp -> prefix.equals(imp.getPrefix())).findFirst().orElse(null);
}
public static LeafRefPath createAbsoluteLeafRefPath(
final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath,
final Module module) {
public static LeafRefPath createAbsoluteLeafRefPath(
final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath,
final Module module) {
if (leafRefPath.isAbsolute()) {
return leafRefPath;
}
if (leafRefPath.isAbsolute()) {
return leafRefPath;
}
return LeafRefPath.create(absoluteLeafRefTargetPathList, true);
}
return LeafRefPath.create(absoluteLeafRefTargetPathList, true);
}
- private static Deque<QNameWithPredicate> schemaPathToXPathQNames(
- final SchemaPath nodePath, final Module module) {
-
+ private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) {
final Deque<QNameWithPredicate> xpath = new LinkedList<>();
final Deque<QNameWithPredicate> xpath = new LinkedList<>();
-
- final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot()
- .iterator();
+ final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot().iterator();
DataNodeContainer currenDataNodeContainer = module;
while (nodePathIterator.hasNext()) {
final QName qname = nodePathIterator.next();
DataNodeContainer currenDataNodeContainer = module;
while (nodePathIterator.hasNext()) {
final QName qname = nodePathIterator.next();
- final DataSchemaNode child = currenDataNodeContainer
- .getDataChildByName(qname);
+ final DataSchemaNode child = currenDataNodeContainer.getDataChildByName(qname);
if (child instanceof DataNodeContainer) {
if (!(child instanceof CaseSchemaNode)) {
if (child instanceof DataNodeContainer) {
if (!(child instanceof CaseSchemaNode)) {
- final QNameWithPredicate newQName = new QNameWithPredicateBuilder(
- qname.getModule(), qname.getLocalName()).build();
- xpath.add(newQName);
+ xpath.add(new QNameWithPredicateBuilder(qname).build());
}
currenDataNodeContainer = (DataNodeContainer) child;
} else if (child instanceof ChoiceSchemaNode) {
if (nodePathIterator.hasNext()) {
}
currenDataNodeContainer = (DataNodeContainer) child;
} else if (child instanceof ChoiceSchemaNode) {
if (nodePathIterator.hasNext()) {
- currenDataNodeContainer = ((ChoiceSchemaNode) child)
- .getCaseNodeByName(nodePathIterator.next());
+ currenDataNodeContainer = ((ChoiceSchemaNode) child).getCases().get(nodePathIterator.next());
- } else if (child instanceof LeafSchemaNode
- || child instanceof LeafListSchemaNode) {
-
- final QNameWithPredicate newQName = new QNameWithPredicateBuilder(
- qname.getModule(), qname.getLocalName()).build();
- xpath.add(newQName);
+ } else if (child instanceof LeafSchemaNode || child instanceof LeafListSchemaNode) {
+ xpath.add(new QNameWithPredicateBuilder(qname).build());
} else if (child == null) {
} else if (child == null) {
- throw new IllegalArgumentException("No child " + qname
- + " found in node container " + currenDataNodeContainer
- + " in module " + module.getName());
+ throw new IllegalArgumentException("No child " + qname + " found in node container "
+ + currenDataNodeContainer + " in module " + module.getName());
- throw new IllegalStateException(
- "Illegal schema node type in the path: "
- + child.getClass());
+ throw new IllegalStateException("Illegal schema node type in the path: " + child.getClass());
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.concepts.Builder;
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
class QNameWithPredicateBuilder implements Builder<QNameWithPredicate> {
import org.opendaylight.yangtools.yang.common.QNameModule;
class QNameWithPredicateBuilder implements Builder<QNameWithPredicate> {
+ QNameWithPredicateBuilder(final QName qname) {
+ this(qname.getModule(), qname.getLocalName());
+ }
+
QNameWithPredicateBuilder(final QNameModule moduleQname, final String localName) {
this.moduleQname = moduleQname;
this.localName = localName;
QNameWithPredicateBuilder(final QNameModule moduleQname, final String localName) {
this.moduleQname = moduleQname;
this.localName = localName;
return child;
}
if (node instanceof ChoiceSchemaNode) {
return child;
}
if (node instanceof ChoiceSchemaNode) {
- return ((ChoiceSchemaNode) node).getCaseNodeByName(qname);
+ return ((ChoiceSchemaNode) node).getCases().get(qname);
}
if (node instanceof OperationDefinition) {
switch (qname.getLocalName()) {
}
if (node instanceof OperationDefinition) {
switch (qname.getLocalName()) {
final T ret = (T) INTERNER.intern(sample);
LOG.trace("Interned object {} to {}", sample, ret);
return ret;
final T ret = (T) INTERNER.intern(sample);
LOG.trace("Interned object {} to {}", sample, ret);
return ret;
- } else {
- // Non-empty attributes, do not intern
- return sample;
+
+ // Non-empty attributes, do not intern
+ return sample;