SoftNet-Consult Java Utility Library

com.softnetConsult.utils.collections
Class NullIterator<ET>

java.lang.Object
  extended by com.softnetConsult.utils.collections.NullIterator<ET>
Type Parameters:
ET -
All Implemented Interfaces:
java.util.Iterator<ET>

public final class NullIterator<ET>
extends java.lang.Object
implements java.util.Iterator<ET>

Provides an Null Iterator: the methods of this class perform no action and no elements are ever returned - this class can be used when a non-null Iterator object must be specified, but no actual iteration indended.

This product includes software developed by the SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.

File: NullIterator.java
Library API version: "2.02"
Java compliance version: "1.5"

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:

1. Redistributions of source code must retain the above acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library project and its contributors.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version:
"2.02"
Author:
Greg Paperin (http://www.paperin.org)

Field Summary
private static NullIterator<?> singeltonInstance
          A singleton instance of the NullIterator.
 
Constructor Summary
NullIterator()
          Constructs a new NullIterator.
 
Method Summary
static
<T> NullIterator<T>
getSingeltonInstance()
          Returns a singleton instance of NullIterator.
static
<T> NullIterator<T>
getSingeltonInstance(java.lang.Class<T> iteratorElementType)
          Returns a singleton instance of NullIterator.
 boolean hasNext()
          Returns false as the NullIterator has nothing to iterate over.
 ET next()
          Always throws a NoSuchElementException as the NullIterator has nothing to iterate over.
 void remove()
          Always throws a IllegalStateException as the NullIterator has nothing to remove.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singeltonInstance

private static NullIterator<?> singeltonInstance
A singleton instance of the NullIterator.

Constructor Detail

NullIterator

public NullIterator()
Constructs a new NullIterator.

Method Detail

getSingeltonInstance

public static <T> NullIterator<T> getSingeltonInstance()
Returns a singleton instance of NullIterator.

Type Parameters:
T - The type for the hypothetically iterated items.
Returns:
A singleton NullIterator instance.

getSingeltonInstance

public static <T> NullIterator<T> getSingeltonInstance(java.lang.Class<T> iteratorElementType)
Returns a singleton instance of NullIterator. This method works in the same way as getSingeltonInstance(), the parameter can be used to explicity specify the iterator type.

Type Parameters:
T - The type for the hypothetically iterated items.
Parameters:
iteratorElementType - The type for the hypothetically iterated items.
Returns:
A singleton NullIterator instance.

hasNext

public boolean hasNext()
Returns false as the NullIterator has nothing to iterate over.

Specified by:
hasNext in interface java.util.Iterator<ET>
Returns:
false.

next

public ET next()
Always throws a NoSuchElementException as the NullIterator has nothing to iterate over.

Specified by:
next in interface java.util.Iterator<ET>
Returns:
Never returns normally as an exception is always thrown.
Throws:
java.util.NoSuchElementException - Always, as the NullIterator has nothing to iterate over.

remove

public void remove()
Always throws a IllegalStateException as the NullIterator has nothing to remove.

Specified by:
remove in interface java.util.Iterator<ET>
Throws:
java.lang.IllegalStateException - Always, as the NullIterator has nothing to remove.

SoftNet-Consult Java Utility Library is a member of SourceForge.net