KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > HashedMap


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.map;
17
18 import java.io.IOException JavaDoc;
19 import java.io.ObjectInputStream JavaDoc;
20 import java.io.ObjectOutputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * A <code>Map</code> implementation that is a general purpose alternative
26  * to <code>HashMap</code>.
27  * <p>
28  * This implementation improves on the JDK1.4 HashMap by adding the
29  * {@link org.apache.commons.collections.MapIterator MapIterator}
30  * functionality and many methods for subclassing.
31  * <p>
32  * @since Commons Collections 3.0
33  * @version $Revision: 1.15 $ $Date: 2004/02/18 01:13:19 $
34  *
35  * @author Stephen Colebourne
36  */

37 public class HashedMap
38         extends AbstractHashedMap implements Serializable JavaDoc, Cloneable JavaDoc {
39
40     /** Serialisation version */
41     private static final long serialVersionUID = -1788199231038721040L;
42     
43     /**
44      * Constructs a new empty map with default size and load factor.
45      */

46     public HashedMap() {
47         super(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD);
48     }
49
50     /**
51      * Constructs a new, empty map with the specified initial capacity.
52      *
53      * @param initialCapacity the initial capacity
54      * @throws IllegalArgumentException if the initial capacity is less than one
55      */

56     public HashedMap(int initialCapacity) {
57         super(initialCapacity);
58     }
59
60     /**
61      * Constructs a new, empty map with the specified initial capacity and
62      * load factor.
63      *
64      * @param initialCapacity the initial capacity
65      * @param loadFactor the load factor
66      * @throws IllegalArgumentException if the initial capacity is less than one
67      * @throws IllegalArgumentException if the load factor is less than zero
68      */

69     public HashedMap(int initialCapacity, float loadFactor) {
70         super(initialCapacity, loadFactor);
71     }
72
73     /**
74      * Constructor copying elements from another map.
75      *
76      * @param map the map to copy
77      * @throws NullPointerException if the map is null
78      */

79     public HashedMap(Map JavaDoc map) {
80         super(map);
81     }
82
83     //-----------------------------------------------------------------------
84
/**
85      * Clones the map without cloning the keys or values.
86      *
87      * @return a shallow clone
88      */

89     public Object JavaDoc clone() {
90         return super.clone();
91     }
92     
93     /**
94      * Write the map out using a custom routine.
95      */

96     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
97         out.defaultWriteObject();
98         doWriteObject(out);
99     }
100
101     /**
102      * Read the map in using a custom routine.
103      */

104     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
105         in.defaultReadObject();
106         doReadObject(in);
107     }
108     
109 }
110
Popular Tags