1 package com.ca.commons.naming; 2 3 import java.util.*; 4 import java.text.Collator ; 5 import java.text.CollationKey ; 6 7 import javax.naming.*; 8 10 37 38 public class DXNamingEnumeration implements NamingEnumeration 39 { 40 private int pointer = 0; 41 private ArrayList data; 42 43 private static Collator myCollator = Collator.getInstance(); 45 46 52 53 private class SimpleComparator implements Comparator 54 { 55 public int compare(Object o1, Object o2) 56 { 57 return myCollator.compare(o1.toString(), o2.toString()); 58 } 59 } 60 61 62 88 89 93 public DXNamingEnumeration() { data = new ArrayList(); } 94 95 98 public DXNamingEnumeration(Enumeration ne) 99 { 100 data = new ArrayList(); 101 while (ne.hasMoreElements()) 102 add(ne.nextElement()); 103 } 104 105 106 107 111 112 public DXNamingEnumeration(NamingEnumeration ne) 113 { 114 data = new ArrayList(); 115 if (ne!=null) 116 while (ne.hasMoreElements()) 117 add(ne.nextElement()); 118 } 119 120 125 126 public DXNamingEnumeration(ArrayList listData) 127 { 128 data = listData; 129 } 130 131 135 public void add(Object o) { data.add(o); } 136 137 141 public void remove(Object o) { data.remove(o); } 142 143 144 149 public void reset() { pointer = 0; } 150 151 156 public int size() { return data.size(); } 157 158 163 public boolean hasMore() { return (pointer < data.size()); } 164 165 169 public boolean hasMoreElements() { return hasMore(); } 170 171 176 public Object next() throws NoSuchElementException 177 { 178 try 179 { return data.get(pointer++); } 180 catch (ArrayIndexOutOfBoundsException e) 181 { throw new NoSuchElementException(); } 182 } 183 184 189 public Object nextElement() throws NoSuchElementException { return next(); } 190 191 192 198 199 public DXNamingEnumeration sort() 200 { 201 Collections.sort(data, new SimpleComparator()); 202 203 return this; 204 } 205 206 212 213 public DXNamingEnumeration fastSort() 214 { 215 Collections.sort(data); 216 217 return this; 218 } 219 220 224 225 public boolean contains(Object test) 226 { 227 return data.contains(test); 228 } 229 230 235 public void close() {;} 236 237 public String toString() { 239 StringBuffer ret = new StringBuffer (); 240 for (int i=0; i<data.size(); i++) 241 { 242 Object o = data.get(i); 243 ret.append((o==null)?"null":o.toString() + "\n"); 244 } 245 return ret.toString(); 246 } 247 248 public Object [] toArray() 249 { 250 return data.toArray(); 251 } 252 253 254 public String [] toStringArray() 255 { 256 String [] ret = new String [data.size()]; 257 for (int i=0; i<data.size(); i++) 258 { 259 Object o = data.get(i); 260 ret[i] = ((o==null)?null:o.toString()); 261 } 262 return ret; 263 } 264 265 public ArrayList getArrayList() { return data; } 266 } | Popular Tags |