Use a simple immutable list instead of SchemaPath.
JIRA: YANGTOOLS-1236
Change-Id: I430671a1ac078718e03af3417f01470567c5e744
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
provides DataTreeFactory with InMemoryDataTreeFactory;
requires transitive org.opendaylight.yangtools.yang.data.tree.api;
+ requires com.google.common;
requires org.opendaylight.yangtools.concepts;
+ requires org.opendaylight.yangtools.yang.common;
requires org.opendaylight.yangtools.yang.data.tree.spi;
requires org.opendaylight.yangtools.yang.data.impl;
requires org.opendaylight.yangtools.yang.data.spi;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Iterator;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveModelContextProvider;
public final class LeafRefContext extends AbstractEffectiveModelContextProvider {
private final QName currentNodeQName;
- private final SchemaPath currentNodePath;
+ private final ImmutableList<QName> currentNodePath;
private final Module module;
private final LeafRefPath leafRefTargetPath;
LeafRefContext(final LeafRefContextBuilder leafRefContextBuilder) {
super(leafRefContextBuilder.getSchemaContext());
- this.currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
- this.currentNodePath = leafRefContextBuilder.getCurrentNodePath();
- this.leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
- this.absoluteLeafRefTargetPath = leafRefContextBuilder.getAbsoluteLeafRefTargetPath();
- this.leafRefTargetPathString = leafRefContextBuilder.getLeafRefTargetPathString();
- this.isReferencedBy = leafRefContextBuilder.isReferencedBy();
- this.isReferencing = leafRefContextBuilder.isReferencing();
- this.referencingChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencingChilds());
- this.referencedByChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencedByChilds());
- this.referencedByLeafRefCtx = ImmutableMap.copyOf(leafRefContextBuilder.getAllReferencedByLeafRefCtxs());
- this.module = leafRefContextBuilder.getLeafRefContextModule();
+ currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
+ currentNodePath = leafRefContextBuilder.getCurrentNodePath();
+ leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
+ absoluteLeafRefTargetPath = leafRefContextBuilder.getAbsoluteLeafRefTargetPath();
+ leafRefTargetPathString = leafRefContextBuilder.getLeafRefTargetPathString();
+ isReferencedBy = leafRefContextBuilder.isReferencedBy();
+ isReferencing = leafRefContextBuilder.isReferencing();
+ referencingChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencingChilds());
+ referencedByChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencedByChilds());
+ referencedByLeafRefCtx = ImmutableMap.copyOf(leafRefContextBuilder.getAllReferencedByLeafRefCtxs());
+ module = leafRefContextBuilder.getLeafRefContextModule();
}
public static LeafRefContext create(final EffectiveModelContext ctx) {
return referencedByChilds;
}
- public SchemaPath getCurrentNodePath() {
+ public ImmutableList<QName> getCurrentNodePath() {
return currentNodePath;
}
private Iterator<QName> descendantIterator(final SchemaNodeIdentifier node) {
final Iterator<QName> nodeSteps = node.getNodeIdentifiers().iterator();
if (node instanceof SchemaNodeIdentifier.Absolute) {
- final Iterator<QName> mySteps = currentNodePath.getPathFromRoot().iterator();
+ final Iterator<QName> mySteps = currentNodePath.iterator();
while (mySteps.hasNext()) {
final QName myNext = mySteps.next();
checkArgument(nodeSteps.hasNext(), "Node %s is an ancestor of %s", node, currentNodePath);
import static java.util.Objects.requireNonNull;
+import com.google.common.collect.ImmutableList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Mutable;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
final class LeafRefContextBuilder implements Mutable {
private final Map<QName, LeafRefContext> referencingChildren = new HashMap<>();
private final Map<QName, LeafRefContext> referencedByLeafRefCtx = new HashMap<>();
private final QName currentNodeQName;
- private final SchemaPath currentNodePath;
+ private final ImmutableList<QName> currentNodePath;
private final EffectiveModelContext schemaContext;
private LeafRefPath leafRefTargetPath = null;
private boolean isReferencedBy = false;
private boolean isReferencing = false;
- LeafRefContextBuilder(final QName currentNodeQName, final SchemaPath currentNodePath,
+ LeafRefContextBuilder(final QName currentNodeQName, final ImmutableList<QName> currentNodePath,
final EffectiveModelContext schemaContext) {
this.currentNodeQName = requireNonNull(currentNodeQName);
this.currentNodePath = requireNonNull(currentNodePath);
return referencedByChildren;
}
- SchemaPath getCurrentNodePath() {
+ ImmutableList<QName> getCurrentNodePath() {
return currentNodePath;
}
}
Module getLeafRefContextModule() {
- final List<QName> path = currentNodePath.getPathFromRoot();
- final QNameModule qnameModule = path.isEmpty() ? currentNodeQName.getModule() : path.get(0).getModule();
+ final QNameModule qnameModule = currentNodePath.isEmpty() ? currentNodeQName.getModule()
+ : currentNodePath.get(0).getModule();
return schemaContext.findModule(qnameModule).orElse(null);
}
*/
package org.opendaylight.yangtools.yang.data.tree.leafref;
+import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
LeafRefContext buildLeafRefContextTree() throws LeafRefYangSyntaxErrorException {
final SchemaInferenceStack stack = SchemaInferenceStack.of(schemaContext);
- final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(SchemaContext.NAME, SchemaPath.ROOT,
+ final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(SchemaContext.NAME, ImmutableList.of(),
schemaContext);
final Collection<? extends Module> modules = schemaContext.getModules();
private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node,
final SchemaInferenceStack stack) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
- stack.toSchemaPath(), schemaContext);
+ extractPath(stack), schemaContext);
if (node instanceof DataNodeContainer container) {
for (final DataSchemaNode childNode : container.getChildNodes()) {
private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule,
final SchemaInferenceStack stack) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
- stack.toSchemaPath(), schemaContext);
+ extractPath(stack), schemaContext);
if (node instanceof DataNodeContainer container) {
for (final DataSchemaNode childNode : container.getChildNodes()) {
stack.enterSchemaTree(childNode.getQName());
}
private List<LeafRefContext> getLeafRefsFor(final Module module, final SchemaInferenceStack stack) {
- final LeafRefPath nodeXPath = LeafRefUtils.schemaPathToLeafRefPath(stack.toSchemaPath(), module);
+ final LeafRefPath nodeXPath = LeafRefUtils.schemaPathToLeafRefPath(extractPath(stack), module);
final List<LeafRefContext> foundLeafRefs = new LinkedList<>();
for (final LeafRefContext leafref : leafRefs) {
final LeafRefPath leafRefTargetPath = leafref.getAbsoluteLeafRefTargetPath();
return foundLeafRefs;
}
+
+ private static ImmutableList<QName> extractPath(final SchemaInferenceStack stack) {
+ return stack.isEmpty() ? ImmutableList.of()
+ : ImmutableList.copyOf(stack.toSchemaNodeIdentifier().getNodeIdentifiers());
+ }
}
*/
package org.opendaylight.yangtools.yang.data.tree.leafref;
+import com.google.common.collect.ImmutableList;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public final class LeafRefUtils {
private LeafRefUtils() {
* @param module module
* @return LeafRefPath object
*/
- public static LeafRefPath createAbsoluteLeafRefPath(
- final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath,
- final Module module) {
+ public static LeafRefPath createAbsoluteLeafRefPath(final LeafRefPath leafRefPath,
+ final ImmutableList<QName> contextNodeSchemaPath, final Module module) {
if (leafRefPath.isAbsolute()) {
return leafRefPath;
}
return LeafRefPath.create(absoluteLeafRefTargetPathList, true);
}
- private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) {
+ private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final ImmutableList<QName> nodePath,
+ final Module module) {
final Deque<QNameWithPredicate> xpath = new LinkedList<>();
- final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot().iterator();
+ final Iterator<QName> nodePathIterator = nodePath.iterator();
DataNodeContainer currenDataNodeContainer = module;
while (nodePathIterator.hasNext()) {
return xpath;
}
- public static LeafRefPath schemaPathToLeafRefPath(final SchemaPath nodePath, final Module module) {
+ public static LeafRefPath schemaPathToLeafRefPath(final ImmutableList<QName> nodePath, final Module module) {
return LeafRefPath.create(schemaPathToXPathQNames(nodePath, module), true);
}
}