2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.api;
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Verify;
12 import com.google.common.collect.UnmodifiableIterator;
13 import java.util.Iterator;
14 import java.util.List;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 final class StackedPathArguments extends PathArgumentList {
19 private final List<PathArgument> base;
20 private final List<PathArgument> stack;
22 StackedPathArguments(@Nonnull final YangInstanceIdentifier base, @Nonnull final List<PathArgument> stack) {
23 Verify.verify(!stack.isEmpty());
24 this.base = base.getPathArguments();
30 return stack.size() + base.size();
34 @SuppressWarnings("checkstyle:parameterName")
35 public boolean contains(final Object o) {
36 final PathArgument srch = (PathArgument) Preconditions.checkNotNull(o);
37 return stack.contains(srch) || base.contains(srch);
41 public PathArgument get(final int index) {
42 if (index < base.size()) {
43 return base.get(index);
45 return stack.get(index - base.size());
49 @SuppressWarnings("checkstyle:parameterName")
50 public int indexOf(final Object o) {
51 final PathArgument srch = (PathArgument) Preconditions.checkNotNull(o);
53 int ret = base.indexOf(srch);
55 ret = stack.indexOf(srch);
57 return base.size() + ret;
64 @SuppressWarnings("checkstyle:parameterName")
65 public int lastIndexOf(final Object o) {
66 final PathArgument srch = (PathArgument) Preconditions.checkNotNull(o);
68 final int ret = stack.lastIndexOf(srch);
70 return base.size() + ret;
73 return base.lastIndexOf(srch);
78 public UnmodifiableIterator<PathArgument> iterator() {
79 return new IteratorImpl(base, stack);
82 private static final class IteratorImpl extends UnmodifiableIterator<PathArgument> {
83 private final Iterator<PathArgument> stack;
84 private final Iterator<PathArgument> base;
86 IteratorImpl(final Iterable<PathArgument> base, final Iterable<PathArgument> stack) {
87 this.base = base.iterator();
88 this.stack = stack.iterator();
92 public boolean hasNext() {
93 return stack.hasNext();
97 public PathArgument next() {