/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// This could be replaced by Collections class unless we want
// to be able to run on JDK 1.1
/**
* This class implements a special purpose hashtable. It works like a
* normal <code>java.util.Hashtable</code> except that: <OL>
* <p/>
* <LI> 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.)
* <p/>
* <LI> It's not synchronized, since it's to be used only by
* one thread at a time.
* <p/>
* <LI> The keys () enumerator allocates no memory, with live
* updates to the data disallowed.
* <p/>
* <LI> 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.
* <p/>
* </OL>
* <p/>
* <P> The overall result is that it's less expensive to use these in
* performance-critical locations, in terms both of CPU and memory,
* than <code>java.util.Hashtable</code> instances. In this package
* it makes a significant difference when normalizing attributes,
* which is done for each start-element construct.
*
* @version $Revision: 1.2 $
*/
// entries ...
// currently enumerated key
private int count;
private int threshold;
/**
* Constructs a new, empty hashtable with the specified initial
* capacity.
*
* @param initialCapacity the initial capacity of the hashtable.
*/
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: " +
if (initialCapacity == 0)
initialCapacity = 1;
}
/**
* Constructs a new, empty hashtable with a default capacity.
*/
public SimpleHashtable() {
this(11);
}
/**
*/
public void clear() {
count = 0;
currentBucket = 0;
}
/**
* Returns the number of keys in this hashtable.
*
* @return the number of keys in this hashtable.
*/
public int size() {
return count;
}
/**
* Returns an enumeration of the keys in this hashtable.
*
* @return an enumeration of the keys in this hashtable.
* @see Enumeration
*/
currentBucket = 0;
return this;
}
/**
* Used to view this as an enumeration; returns true if there
* are more keys to be enumerated.
*/
public boolean hasMoreElements() {
return true;
return true;
}
return false;
}
/**
* Used to view this as an enumeration; returns the next key
* in the enumeration.
*/
throw new IllegalStateException();
return retval;
}
/**
* Returns the value to which the specified key is mapped in this hashtable.
*/
return e.value;
}
return null;
}
/**
* Returns the value to which the specified key is mapped in this
* hashtable ... the key isn't necessarily interned, though.
*/
return e.value;
}
return null;
}
/**
* 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.
*/
private void rehash() {
/*
System.out.println("rehash old=" + oldCapacity
+ ", new=" + newCapacity
+ ", thresh=" + threshold
+ ", count=" + count);
*/
for (int i = oldCapacity; i-- > 0;) {
}
}
}
/**
* Maps the specified <code>key</code> to the specified
* <code>value</code> in this hashtable. Neither the key nor the
* value can be <code>null</code>.
* <p/>
* <P>The value can be retrieved by calling the <code>get</code> method
* with a key that is equal to the original key.
*/
// Make sure the value is not null
throw new NullPointerException();
}
// Makes sure the key is not already in the hashtable.
// if ((e.hash == hash) && e.key.equals(key)) {
return old;
}
}
// Rehash the table if the threshold is exceeded
rehash();
}
// Creates the new entry.
count++;
return null;
}
/**
* Hashtable collision list.
*/
private static class Entry {
int hash;
}
}
}