/** * Creates a {@link FastMap} with a capacity of <code>256</code> entries. */ public FastMap() { initialize( 256 ); }
/** * Creates a {@link FastMap} with the specified capacity. Unless the capacity is exceeded, operations on this map do * not allocate entries. For optimum performance, the capacity should be of the same order of magnitude or larger * than the expected map's size. * * @param capacity the number of buckets in the hash table; it also defines the number of pre-allocated entries. */ public FastMap( int capacity ) { initialize( capacity ); }
/** * Requires special handling during de-serialization process. * * @param stream the object input stream. * @throws IOException if an I/O error occurs. * @throws ClassNotFoundException if the class for the object de-serialized is not found. */ private void readObject( ObjectInputStream stream ) throws IOException, ClassNotFoundException { int capacity = stream.readInt(); initialize( capacity ); int size = stream.readInt(); for ( int i = 0; i < size; i++ ) { Object key = stream.readObject(); Object value = stream.readObject(); addEntry( key, value ); } }
/** * Returns a shallow copy of this {@link FastMap}. The keys and the values themselves are not cloned. * * @return a shallow copy of this map. */ public Object clone() { try { FastMap clone = (FastMap) super.clone(); clone.initialize( _capacity ); clone.putAll( this ); return clone; } catch ( CloneNotSupportedException e ) { // Should not happen, since we are Cloneable. throw new InternalError(); } }
/** * Creates a {@link FastMap}, copy of the specified <code>Map</code>. If the specified map is not an instance of * {@link FastMap}, the newly created map has a capacity set to the specified map's size. The copy has the same * order as the original, regardless of the original map's implementation: * * <pre> * TreeMap dictionary = ...; * FastMap dictionaryLookup = new FastMap(dictionary); * </pre> * * @param map the map whose mappings are to be placed in this map. */ public FastMap( Map map ) { int capacity = ( map instanceof FastMap ) ? ( (FastMap) map ).capacity() : map.size(); initialize( capacity ); putAll( map ); }
/** * Creates a {@link FastMap} with the specified capacity. Unless the * capacity is exceeded, operations on this map do not allocate entries. * For optimum performance, the capacity should be of the same order * of magnitude or larger than the expected map's size. * * @param capacity the number of buckets in the hash table; it also * defines the number of pre-allocated entries. */ public FastMap(int capacity) { initialize(capacity); }
/** * Creates a {@link FastMap} with a capacity of <code>256</code> entries. */ public FastMap() { initialize(256); }
/** * Returns a shallow copy of this {@link FastMap}. The keys and * the values themselves are not cloned. * * @return a shallow copy of this map. */ public Object clone() { try { FastMap clone = (FastMap) super.clone(); clone.initialize(_capacity); clone.putAll(this); return clone; } catch (CloneNotSupportedException e) { // Should not happen, since we are Cloneable. throw new InternalError(); } }
/** * Requires special handling during de-serialization process. * * @param stream the object input stream. * @throws IOException if an I/O error occurs. * @throws ClassNotFoundException if the class for the object de-serialized * is not found. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { int capacity = stream.readInt(); initialize(capacity); int size = stream.readInt(); for (int i=0; i < size; i++) { Object key = stream.readObject(); Object value = stream.readObject(); addEntry(key, value); } }
/** * Creates a {@link FastMap}, copy of the specified <code>Map</code>. * If the specified map is not an instance of {@link FastMap}, the * newly created map has a capacity set to the specified map's size. * The copy has the same order as the original, regardless of the original * map's implementation:<pre> * TreeMap dictionary = ...; * FastMap dictionaryLookup = new FastMap(dictionary); * </pre> * * @param map the map whose mappings are to be placed in this map. */ public FastMap(Map map) { int capacity = (map instanceof FastMap) ? ((FastMap)map).capacity() : map.size(); initialize(capacity); putAll(map); }