KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > util > AbstractRangeIterator


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.jcr.util;
18
19 import java.util.NoSuchElementException JavaDoc;
20
21 import javax.jcr.RangeIterator;
22
23
24 /**
25  * Alfresco implementation of a Node Iterator
26  *
27  * @author David Caruana
28  */

29 public abstract class AbstractRangeIterator implements RangeIterator
30 {
31     private int position = -1;
32     
33     /**
34      * Construct
35      *
36      * @param context session context
37      * @param nodes node list
38      */

39     public AbstractRangeIterator()
40     {
41     }
42
43     /**
44      * Skip 1 position
45      *
46      * @return current position
47      */

48     protected long skip()
49     {
50         skip(1);
51         return position;
52     }
53         
54     /* (non-Javadoc)
55      * @see javax.jcr.RangeIterator#skip(long)
56      */

57     public void skip(long skipNum)
58     {
59         if (skipNum < 0)
60         {
61             throw new IllegalArgumentException JavaDoc("skipNum must be positive.");
62         }
63         if (position + skipNum >= getSize())
64         {
65             throw new NoSuchElementException JavaDoc("Cannot skip " + skipNum + " elements from position " + getPosition() + " as only " + getSize() + " elements are available.");
66         }
67         position += skipNum;
68     }
69
70     /* (non-Javadoc)
71      * @see javax.jcr.RangeIterator#getPosition()
72      */

73     public long getPosition()
74     {
75         return position + 1;
76     }
77
78     /* (non-Javadoc)
79      * @see java.util.Iterator#hasNext()
80      */

81     public boolean hasNext()
82     {
83         return getPosition() < getSize();
84     }
85
86     /* (non-Javadoc)
87      * @see java.util.Iterator#remove()
88      */

89     public void remove()
90     {
91         throw new UnsupportedOperationException JavaDoc();
92     }
93
94 }
95
Popular Tags