@Override public int size() { int ret = size; if (!haveSize) { ret = calculateSize(identifier.getParent()); size = ret; haveSize = true; } return ret; }
@Override public int size() { int ret = size; if (!haveSize) { ret = calculateSize(identifier.getParent()); size = ret; haveSize = true; } return ret; }
@Override public PathArgument next() { if (tail != null) { return tail.next(); } final PathArgument ret = identifier.getLastPathArgument(); final YangInstanceIdentifier next = identifier.getParent(); final Iterable<PathArgument> args = next.tryReversePathArguments(); if (args != null) { tail = args.iterator(); identifier = null; } else { verify(next instanceof StackedYangInstanceIdentifier); identifier = (StackedYangInstanceIdentifier) next; } return ret; } }
@Override public PathArgument next() { if (tail != null) { return tail.next(); } final PathArgument ret = identifier.getLastPathArgument(); final YangInstanceIdentifier next = identifier.getParent(); final Iterable<PathArgument> args = next.tryReversePathArguments(); if (args != null) { tail = args.iterator(); identifier = null; } else { verify(next instanceof StackedYangInstanceIdentifier); identifier = (StackedYangInstanceIdentifier) next; } return ret; } }
@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; }
@Override public List<PathArgument> getPathArguments() { StackedPathArguments ret = tryPathArguments(); if (ret == null) { final List<PathArgument> stack = new ArrayList<>(); YangInstanceIdentifier current = this; do { verify(current instanceof StackedYangInstanceIdentifier); final StackedYangInstanceIdentifier stacked = (StackedYangInstanceIdentifier) current; stack.add(stacked.getLastPathArgument()); current = stacked.getParent(); } while (current.tryPathArguments() == null); ret = new StackedPathArguments(current, Lists.reverse(stack)); pathArguments = ret; } return ret; }
@Override public List<PathArgument> getPathArguments() { StackedPathArguments ret = tryPathArguments(); if (ret == null) { final List<PathArgument> stack = new ArrayList<>(); YangInstanceIdentifier current = this; do { verify(current instanceof StackedYangInstanceIdentifier); final StackedYangInstanceIdentifier stacked = (StackedYangInstanceIdentifier) current; stack.add(stacked.getLastPathArgument()); current = stacked.getParent(); } while (current.tryPathArguments() == null); ret = new StackedPathArguments(current, Lists.reverse(stack)); pathArguments = ret; } return ret; }