1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.jcr;
25
26 import java.util.Iterator;
27 import javax.jcr.NodeIterator;
28 import net.jcip.annotations.Immutable;
29 import org.modeshape.common.util.CheckArg;
30
31 /**
32 * A concrete {@link NodeIterator} implementation.
33 */
34 @Immutable
35 final class JcrChildNodeIterator implements NodeIterator {
36
37 private final Iterator<AbstractJcrNode> iterator;
38 private int ndx;
39 private int size;
40
41 JcrChildNodeIterator( Iterable<AbstractJcrNode> children,
42 int size ) {
43 assert children != null;
44 iterator = children.iterator();
45 this.size = size;
46 }
47
48 /**
49 * {@inheritDoc}
50 *
51 * @see javax.jcr.RangeIterator#getPosition()
52 */
53 public long getPosition() {
54 return ndx;
55 }
56
57 /**
58 * {@inheritDoc}
59 *
60 * @see javax.jcr.RangeIterator#getSize()
61 */
62 public long getSize() {
63 return size;
64 }
65
66 /**
67 * {@inheritDoc}
68 *
69 * @see java.util.Iterator#hasNext()
70 */
71 public boolean hasNext() {
72 return iterator.hasNext();
73 }
74
75 /**
76 * {@inheritDoc}
77 *
78 * @see java.util.Iterator#next()
79 */
80 public Object next() {
81 return nextNode();
82 }
83
84 /**
85 * {@inheritDoc}
86 *
87 * @see javax.jcr.NodeIterator#nextNode()
88 */
89 public javax.jcr.Node nextNode() {
90 AbstractJcrNode child = iterator.next();
91 ndx++;
92 return child;
93 }
94
95 /**
96 * {@inheritDoc}
97 *
98 * @throws UnsupportedOperationException always
99 * @see java.util.Iterator#remove()
100 */
101 public void remove() {
102 throw new UnsupportedOperationException();
103 }
104
105 /**
106 * {@inheritDoc}
107 *
108 * @throws IllegalArgumentException if <code>count</code> is negative.
109 * @see javax.jcr.RangeIterator#skip(long)
110 */
111 public void skip( long count ) {
112 CheckArg.isNonNegative(count, "count");
113 while (--count >= 0) {
114 nextNode();
115 }
116 }
117 }