001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020
021 package org.apache.directory.shared.ldap.message;
022
023
024 import java.util.Iterator;
025 import javax.naming.NamingEnumeration;
026
027
028 /**
029 * A NamingEnumeration over an Iterator.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Revision: 510365 $
033 */
034 public class IteratorNamingEnumeration<T> implements NamingEnumeration<T>
035 {
036 /** the iterator to wrap as in the enumeration */
037 private Iterator<T> iterator;
038
039
040 /**
041 * Creates a NamingEnumeration over an Iterator.
042 *
043 * @param iterator
044 * the Iterator the NamingEnumeration is based on.
045 */
046 public IteratorNamingEnumeration( Iterator<T> iterator)
047 {
048 this.iterator = iterator;
049 }
050
051
052 // --------------------------------------------------------------------
053 // Enumeration Interface Method Implementations
054 // --------------------------------------------------------------------
055
056 /**
057 * @see java.util.Enumeration#hasMoreElements()
058 */
059 public boolean hasMoreElements()
060 {
061 return iterator.hasNext();
062 }
063
064
065 /**
066 * @see java.util.Enumeration#nextElement()
067 */
068 public T nextElement()
069 {
070 return iterator.next();
071 }
072
073
074 // --------------------------------------------------------------------
075 // NamingEnumeration Interface Method Implementations
076 // --------------------------------------------------------------------
077
078 /**
079 * @see javax.naming.NamingEnumeration#close()
080 */
081 public void close()
082 {
083 // Does nothing!
084 }
085
086
087 /**
088 * @see javax.naming.NamingEnumeration#hasMore()
089 */
090 public boolean hasMore()
091 {
092 return iterator.hasNext();
093 }
094
095
096 /**
097 * @see javax.naming.NamingEnumeration#next()
098 */
099 public T next()
100 {
101 return iterator.next();
102 }
103 }