View Javadoc

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.Collection;
27  import java.util.Iterator;
28  import javax.jcr.Property;
29  import javax.jcr.PropertyIterator;
30  import net.jcip.annotations.Immutable;
31  import org.modeshape.common.util.CheckArg;
32  
33  /**
34   * ModeShape implementation of a {@link PropertyIterator}.
35   */
36  @Immutable
37  final class JcrPropertyIterator implements PropertyIterator {
38  
39      private final Iterator<? extends Property> iterator;
40      private int ndx;
41      private int size;
42  
43      JcrPropertyIterator( Collection<? extends Property> properties ) {
44          assert properties != null;
45          iterator = properties.iterator();
46          size = properties.size();
47      }
48  
49      /**
50       * {@inheritDoc}
51       * 
52       * @see javax.jcr.RangeIterator#getPosition()
53       */
54      public long getPosition() {
55          return ndx;
56      }
57  
58      /**
59       * {@inheritDoc}
60       * 
61       * @see javax.jcr.RangeIterator#getSize()
62       */
63      public long getSize() {
64          return size;
65      }
66  
67      /**
68       * {@inheritDoc}
69       * 
70       * @see java.util.Iterator#hasNext()
71       */
72      public boolean hasNext() {
73          return iterator.hasNext();
74      }
75  
76      /**
77       * {@inheritDoc}
78       * 
79       * @see java.util.Iterator#next()
80       */
81      public Object next() {
82          return nextProperty();
83      }
84  
85      /**
86       * {@inheritDoc}
87       * 
88       * @see javax.jcr.PropertyIterator#nextProperty()
89       */
90      public Property nextProperty() {
91          Property next = iterator.next();
92          ndx++;
93          return next;
94      }
95  
96      /**
97       * {@inheritDoc}
98       * 
99       * @throws UnsupportedOperationException always
100      * @see java.util.Iterator#remove()
101      */
102     public void remove() {
103         throw new UnsupportedOperationException();
104     }
105 
106     /**
107      * {@inheritDoc}
108      * 
109      * @throws IllegalArgumentException if <code>count</code> is negative.
110      * @see javax.jcr.RangeIterator#skip(long)
111      */
112     public void skip( long count ) {
113         CheckArg.isNonNegative(count, "count");
114         while (--count >= 0) {
115             nextProperty();
116         }
117     }
118 }