SoftNet-Consult Java Utility Library

com.softnetConsult.utils.collections
Class ReadOnlyIterator<T>

java.lang.Object
  extended by com.softnetConsult.utils.collections.ReadOnlyIterator<T>
Type Parameters:
T - A class type of the objects over which this iterator iterates.
All Implemented Interfaces:
java.util.Iterator<T>

public class ReadOnlyIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>

A generic read-only iterator. A ReadOnlyIterator<T> object wraps around an Iterator<? extends T> object and simply forwards all read-only method calls to it. Modifying operations (i.e. remove throw a UnsupportedOperationException.

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: ReadOnlyIterator.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  java.util.Iterator<? extends T> iterator
          The encapsulated generic iterator;
 
Constructor Summary
ReadOnlyIterator(java.lang.Iterable<? extends T> iterable)
          Creates a read-only iteretor for the iterator over the specified iterable object.
ReadOnlyIterator(java.util.Iterator<? extends T> iterator)
          Creates a read-only iteretor for the specified iterator.
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
 T next()
          Returns the next element in the iteration.
 void remove()
          Always throws UnsupportedOperationException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iterator

private java.util.Iterator<? extends T> iterator
The encapsulated generic iterator;

Constructor Detail

ReadOnlyIterator

public ReadOnlyIterator(java.util.Iterator<? extends T> iterator)
Creates a read-only iteretor for the specified iterator.

Parameters:
iterator - An iterator.

ReadOnlyIterator

public ReadOnlyIterator(java.lang.Iterable<? extends T> iterable)
Creates a read-only iteretor for the iterator over the specified iterable object.

Parameters:
iterable - An iterable object whose iterator will be wraped by this read only iterator.
Method Detail

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if true would return an element rather than throwing an exception.)

Specified by:
hasNext in interface java.util.Iterator<T>
Returns:
true if the iterator has more elements.

next

public T next()
Returns the next element in the iteration.

Specified by:
next in interface java.util.Iterator<T>
Returns:
the next element in the iteration.
Throws:
java.util.NoSuchElementException - iteration has no more elements.

remove

public void remove()
Always throws UnsupportedOperationException.

Specified by:
remove in interface java.util.Iterator<T>
Throws:
java.lang.UnsupportedOperationException - Always thrown since this is a read-only iterator.

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