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