001: /*
002: * Copyright 2003-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.map;
017:
018: import java.io.IOException;
019: import java.io.ObjectInputStream;
020: import java.io.ObjectOutputStream;
021: import java.io.Serializable;
022: import java.util.Map;
023:
024: /**
025: * A <code>Map</code> implementation that is a general purpose alternative
026: * to <code>HashMap</code>.
027: * <p>
028: * This implementation improves on the JDK1.4 HashMap by adding the
029: * {@link org.apache.commons.collections.MapIterator MapIterator}
030: * functionality and many methods for subclassing.
031: * <p>
032: * <strong>Note that HashedMap is not synchronized and is not thread-safe.</strong>
033: * If you wish to use this map from multiple threads concurrently, you must use
034: * appropriate synchronization. The simplest approach is to wrap this map
035: * using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw
036: * exceptions when accessed by concurrent threads without synchronization.
037: *
038: * @since Commons Collections 3.0
039: * @version $Revision: 348007 $ $Date: 2005-11-21 22:52:57 +0000 (Mon, 21 Nov 2005) $
040: *
041: * @author Stephen Colebourne
042: */
043: public class HashedMap extends AbstractHashedMap implements
044: Serializable, Cloneable {
045:
046: /** Serialisation version */
047: private static final long serialVersionUID = -1788199231038721040L;
048:
049: /**
050: * Constructs a new empty map with default size and load factor.
051: */
052: public HashedMap() {
053: super (DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD);
054: }
055:
056: /**
057: * Constructs a new, empty map with the specified initial capacity.
058: *
059: * @param initialCapacity the initial capacity
060: * @throws IllegalArgumentException if the initial capacity is less than one
061: */
062: public HashedMap(int initialCapacity) {
063: super (initialCapacity);
064: }
065:
066: /**
067: * Constructs a new, empty map with the specified initial capacity and
068: * load factor.
069: *
070: * @param initialCapacity the initial capacity
071: * @param loadFactor the load factor
072: * @throws IllegalArgumentException if the initial capacity is less than one
073: * @throws IllegalArgumentException if the load factor is less than zero
074: */
075: public HashedMap(int initialCapacity, float loadFactor) {
076: super (initialCapacity, loadFactor);
077: }
078:
079: /**
080: * Constructor copying elements from another map.
081: *
082: * @param map the map to copy
083: * @throws NullPointerException if the map is null
084: */
085: public HashedMap(Map map) {
086: super (map);
087: }
088:
089: //-----------------------------------------------------------------------
090: /**
091: * Clones the map without cloning the keys or values.
092: *
093: * @return a shallow clone
094: */
095: public Object clone() {
096: return super .clone();
097: }
098:
099: /**
100: * Write the map out using a custom routine.
101: */
102: private void writeObject(ObjectOutputStream out) throws IOException {
103: out.defaultWriteObject();
104: doWriteObject(out);
105: }
106:
107: /**
108: * Read the map in using a custom routine.
109: */
110: private void readObject(ObjectInputStream in) throws IOException,
111: ClassNotFoundException {
112: in.defaultReadObject();
113: doReadObject(in);
114: }
115:
116: }
|