package nl.tudelft.simulation.immutablecollections;
import java.util.HashMap;
import java.util.Map;
/**
* An immutable wrapper for a HashMap.
*
* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
* reserved.
* BSD-style license. See DSOL License.
*
* $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck
* $, initial version May 7, 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param the key type of content of this Map
* @param the value type of content of this Map
*/
public class ImmutableHashMap extends ImmutableAbstractMap
{
/** */
private static final long serialVersionUID = 20160507L;
/**
* @param map the map to use for the immutable map.
*/
public ImmutableHashMap(final Map map)
{
super(new HashMap(map), Immutable.COPY);
}
/**
* @param map the map to use for the immutable map.
* @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original
* collection
*/
public ImmutableHashMap(final Map map, final Immutable copyOrWrap)
{
super(copyOrWrap == Immutable.COPY ? new HashMap(map) : map, copyOrWrap);
}
/**
* @param immutableMap the map to use for the immutable map.
*/
public ImmutableHashMap(final ImmutableAbstractMap immutableMap)
{
super(new HashMap(immutableMap.getMap()), Immutable.COPY);
}
/**
* @param immutableMap the map to use for the immutable map.
* @param copyOrWrap COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original
* collection
*/
public ImmutableHashMap(final ImmutableAbstractMap immutableMap, final Immutable copyOrWrap)
{
super(copyOrWrap == Immutable.COPY ? new HashMap(immutableMap.getMap()) : immutableMap.getMap(),
copyOrWrap);
}
/** {@inheritDoc} */
@Override
protected final Map getMap()
{
return super.getMap();
}
/** {@inheritDoc} */
@Override
public final Map toMap()
{
return new HashMap(getMap());
}
/** {@inheritDoc} */
@Override
public final ImmutableSet keySet()
{
return new ImmutableHashSet(getMap().keySet());
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public String toString()
{
Map map = getMap();
if (null == map)
{
return "ImmutableHashMap []";
}
return "ImmutableHashMap [" + map.toString() + "]";
}
}