1 package com.bonevich.java.util;
2
3 import java.util.*;
4
5 /***
6 * An implementation of <code>java.util.Iterator</code> that
7 * is immutable and therefore cannot remove items from the backing
8 * list.
9 * @see java.util.Iterator
10 * @author Jeffrey D. Bonevich <bonevich@telocity.com>
11 */
12 public class ImmutableIterator implements java.util.Iterator
13 {
14 /////////////////////////////////////////////////////////
15 // Associations
16 private Iterator _itr;
17
18 //////////////////////////////////////////////////////////
19 // Constructors
20 public ImmutableIterator(Iterator itr)
21 {
22 _itr = itr;
23 }
24
25 public ImmutableIterator(Collection coll)
26 {
27 this(coll.iterator());
28 }
29
30 /////////////////////////////////////////////////////////
31 // Operations
32 public boolean hasNext()
33 {
34 return _itr.hasNext();
35 }
36
37 public Object next()
38 {
39 return _itr.next();
40 }
41
42 /*** Throws <code>java.lang.UnsupportedOperationException</code>. */
43 public void remove()
44 {
45 throw new UnsupportedOperationException("This is an immutable iterator, pal! You cannot remove items!");
46 }
47
48 } /* end class ImmutableIterator */
49
50
This page was automatically generated by Maven