+ this.identifier = requireNonNull(identifier);
+ }
+
+ private static int calculateSize(final @NonNull 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 = ((StackedYangInstanceIdentifier) current).getParent();
+ }
+ }
+
+ @Override
+ public int size() {
+ int ret = size;
+ if (ret == 0) {
+ ret = calculateSize(identifier.getParent());
+ size = ret;
+ }
+
+ return ret;
+ }
+
+ @Override
+ @SuppressWarnings("checkstyle:parameterName")
+ public boolean contains(final Object o) {
+ final PathArgument srch = (PathArgument) requireNonNull(o);
+ return Iterators.contains(iterator(), srch);
+ }
+
+ @Override
+ public PathArgument get(final int index) {
+ return Iterators.get(iterator(), index);
+ }
+
+ @Override
+ @SuppressWarnings("checkstyle:parameterName")
+ public int indexOf(final Object o) {
+ final PathArgument srch = (PathArgument) requireNonNull(o);
+ return super.indexOf(srch);
+ }
+
+ @Override
+ @SuppressWarnings("checkstyle:parameterName")
+ public int lastIndexOf(final Object o) {
+ final PathArgument srch = (PathArgument) requireNonNull(o);
+
+ int ret = -1;
+ final Iterator<PathArgument> it = iterator();
+ for (int i = 0; it.hasNext(); ++i) {
+ if (srch.equals(it.next())) {
+ ret = i;
+ }
+ }
+
+ return ret;