1 package org.exolab.castor.mapping.loader.collection.handler; 2 3 import java.util.Enumeration; 4 import java.util.Vector; 5 6 import org.exolab.castor.mapping.CollectionHandler; 7 import org.exolab.castor.mapping.loader.CollectionHandlers; 8 9 public final class VectorCollectionHandler<T> implements CollectionHandler<T> { 10 11 @SuppressWarnings("unchecked") 12 public Object add(Object collection, T object) { 13 if (collection == null) { 14 collection = new Vector<T>(); 15 ((Vector<T>) collection).addElement(object); 16 return collection; 17 } 18 ((Vector<T>) collection).addElement(object); 19 return null; 20 } 21 22 @SuppressWarnings("unchecked") 23 public Enumeration<T> elements(Object collection) { 24 if (collection == null) 25 return new CollectionHandlers.EmptyEnumerator<T>(); 26 return ((Vector<T>) collection).elements(); 27 } 28 29 @SuppressWarnings("unchecked") 30 public int size(Object collection) { 31 if (collection == null) 32 return 0; 33 return ((Vector<T>) collection).size(); 34 } 35 36 @SuppressWarnings("unchecked") 37 public Object clear(Object collection) { 38 if (collection != null) 39 ((Vector<T>) collection).removeAllElements(); 40 return null; 41 } 42 43 public String toString() { 44 return "Vector"; 45 } 46 }