1 16 package org.apache.commons.collections.iterators; 17 18 import java.util.Collection ; 19 import java.util.Enumeration ; 20 import java.util.Iterator ; 21 22 32 public class EnumerationIterator implements Iterator { 33 34 35 private Collection collection; 36 37 private Enumeration enumeration; 38 39 private Object last; 40 41 47 public EnumerationIterator() { 48 this(null, null); 49 } 50 51 57 public EnumerationIterator(final Enumeration enumeration) { 58 this(enumeration, null); 59 } 60 61 68 public EnumerationIterator(final Enumeration enumeration, final Collection collection) { 69 super(); 70 this.enumeration = enumeration; 71 this.collection = collection; 72 this.last = null; 73 } 74 75 83 public boolean hasNext() { 84 return enumeration.hasMoreElements(); 85 } 86 87 93 public Object next() { 94 last = enumeration.nextElement(); 95 return last; 96 } 97 98 108 public void remove() { 109 if (collection != null) { 110 if (last != null) { 111 collection.remove(last); 112 } else { 113 throw new IllegalStateException ("next() must have been called for remove() to function"); 114 } 115 } else { 116 throw new UnsupportedOperationException ("No Collection associated with this Iterator"); 117 } 118 } 119 120 127 public Enumeration getEnumeration() { 128 return enumeration; 129 } 130 131 136 public void setEnumeration(final Enumeration enumeration) { 137 this.enumeration = enumeration; 138 } 139 140 } 141 | Popular Tags |