| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.framework; |
| 12 | |
| 13 | import java.util.Iterator; |
| 14 | |
| 15 | final class UnmodifiableIteratorFactory |
| 16 | { |
| 17 | private UnmodifiableIteratorFactory() |
| 18 | { |
| 19 | |
| 20 | } |
| 21 | |
| 22 | static <E> Iterator<E> unmodifiableIterator(final Iterator<E> i) throws NullPointerException |
| 23 | { |
| 24 | if(i == null) |
| 25 | { |
| 26 | throw new NullPointerException(); |
| 27 | } |
| 28 | |
| 29 | return new UnmodifiableIterator<E>(i); |
| 30 | } |
| 31 | |
| 32 | private static final class UnmodifiableIterator<E> implements Iterator<E> |
| 33 | { |
| 34 | private final Iterator<E> i; |
| 35 | |
| 36 | UnmodifiableIterator(final Iterator<E> i) |
| 37 | { |
| 38 | this.i = i; |
| 39 | } |
| 40 | |
| 41 | public boolean hasNext() |
| 42 | { |
| 43 | return i.hasNext(); |
| 44 | } |
| 45 | |
| 46 | public E next() |
| 47 | { |
| 48 | return i.next(); |
| 49 | } |
| 50 | |
| 51 | public void remove() |
| 52 | { |
| 53 | throw new UnsupportedOperationException(); |
| 54 | } |
| 55 | } |
| 56 | } |