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 */ 020package org.apache.directory.api.util; 021 022 023import java.util.NoSuchElementException; 024 025import javax.naming.NamingException; 026import javax.naming.NamingEnumeration; 027 028 029/** 030 * An empty NamingEnumeration without any values: meaning 031 * hasMore/hasMoreElements() always returns false, and next/nextElement() always 032 * throws a NoSuchElementException. 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 */ 036public class EmptyEnumeration<T> implements NamingEnumeration<T> 037{ 038 039 /** 040 * @see javax.naming.NamingEnumeration#close() 041 */ 042 public void close() 043 { 044 } 045 046 047 /** 048 * Always returns false. 049 * 050 * @see javax.naming.NamingEnumeration#hasMore() 051 */ 052 public boolean hasMore() throws NamingException 053 { 054 return false; 055 } 056 057 058 /** 059 * Always throws NoSuchElementException. 060 * 061 * @see javax.naming.NamingEnumeration#next() 062 */ 063 public T next() throws NamingException 064 { 065 throw new NoSuchElementException(); 066 } 067 068 069 /** 070 * Always return false. 071 * 072 * @see java.util.Enumeration#hasMoreElements() 073 */ 074 public boolean hasMoreElements() 075 { 076 return false; 077 } 078 079 080 /** 081 * Always throws NoSuchElementException. 082 * 083 * @see java.util.Enumeration#nextElement() 084 */ 085 public T nextElement() 086 { 087 throw new NoSuchElementException(); 088 } 089 090}