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   *  https://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.api.ldap.model.cursor;
20  
21  
22  import java.io.IOException;
23  
24  import org.apache.directory.api.i18n.I18n;
25  import org.apache.directory.api.ldap.model.constants.Loggers;
26  import org.apache.directory.api.ldap.model.exception.LdapException;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  
31  /**
32   * An empty Cursor implementation.
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @param <E> The type of element on which this cursor will iterate
36   */
37  public class EmptyCursor<E> extends AbstractCursor<E>
38  {
39      /** A dedicated log for cursors */
40      private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() );
41  
42      /**
43       * Creates a new EmptyCursor instance
44       */
45      public EmptyCursor()
46      {
47          if ( LOG_CURSOR.isDebugEnabled() )
48          {
49              LOG_CURSOR.debug( I18n.msg( I18n.MSG_13103_CREATING_EMPTY_CURSOR, this ) );
50          }
51      }
52  
53  
54      /**
55       * {@inheritDoc}
56       */
57      @Override
58      public boolean available()
59      {
60          return false;
61      }
62  
63  
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public void before( E element ) throws LdapException, CursorException
69      {
70          checkNotClosed();
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public void after( E element ) throws LdapException, CursorException
79      {
80          checkNotClosed();
81      }
82  
83  
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      public void beforeFirst() throws LdapException, CursorException
89      {
90          checkNotClosed();
91      }
92  
93  
94      /**
95       * {@inheritDoc}
96       */
97      @Override
98      public void afterLast() throws LdapException, CursorException
99      {
100         checkNotClosed();
101     }
102 
103 
104     /**
105      * {@inheritDoc}
106      */
107     @Override
108     public boolean first() throws LdapException, CursorException
109     {
110         checkNotClosed();
111         return false;
112     }
113 
114 
115     /**
116      * {@inheritDoc}
117      */
118     @Override
119     public boolean last() throws LdapException, CursorException
120     {
121         checkNotClosed();
122         return false;
123     }
124 
125 
126     /**
127      * {@inheritDoc}
128      */
129     @Override
130     public boolean previous() throws LdapException, CursorException
131     {
132         checkNotClosed();
133         return false;
134     }
135 
136 
137     /**
138      * {@inheritDoc}
139      */
140     @Override
141     public boolean next() throws LdapException, CursorException
142     {
143         checkNotClosed();
144         return false;
145     }
146 
147 
148     /**
149      * {@inheritDoc}
150      */
151     @Override
152     public E get() throws CursorException
153     {
154         checkNotClosed();
155         throw new InvalidCursorPositionException( I18n.err( I18n.ERR_13104_EMPTY_CURSOR ) );
156     }
157 
158 
159     /**
160      * {@inheritDoc}
161      */
162     @Override
163     public void close() throws IOException
164     {
165         if ( LOG_CURSOR.isDebugEnabled() )
166         {
167             LOG_CURSOR.debug( I18n.msg( I18n.MSG_13100_CLOSING_EMPTY_CURSOR, this ) );
168         }
169 
170         super.close();
171     }
172 
173 
174     /**
175      * {@inheritDoc}
176      */
177     @Override
178     public void close( Exception cause ) throws IOException
179     {
180         if ( LOG_CURSOR.isDebugEnabled() )
181         {
182             LOG_CURSOR.debug( I18n.msg( I18n.MSG_13100_CLOSING_EMPTY_CURSOR, this ) );
183         }
184 
185         super.close( cause );
186     }
187 }