1 16 package org.apache.commons.collections.iterators; 17 18 import java.util.Iterator ; 19 20 import org.apache.commons.collections.Unmodifiable; 21 22 30 public final class UnmodifiableIterator implements Iterator , Unmodifiable { 31 32 33 private Iterator iterator; 34 35 44 public static Iterator decorate(Iterator iterator) { 45 if (iterator == null) { 46 throw new IllegalArgumentException ("Iterator must not be null"); 47 } 48 if (iterator instanceof Unmodifiable) { 49 return iterator; 50 } 51 return new UnmodifiableIterator(iterator); 52 } 53 54 60 private UnmodifiableIterator(Iterator iterator) { 61 super(); 62 this.iterator = iterator; 63 } 64 65 public boolean hasNext() { 67 return iterator.hasNext(); 68 } 69 70 public Object next() { 71 return iterator.next(); 72 } 73 74 public void remove() { 75 throw new UnsupportedOperationException ("remove() is not supported"); 76 } 77 78 } 79 | Popular Tags |