Propagate @Nonnull and @Nullable annotations
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / StackedPathArguments.java
index ed9d65b8ba2f80a1c2e7c5be68f9bee50d39a761..690e2a438b3c3f9a32fe3e24fea30255a91caeab 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -7,19 +8,21 @@
 package org.opendaylight.yangtools.yang.data.api;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
 import com.google.common.collect.UnmodifiableIterator;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
-final class StackedPathArguments extends PathArgumentCollection {
-    private final Collection<PathArgument> base;
+final class StackedPathArguments extends PathArgumentList {
+    private final List<PathArgument> base;
     private final List<PathArgument> stack;
 
-    public StackedPathArguments(final YangInstanceIdentifier base, final List<PathArgument> stack) {
+    public StackedPathArguments(@Nonnull final YangInstanceIdentifier base, @Nonnull final List<PathArgument> stack) {
+        Verify.verify(!stack.isEmpty());
         this.base = base.getPathArguments();
-        this.stack = Preconditions.checkNotNull(stack);
+        this.stack = stack;
     }
 
     @Override
@@ -33,6 +36,41 @@ final class StackedPathArguments extends PathArgumentCollection {
         return stack.contains(srch) || base.contains(srch);
     }
 
+    @Override
+    public PathArgument get(final int index) {
+        if (index < base.size()) {
+            return base.get(index);
+        }
+        return stack.get(index - base.size());
+    }
+
+    @Override
+    public int indexOf(final Object o) {
+        final PathArgument srch = (PathArgument) Preconditions.checkNotNull(o);
+
+        int ret = base.indexOf(srch);
+        if (ret == -1) {
+            ret = stack.indexOf(srch);
+            if (ret != -1) {
+                return base.size() + ret;
+            }
+        }
+        return ret;
+    }
+
+    @Override
+    public int lastIndexOf(final Object o) {
+        final PathArgument srch = (PathArgument) Preconditions.checkNotNull(o);
+
+        final int ret = stack.lastIndexOf(srch);
+        if (ret != -1) {
+            return base.size() + ret;
+        }
+
+        return base.lastIndexOf(srch);
+    }
+
+    @Nonnull
     @Override
     public UnmodifiableIterator<PathArgument> iterator() {
         return new IteratorImpl(base, stack);