1 45 package org.openejb.util; 46 47 import java.io.Externalizable ; 48 import java.io.IOException ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectOutput ; 51 import java.util.Enumeration ; 52 import java.util.NoSuchElementException ; 53 import java.util.Vector ; 54 55 62 public final class ArrayEnumeration implements Enumeration , Externalizable { 63 static final long serialVersionUID = -1194966576855523042L; 64 65 private Object [] elements; 66 private int elementsIndex; 67 68 public ArrayEnumeration(Vector elements){ 69 this.elements = new Object [elements.size()]; 70 elements.copyInto(this.elements); 71 } 72 73 public ArrayEnumeration(java.util.List list){ 74 this.elements = new Object [list.size()]; 75 list.toArray(this.elements); 76 } 77 78 public ArrayEnumeration() { 80 } 81 82 public java.lang.Object get(int index) { 86 return elements[index]; 87 } 88 89 public void set(int index, java.lang.Object o) { 90 elements[index] = o; 91 } 92 93 public int size() { 94 return elements.length; 95 } 96 97 101 108 public boolean hasMoreElements(){ 109 return ( elementsIndex < elements.length ); 110 } 111 112 119 public Object nextElement(){ 120 if ( !hasMoreElements()) throw new NoSuchElementException ("No more elements exist"); 121 return elements[elementsIndex++]; 122 } 123 124 128 132 146 public void writeExternal(ObjectOutput out) throws IOException { 147 out.writeInt(elements.length); 148 out.writeInt(elementsIndex); 149 for (int i=0; i < elements.length; i++) { 150 out.writeObject(elements[i]); 151 } 152 } 153 154 163 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 164 elements = new Object [in.readInt()]; 165 elementsIndex = in.readInt(); 166 for (int i=0; i < elements.length; i++) { 167 elements[i] = in.readObject(); 168 } 169 } 170 171 175 176 } 177 178 | Popular Tags |