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.Iterator;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 final class StackedReversePathArguments implements Iterable<PathArgument> {
15 private final StackedYangInstanceIdentifier identifier;
17 StackedReversePathArguments(final StackedYangInstanceIdentifier identifier) {
18 this.identifier = Preconditions.checkNotNull(identifier);
22 public Iterator<PathArgument> iterator() {
23 return new IteratorImpl(identifier);
26 private static final class IteratorImpl extends UnmodifiableIterator<PathArgument> {
27 private StackedYangInstanceIdentifier identifier;
28 private Iterator<PathArgument> tail;
30 IteratorImpl(final StackedYangInstanceIdentifier identifier) {
31 this.identifier = Preconditions.checkNotNull(identifier);
35 public boolean hasNext() {
36 return tail == null || tail.hasNext();
40 public PathArgument next() {
45 final PathArgument ret = identifier.getLastPathArgument();
46 final YangInstanceIdentifier next = identifier.getParent();
47 if (!(next instanceof StackedYangInstanceIdentifier)) {
48 tail = next.getReversePathArguments().iterator();
51 identifier = (StackedYangInstanceIdentifier) next;