| Method from org.apache.bsf.debug.util.IntHashtable Detail: |
public synchronized void clear() {
elementCount = 0;
for (int i = elementData.length; --i >= 0;) {
elementData[i] = null;
}
}
Removes all key/value pairs from this IntHashtable, leaving the size zero
and the capacity unchanged. |
public synchronized Object clone() {
try {
IntHashtable hashtable = (IntHashtable) super.clone ();
hashtable.elementData = (IntHashMapEntry[])elementData.clone();
IntHashMapEntry entry;
for (int i=elementData.length; --i >= 0;) {
if ((entry = elementData[i]) != null)
hashtable.elementData[i] = (IntHashMapEntry)entry.clone();
}
return hashtable;
} catch (CloneNotSupportedException e) {
return null;
}
}
Answers a new IntHashtable with the same key/value pairs, capacity
and load factor. |
public synchronized boolean contains(Object value) {
for (int i=elementData.length; --i >= 0;) {
IntHashMapEntry entry = elementData[i];
while (entry != null) {
if (entry.value == value || entry.value.equals(value))
return true;
entry = entry.next;
}
}
return false;
}
Answers if this Hashtable contains the specified object as the value
of at least one of the key/value pairs. |
public synchronized boolean containsKey(int key) {
return getEntry(key) != null;
}
Answers if this Hashtable contains the specified object as a key
of one of the key/value pairs. |
public synchronized Enumeration elements() {
return new HashEnumerator (elementData);
}
Answers an Enumeration on the values of this Hashtable. The
results of the Enumeration may be affected if the contents
of this Hashtable are modified. |
public synchronized Object get(int key) {
int index = (key & 0x7FFFFFFF) % elementData.length;
IntHashMapEntry entry = elementData[index];
while (entry != null) {
if (entry.key == key) return entry.value;
entry = entry.next;
}
return null;
}
Answers the value associated with the specified key in
this Hashtable. |
public boolean isEmpty() {
return elementCount == 0;
}
Answers if this Hashtable has no key/value pairs, a size of zero. |
public synchronized Object put(int key,
Object value) {
if (value == null) throw new NullPointerException ();
int index = (key & 0x7FFFFFFF) % elementData.length;
IntHashMapEntry entry = elementData[index];
while (entry != null) {
if (entry.key == key) break;
entry = entry.next;
}
if (entry == null) {
if (++elementCount > threshold) {
rehash();
index = (key & 0x7FFFFFFF) % elementData.length;
}
entry = new IntHashMapEntry(key, value);
entry.next = elementData[index];
elementData[index] = entry;
return null;
}
Object result = entry.value;
entry.value = value;
return result;
}
Associate the specified value with the specified key in this Hashtable.
If the key already exists, the old value is replaced. The key and value
cannot be null. |
protected void rehash() {
int length = elementData.length< < 1;
if (length == 0) length = 1;
IntHashMapEntry[] newData = new IntHashMapEntry[length];
for (int i=elementData.length; --i >= 0;) {
IntHashMapEntry entry = elementData[i];
while (entry != null) {
int index = (entry.key & 0x7FFFFFFF) % length;
IntHashMapEntry next = entry.next;
entry.next = newData[index];
newData[index] = entry;
entry = next;
}
}
elementData = newData;
computeMaxSize();
}
Increases the capacity of this Hashtable. This method is sent when
the size of this Hashtable exceeds the load factor. |
public synchronized Object remove(int key) {
IntHashMapEntry last = null;
int index = (key & 0x7FFFFFFF) % elementData.length;
IntHashMapEntry entry = elementData[index];
while (entry != null) {
if (entry.key == key) break;
last = entry;
entry = entry.next;
}
if (entry != null) {
if (last == null) elementData[index] = entry.next;
else last.next = entry.next;
elementCount--;
return entry.value;
}
return null;
}
Remove the key/value pair with the specified key from this Hashtable. |
public int size() {
return elementCount;
}
Answers the number of key/value pairs in this Hashtable. |
public synchronized String toString() {
Object key;
int count = 0;
StringBuffer buffer = new StringBuffer ();
buffer.append ('{");
for (int i=elementData.length; --i >= 0;) {
IntHashMapEntry entry = elementData[i];
while (entry != null) {
buffer.append(entry.key);
buffer.append('=");
buffer.append(entry.value);
buffer.append(',");
entry = entry.next;
}
}
// Remove the last ','
if (elementCount > 0) buffer.setLength(buffer.length() - 1);
buffer.append ('}");
return buffer.toString ();
}
Answers the string representation of this Hashtable. |