Top Description Fields Constructors Methods
org.apache.commons.collections4.map

public Class HashedMap<K, V>

extends AbstractHashedMap<K, V>
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.Map

A Map implementation that is a general purpose alternative to HashMap.

This implementation improves on the JDK1.4 HashMap by adding the MapIterator functionality and many methods for subclassing.

Note that HashedMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using java.util.Collections#synchronizedMap(Map). This class may throw exceptions when accessed by concurrent threads without synchronization.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serialisation version

Inherited from org.apache.commons.collections4.map.AbstractHashedMap:
dataDEFAULT_CAPACITYDEFAULT_LOAD_FACTORDEFAULT_THRESHOLDentrySetGETKEY_INVALIDGETVALUE_INVALIDkeySetloadFactorMAXIMUM_CAPACITYmodCountNO_NEXT_ENTRYNO_PREVIOUS_ENTRYNULLREMOVE_INVALIDSETVALUE_INVALIDsizethresholdvalues

Constructor Summary

AccessConstructor and Description
public
HashedMap()

Constructs a new empty map with default size and load factor.

public
HashedMap(final int
the initial capacity
initialCapacity
)

Constructs a new, empty map with the specified initial capacity.

public
HashedMap(final int
the initial capacity
initialCapacity
,
final float
the load factor
loadFactor
)

Constructs a new, empty map with the specified initial capacity and load factor.

public
HashedMap(final Map<? extends K, ? extends V>
the map to copy
map
)

Constructor copying elements from another map.

Method Summary

Modifier and TypeMethod and Description
public HashedMap<K, V>

Returns:

a shallow clone
clone
()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.clone.

Clones the map without cloning the keys or values.
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the map in using a custom routine.

private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the map out using a custom routine.

Inherited from org.apache.commons.collections4.map.AbstractHashedMap:
addEntryaddMappingcalculateNewCapacitycalculateThresholdcheckCapacityclearcontainsKeycontainsValueconvertKeycreateEntrycreateEntrySetIteratorcreateKeySetIteratorcreateValuesIteratordestroyEntrydoReadObjectdoWriteObjectensureCapacityentryHashCodeentryKeyentryNextentrySetentryValueequalsgetgetEntryhashhashCodehashIndexinitisEmptyisEqualKeyisEqualValuekeySetmapIteratorputputAllremoveremoveEntryremoveMappingreuseEntrysizetoStringupdateEntryvalues

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serialisation version

Constructor Detail

HashedMapback to summary
public HashedMap()

Constructs a new empty map with default size and load factor.

HashedMapback to summary
public HashedMap(final int initialCapacity)

Constructs a new, empty map with the specified initial capacity.

Parameters
initialCapacity:int

the initial capacity

Exceptions
IllegalArgumentException:
if the initial capacity is negative
HashedMapback to summary
public HashedMap(final int initialCapacity, final float loadFactor)

Constructs a new, empty map with the specified initial capacity and load factor.

Parameters
initialCapacity:int

the initial capacity

loadFactor:float

the load factor

Exceptions
IllegalArgumentException:
  • if the initial capacity is negative
  • if the load factor is less than zero
HashedMapback to summary
public HashedMap(final Map<? extends K, ? extends V> map)

Constructor copying elements from another map.

Parameters
map:Map<? extends K, ? extends V>

the map to copy

Exceptions
NullPointerException:
if the map is null

Method Detail

cloneback to summary
public HashedMap<K, V> clone()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.clone.

Clones the map without cloning the keys or values.

Returns:HashedMap<K, V>

a shallow clone

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the map in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the map out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream