/***********************************************************************

GECCO, a platform for command and control gaming

Copyright (C) 2001 Henrik Bäärnhielm, Andreas Enblom, Niklas
Hallenfur, Karl Hasselström, Henrik Hägerström, Oskar Linde, Jing Fu
Zi and Jon Åslund

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

***********************************************************************/

package gecco.server.startup;

import java.util.*;

/**
 *  Description of the Class
 *
 * @author     Karl Hasselström
 * @created    June 27, 2001
 */
public class DeepCloneHashMap extends HashMap implements DeepCloneable {
    /**
     *  Constructor for the DeepCloneHashMap object
     */
    DeepCloneHashMap() {
        super();
    }


    /**
     *  Constructor for the DeepCloneHashMap object
     *
     * @param  initialCapacity  Description of Parameter
     */
    DeepCloneHashMap(int initialCapacity) {
        super(initialCapacity);
    }


    /**
     *  Constructor for the DeepCloneHashMap object
     *
     * @param  initialCapacity  Description of Parameter
     * @param  loadFactor       Description of Parameter
     */
    DeepCloneHashMap(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
    }


    /**
     *  Constructor for the DeepCloneHashMap object
     *
     * @param  t  Description of Parameter
     */
    DeepCloneHashMap(Map t) {
        super(t);
    }


    // Make a deep clone
    /**
     *  Description of the Method
     *
     * @return    Description of the Returned Value
     */
    public DeepCloneable deepClone() {
        DeepCloneHashMap copy = new DeepCloneHashMap(size());
        Iterator iter = entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry me = (Map.Entry) iter.next();
            Object key;
            Object value;
            if (me.getKey() instanceof DeepCloneable) {
                key = ((DeepCloneable) me.getKey()).deepClone();
            } else {
                key = me.getKey();
            }
            if (me.getValue() instanceof DeepCloneable) {
                value = ((DeepCloneable) me.getValue()).deepClone();
            } else {
                value = me.getValue();
            }
            copy.put(key, value);
        }
        return copy;
    }
}
