1 17 18 19 package org.apache.catalina.util; 20 21 22 import java.util.Collection ; 23 import java.util.Enumeration ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Map ; 28 import java.util.NoSuchElementException ; 29 30 31 40 41 public final class Enumerator implements Enumeration { 42 43 44 46 47 52 public Enumerator(Collection collection) { 53 54 this(collection.iterator()); 55 56 } 57 58 59 65 public Enumerator(Collection collection, boolean clone) { 66 67 this(collection.iterator(), clone); 68 69 } 70 71 72 78 public Enumerator(Iterator iterator) { 79 80 super(); 81 this.iterator = iterator; 82 83 } 84 85 86 93 public Enumerator(Iterator iterator, boolean clone) { 94 95 super(); 96 if (!clone) { 97 this.iterator = iterator; 98 } else { 99 List list = new ArrayList (); 100 while (iterator.hasNext()) { 101 list.add(iterator.next()); 102 } 103 this.iterator = list.iterator(); 104 } 105 106 } 107 108 109 114 public Enumerator(Map map) { 115 116 this(map.values().iterator()); 117 118 } 119 120 121 127 public Enumerator(Map map, boolean clone) { 128 129 this(map.values().iterator(), clone); 130 131 } 132 133 134 136 137 141 private Iterator iterator = null; 142 143 144 146 147 154 public boolean hasMoreElements() { 155 156 return (iterator.hasNext()); 157 158 } 159 160 161 169 public Object nextElement() throws NoSuchElementException { 170 171 return (iterator.next()); 172 173 } 174 175 176 } 177 | Popular Tags |