org.exolab.castor.mapping.loader.collection.handler.QueueCollectionHandler Maven / Gradle / Ivy
package org.exolab.castor.mapping.loader.collection.handler;
import java.util.Enumeration;
import java.util.PriorityQueue;
import java.util.Queue;
import org.exolab.castor.mapping.CollectionHandler;
import org.exolab.castor.mapping.loader.CollectionHandlers;
import org.exolab.castor.mapping.loader.J2CollectionHandlers.IteratorEnumerator;
public final class QueueCollectionHandler implements CollectionHandler {
@SuppressWarnings("unchecked")
public Object add(Object collection, T object) {
if (collection == null) {
collection = new PriorityQueue();
((Queue) collection).add(object);
return collection;
}
((Queue) collection).add(object);
return null;
}
@SuppressWarnings("unchecked")
public Enumeration elements(Object collection) {
if (collection == null)
return new CollectionHandlers.EmptyEnumerator();
return new IteratorEnumerator(((Queue) collection).iterator());
}
@SuppressWarnings("unchecked")
public int size(Object collection) {
if (collection == null)
return 0;
return ((Queue) collection).size();
}
@SuppressWarnings("unchecked")
public Object clear(Object collection) {
if (collection != null)
((Queue) collection).clear();
return null;
}
public String toString() {
return "Queue";
}
}