View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.directory.server.core.cursor;
20  
21  
22  import java.util.Iterator;
23  
24  
25  /**
26   * A limited Cursor over an Iterator of elements.
27   *
28   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
29   * @version $Rev$, $Date$
30   */
31  public class IteratorCursor<E> extends AbstractCursor<E>
32  {
33      private final Iterator<E> values;
34      private E current;
35  
36  
37      public IteratorCursor( Iterator<E> values )
38      {
39          this.values = values;
40      }
41  
42  
43      public boolean available()
44      {
45          return current != null;    
46      }
47      
48  
49      public void before( E element )
50      {
51          throw new UnsupportedOperationException( "Cannot advance before an element on the underlying Iterator." );
52      }
53  
54  
55      public void after( E element )
56      {
57          throw new UnsupportedOperationException( "Cannot advance after an element on the underlying Iterator." );
58      }
59  
60  
61      public void beforeFirst()
62      {
63          throw new UnsupportedOperationException( "Cannot advance before first on the underlying Iterator." );
64      }
65  
66  
67      public void afterLast()
68      {
69          throw new UnsupportedOperationException( "Cannot adanvce after last on the underlying Iterator." );
70      }
71  
72  
73      public boolean first()
74      {
75          throw new UnsupportedOperationException( "Cannot advance to first position on the underlying Iterator." );
76      }
77  
78  
79      public boolean last()
80      {
81          throw new UnsupportedOperationException( "Cannot advance to last position on the underlying Iterator." );
82      }
83  
84  
85      public boolean previous()
86      {
87          throw new UnsupportedOperationException( "Cannot back up on the underlying Iterator." );
88      }
89  
90  
91      public boolean next() throws Exception
92      {
93          checkNotClosed( "next()" );
94          if ( values.hasNext() )
95          {
96              current = values.next();
97              return true;
98          }
99  
100         return false;
101     }
102 
103 
104     public E get() throws Exception
105     {
106         checkNotClosed( "get()" );
107         return current;
108     }
109 
110 
111     public boolean isElementReused()
112     {
113         return false;
114     }
115 }