Package com.sun.msv.scanner.dtd
Class SimpleHashtable
- java.lang.Object
-
- com.sun.msv.scanner.dtd.SimpleHashtable
-
- All Implemented Interfaces:
java.util.Enumeration
final class SimpleHashtable extends java.lang.Object implements java.util.Enumeration
This class implements a special purpose hashtable. It works like a normaljava.util.Hashtable
except that:- Keys to "get" are strings which are known to be interned, so that "==" is used instead of "String.equals". (Interning could be document-relative instead of global.)
- It's not synchronized, since it's to be used only by one thread at a time.
- The keys () enumerator allocates no memory, with live updates to the data disallowed.
- It's got fewer bells and whistles: fixed threshold and load factor, no JDK 1.2 collection support, only keys can be enumerated, things can't be removed, simpler inheritance; more.
The overall result is that it's less expensive to use these in performance-critical locations, in terms both of CPU and memory, than
java.util.Hashtable
instances. In this package it makes a significant difference when normalizing attributes, which is done for each start-element construct.- Version:
- $Revision: 1793 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SimpleHashtable.Entry
Hashtable collision list.
-
Field Summary
Fields Modifier and Type Field Description private int
count
private SimpleHashtable.Entry
current
private int
currentBucket
private static float
loadFactor
private SimpleHashtable.Entry[]
table
private int
threshold
-
Constructor Summary
Constructors Constructor Description SimpleHashtable()
Constructs a new, empty hashtable with a default capacity.SimpleHashtable(int initialCapacity)
Constructs a new, empty hashtable with the specified initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
java.lang.Object
get(java.lang.String key)
Returns the value to which the specified key is mapped in this hashtable.java.lang.Object
getNonInterned(java.lang.String key)
Returns the value to which the specified key is mapped in this hashtable ...boolean
hasMoreElements()
Used to view this as an enumeration; returns true if there are more keys to be enumerated.java.util.Enumeration
keys()
Returns an enumeration of the keys in this hashtable.java.lang.Object
nextElement()
Used to view this as an enumeration; returns the next key in the enumeration.java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Maps the specifiedkey
to the specifiedvalue
in this hashtable.private void
rehash()
Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.int
size()
Returns the number of keys in this hashtable.
-
-
-
Field Detail
-
table
private SimpleHashtable.Entry[] table
-
current
private SimpleHashtable.Entry current
-
currentBucket
private int currentBucket
-
count
private int count
-
threshold
private int threshold
-
loadFactor
private static final float loadFactor
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SimpleHashtable
public SimpleHashtable(int initialCapacity)
Constructs a new, empty hashtable with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the hashtable.
-
SimpleHashtable
public SimpleHashtable()
Constructs a new, empty hashtable with a default capacity.
-
-
Method Detail
-
clear
public void clear()
-
size
public int size()
Returns the number of keys in this hashtable.- Returns:
- the number of keys in this hashtable.
-
keys
public java.util.Enumeration keys()
Returns an enumeration of the keys in this hashtable.- Returns:
- an enumeration of the keys in this hashtable.
- See Also:
Enumeration
-
hasMoreElements
public boolean hasMoreElements()
Used to view this as an enumeration; returns true if there are more keys to be enumerated.- Specified by:
hasMoreElements
in interfacejava.util.Enumeration
-
nextElement
public java.lang.Object nextElement()
Used to view this as an enumeration; returns the next key in the enumeration.- Specified by:
nextElement
in interfacejava.util.Enumeration
-
get
public java.lang.Object get(java.lang.String key)
Returns the value to which the specified key is mapped in this hashtable.
-
getNonInterned
public java.lang.Object getNonInterned(java.lang.String key)
Returns the value to which the specified key is mapped in this hashtable ... the key isn't necessarily interned, though.
-
rehash
private void rehash()
Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Maps the specifiedkey
to the specifiedvalue
in this hashtable. Neither the key nor the value can benull
.The value can be retrieved by calling the
get
method with a key that is equal to the original key.
-
-