2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5 * and is available at http://www.eclipse.org/legal/epl-v10.html
7 package org.opendaylight.yangtools.yang.data.api;
9 import com.google.common.base.Preconditions;
10 import com.google.common.collect.UnmodifiableIterator;
11 import java.util.Collection;
12 import java.util.Iterator;
13 import java.util.List;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 final class StackedPathArguments implements Iterable<PathArgument> {
17 private final List<StackedYangInstanceIdentifier> stack;
18 private final YangInstanceIdentifier base;
20 public StackedPathArguments(final YangInstanceIdentifier base, final List<StackedYangInstanceIdentifier> stack) {
21 this.base = Preconditions.checkNotNull(base);
22 this.stack = Preconditions.checkNotNull(stack);
26 public Iterator<PathArgument> iterator() {
27 return new IteratorImpl(base, stack);
30 private static final class IteratorImpl extends UnmodifiableIterator<PathArgument> {
31 private final Iterator<StackedYangInstanceIdentifier> stack;
32 private final Iterator<PathArgument> base;
34 IteratorImpl(final YangInstanceIdentifier base, final Collection<StackedYangInstanceIdentifier> stack) {
35 this.base = base.getPathArguments().iterator();
36 this.stack = stack.iterator();
40 public boolean hasNext() {
41 return stack.hasNext();
45 public PathArgument next() {
49 return stack.next().getLastPathArgument();