@Override public final void exit(final int depth) { Preconditions.checkArgument(depth >= 0); YangInstanceIdentifier next = current; for (int i = 0; i < depth; ++i) { next = next.getParent(); Preconditions.checkState(next != null); } current = next; }
/** * @deprecated Use {@link YangInstanceIdentifier#getParent()} instead. */ @Deprecated protected static Optional<YangInstanceIdentifier> getParent(final YangInstanceIdentifier child) { return Optional.fromNullable(child.getParent()); }
/** * Use {@link YangInstanceIdentifier#getParent()} instead. */ @Deprecated protected static Optional<YangInstanceIdentifier> getParent(final YangInstanceIdentifier child) { return Optional.ofNullable(child.getParent()); }
@Override public final void exit(final int depth) { Preconditions.checkArgument(depth >= 0); YangInstanceIdentifier next = current; for (int i = 0; i < depth; ++i) { next = next.getParent(); Preconditions.checkState(next != null); } current = next; }
@Nonnull default Optional<YangInstanceIdentifier> getNodeParent(@Nonnull final YangInstanceIdentifier identifier) { return Optional.ofNullable(identifier.getParent()); }
private static int calculateSize(final YangInstanceIdentifier parent) { YangInstanceIdentifier current = parent; for (int i = 1;; ++i) { final Collection<PathArgument> args = current.tryReversePathArguments(); if (args != null) { return i + args.size(); } verify(current instanceof StackedYangInstanceIdentifier); current = current.getParent(); } }
@Override public final void exit() { Preconditions.checkState(!current.isEmpty()); current = Verify.verifyNotNull(current.getParent()); }
private static int calculateSize(final YangInstanceIdentifier parent) { YangInstanceIdentifier current = parent; for (int i = 1;; ++i) { final Collection<PathArgument> args = current.tryReversePathArguments(); if (args != null) { return i + args.size(); } verify(current instanceof StackedYangInstanceIdentifier); current = current.getParent(); } }
@Override public final void exit() { Preconditions.checkState(!current.isEmpty()); current = Verify.verifyNotNull(current.getParent()); }
@Nonnull @Override public YangInstanceIdentifier getAncestor(final int depth) { checkArgument(depth >= 0, "Steps cannot be negative"); // Calculate how far up our FixedYangInstanceIdentifier ancestor is int stackedDepth = 1; YangInstanceIdentifier wlk = getParent(); while (wlk instanceof StackedYangInstanceIdentifier) { wlk = wlk.getParent(); stackedDepth++; } // Guaranteed to come from FixedYangInstanceIdentifier final int fixedDepth = wlk.getPathArguments().size(); if (fixedDepth >= depth) { return wlk.getAncestor(depth); } // Calculate our depth and check argument final int ourDepth = stackedDepth + fixedDepth; checkArgument(depth <= ourDepth, "Depth %s exceeds maximum depth %s", depth, ourDepth); // Requested depth is covered by the stack, traverse up for specified number of steps final int toWalk = ourDepth - depth; YangInstanceIdentifier result = this; for (int i = 0; i < toWalk; ++i) { result = result.getParent(); } return result; }
@Nonnull @Override public YangInstanceIdentifier getAncestor(final int depth) { checkArgument(depth >= 0, "Steps cannot be negative"); // Calculate how far up our FixedYangInstanceIdentifier ancestor is int stackedDepth = 1; YangInstanceIdentifier wlk = getParent(); while (wlk instanceof StackedYangInstanceIdentifier) { wlk = wlk.getParent(); stackedDepth++; } // Guaranteed to come from FixedYangInstanceIdentifier final int fixedDepth = wlk.getPathArguments().size(); if (fixedDepth >= depth) { return wlk.getAncestor(depth); } // Calculate our depth and check argument final int ourDepth = stackedDepth + fixedDepth; checkArgument(depth <= ourDepth, "Depth %s exceeds maximum depth %s", depth, ourDepth); // Requested depth is covered by the stack, traverse up for specified number of steps final int toWalk = ourDepth - depth; YangInstanceIdentifier result = this; for (int i = 0; i < toWalk; ++i) { result = result.getParent(); } return result; }
public static String entityTypeFromEntityPath(YangInstanceIdentifier entityPath){ YangInstanceIdentifier parent = entityPath; while(!parent.isEmpty()) { if (EntityType.QNAME.equals(parent.getLastPathArgument().getNodeType())) { YangInstanceIdentifier.NodeIdentifierWithPredicates entityTypeLastPathArgument = (YangInstanceIdentifier.NodeIdentifierWithPredicates) parent.getLastPathArgument(); return (String) entityTypeLastPathArgument.getKeyValues().get(ENTITY_TYPE_QNAME); } parent = parent.getParent(); } return null; }
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalized) { if (Identifiable.class.isAssignableFrom(path.getTargetType())) { YangInstanceIdentifier parentMapPath = normalized.getKey().getParent(); Preconditions.checkArgument(parentMapPath != null, "Map path %s does not have a parent", path);
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalized) { if (IdentifiableItem.class.isAssignableFrom(path.getTargetType())) { final YangInstanceIdentifier parentMapPath = normalized.getKey().getParent(); Preconditions.checkArgument(parentMapPath != null, "Map path %s does not have a parent", path);
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) { final YangInstanceIdentifier candidatePath = candidate.getRootPath(); if (candidatePath.isEmpty()) { try (DataTreeModificationCursor cursor = modification.openCursor()) { DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode()); } } else { try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) { DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode()); } } }
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) { final YangInstanceIdentifier candidatePath = candidate.getRootPath(); if (candidatePath.isEmpty()) { try (DataTreeModificationCursor cursor = modification.openCursor()) { DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode()); } } else { try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) { DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode()); } } }
/** * Subclasses of this class are required to implement creation of parent nodes based on behaviour of their * underlying transaction. * * @param store an instance of LogicalDatastoreType * @param domPath an instance of YangInstanceIdentifier * @param path an instance of InstanceIdentifier */ protected final void ensureParentsByMerge(final LogicalDatastoreType store, final YangInstanceIdentifier domPath, final InstanceIdentifier<?> path) { final YangInstanceIdentifier parentPath = domPath.getParent(); if (parentPath != null) { final NormalizedNode<?, ?> parentNode = getCodec().instanceIdentifierToNode(parentPath); getDelegate().merge(store, YangInstanceIdentifier.create(parentNode.getIdentifier()), parentNode); } }
/** * Subclasses of this class are required to implement creation of parent nodes based on behavior of their * underlying transaction. * * @param store * - an instance of LogicalDatastoreType * @param domPath * - an instance of YangInstanceIdentifier * @param path * - an instance of InstanceIdentifier */ protected final void ensureParentsByMerge(final LogicalDatastoreType store, final YangInstanceIdentifier domPath, final InstanceIdentifier<?> path) { final YangInstanceIdentifier parentPath = domPath.getParent(); if (parentPath != null) { final NormalizedNode<?, ?> parentNode = getCodec().instanceIdentifierToNode(parentPath); getDelegate().merge(store, YangInstanceIdentifier.create(parentNode.getIdentifier()), parentNode); } }