All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.exolab.castor.mapping.loader.collection.handler.HashtableCollectionHandler Maven / Gradle / Ivy

Go to download

The core XML data binding framework with support for marshalling Java objects to and unmarshalling from XML documents.

The newest version!
package org.exolab.castor.mapping.loader.collection.handler;

import java.util.Enumeration;
import java.util.Hashtable;

import org.exolab.castor.mapping.CollectionHandler;
import org.exolab.castor.mapping.MapItem;
import org.exolab.castor.mapping.loader.CollectionHandlers;

public final class HashtableCollectionHandler implements CollectionHandler {

  @SuppressWarnings("unchecked")
  public Object add(Object collection, T object) {

    T key = object;
    T value = object;

    if (object instanceof org.exolab.castor.mapping.MapItem) {
      MapItem mapItem = (MapItem) object;
      key = mapItem.getKey();
      value = mapItem.getValue();
      if (value == null) {
        value = object;
      }
      if (key == null) {
        key = value;
      }
    }

    if (collection == null) {
      collection = new Hashtable();
      ((Hashtable) collection).put(key, value);
      return collection;
    }
    ((Hashtable) collection).put(key, value);
    return null;
  }

  @SuppressWarnings("unchecked")
  public Enumeration elements(Object collection) {
    if (collection == null)
      return new CollectionHandlers.EmptyEnumerator();
    return ((Hashtable) collection).elements();
  }

  @SuppressWarnings("unchecked")
  public int size(Object collection) {
    if (collection == null)
      return 0;
    return ((Hashtable) collection).size();
  }

  @SuppressWarnings("unchecked")
  public Object clear(Object collection) {
    if (collection != null)
      ((Hashtable) collection).clear();
    return null;
  }

  public String toString() {
    return "Hashtable";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy