Method from freemarker.ext.util.IdentityHashMap Detail: |
int capacity() {
return table.length;
}
|
public void clear() {
Entry tab[] = table;
modCount++;
for (int index = tab.length; --index >= 0;)
tab[index] = null;
count = 0;
}
Removes all mappings from this map. |
public Object clone() {
try
{
IdentityHashMap t = (IdentityHashMap) super.clone();
t.table = new Entry[table.length];
for (int i = table.length; i-- > 0;)
{
t.table[i] =
(table[i] != null) ? (Entry) table[i].clone() : null;
}
t.keySet = null;
t.entrySet = null;
t.values = null;
t.modCount = 0;
return t;
}
catch (CloneNotSupportedException e)
{
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
Returns a shallow copy of this IdentityHashMap instance: the keys and
values themselves are not cloned. |
public boolean containsKey(Object key) {
Entry tab[] = table;
if (key != null)
{
int hash = System.identityHashCode(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index]; e != null; e = e.next)
if (e.hash == hash && key == e.key)
return true;
}
else
{
for (Entry e = tab[0]; e != null; e = e.next)
if (e.key == null)
return true;
}
return false;
}
Returns true if this map contains a mapping for the specified
key. |
public boolean containsValue(Object value) {
Entry tab[] = table;
if (value == null)
{
for (int i = tab.length; i-- > 0;)
for (Entry e = tab[i]; e != null; e = e.next)
if (e.value == null)
return true;
}
else
{
for (int i = tab.length; i-- > 0;)
for (Entry e = tab[i]; e != null; e = e.next)
if (value.equals(e.value))
return true;
}
return false;
}
Returns true if this map maps one or more keys to the
specified value. |
public Set entrySet() {
if (entrySet == null)
{
entrySet = new AbstractSet()
{
public Iterator iterator()
{
return getHashIterator(ENTRIES);
}
public boolean contains(Object o)
{
if (!(o instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry) o;
Object key = entry.getKey();
Entry tab[] = table;
int hash = (key == null ? 0 : System.identityHashCode(key));
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index]; e != null; e = e.next)
if (e.hash == hash && e.equals(entry))
return true;
return false;
}
public boolean remove(Object o)
{
if (!(o instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry) o;
Object key = entry.getKey();
Entry tab[] = table;
int hash = (key == null ? 0 : System.identityHashCode(key));
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index], prev = null;
e != null;
prev = e, e = e.next)
{
if (e.hash == hash && e.equals(entry))
{
modCount++;
if (prev != null)
prev.next = e.next;
else
tab[index] = e.next;
count--;
e.value = null;
return true;
}
}
return false;
}
public int size()
{
return count;
}
public void clear()
{
IdentityHashMap.this.clear();
}
};
}
return entrySet;
}
Returns a collection view of the mappings contained in this map. Each
element in the returned collection is a Map.Entry. The
collection is backed by the map, so changes to the map are reflected in
the collection, and vice versa. The collection supports element
removal, which removes the corresponding mapping from the map, via the
Iterator.remove, Collection.remove,
removeAll, retainAll, and clear operations.
It does not support the add or addAll operations. |
public Object get(Object key) {
Entry tab[] = table;
if (key != null)
{
int hash = System.identityHashCode(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index]; e != null; e = e.next)
if ((e.hash == hash) && key == e.key)
return e.value;
}
else
{
for (Entry e = tab[0]; e != null; e = e.next)
if (e.key == null)
return e.value;
}
return null;
}
Returns the value to which this map maps the specified key. Returns
null if the map contains no mapping for this key. A return
value of null does not necessarily indicate that the
map contains no mapping for the key; it's also possible that the map
explicitly maps the key to null. The containsKey
operation may be used to distinguish these two cases. |
public boolean isEmpty() {
return count == 0;
}
Returns true if this map contains no key-value mappings. |
public Set keySet() {
if (keySet == null)
{
keySet = new AbstractSet()
{
public Iterator iterator()
{
return getHashIterator(KEYS);
}
public int size()
{
return count;
}
public boolean contains(Object o)
{
return containsKey(o);
}
public boolean remove(Object o)
{
int oldSize = count;
IdentityHashMap.this.remove(o);
return count != oldSize;
}
public void clear()
{
IdentityHashMap.this.clear();
}
};
}
return keySet;
}
Returns a set view of the keys contained in this map. The set is
backed by the map, so changes to the map are reflected in the set, and
vice versa. The set supports element removal, which removes the
corresponding mapping from this map, via the Iterator.remove,
Set.remove, removeAll, retainAll, and
clear operations. It does not support the add or
addAll operations. |
float loadFactor() {
return loadFactor;
}
|
public Object put(Object key,
Object value) {
// Makes sure the key is not already in the IdentityHashMap.
Entry tab[] = table;
int hash = 0;
int index = 0;
if (key != null)
{
hash = System.identityHashCode(key);
index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index]; e != null; e = e.next)
{
if ((e.hash == hash) && key == e.key)
{
Object old = e.value;
e.value = value;
return old;
}
}
}
else
{
for (Entry e = tab[0]; e != null; e = e.next)
{
if (e.key == null)
{
Object old = e.value;
e.value = value;
return old;
}
}
}
modCount++;
if (count >= threshold)
{
// Rehash the table if the threshold is exceeded
rehash();
tab = table;
index = (hash & 0x7FFFFFFF) % tab.length;
}
// Creates the new entry.
Entry e = new Entry(hash, key, value, tab[index]);
tab[index] = e;
count++;
return null;
}
Associates the specified value with the specified key in this map.
If the map previously contained a mapping for this key, the old
value is replaced. |
public void putAll(Map t) {
Iterator i = t.entrySet().iterator();
while (i.hasNext())
{
Map.Entry e = (Map.Entry) i.next();
put(e.getKey(), e.getValue());
}
}
Copies all of the mappings from the specified map to this one.
These mappings replace any mappings that this map had for any of the
keys currently in the specified Map. |
public Object remove(Object key) {
Entry tab[] = table;
if (key != null)
{
int hash = System.identityHashCode(key);
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index], prev = null;
e != null;
prev = e, e = e.next)
{
if ((e.hash == hash) && key == e.key)
{
modCount++;
if (prev != null)
prev.next = e.next;
else
tab[index] = e.next;
count--;
Object oldValue = e.value;
e.value = null;
return oldValue;
}
}
}
else
{
for (Entry e = tab[0], prev = null;
e != null;
prev = e, e = e.next)
{
if (e.key == null)
{
modCount++;
if (prev != null)
prev.next = e.next;
else
tab[0] = e.next;
count--;
Object oldValue = e.value;
e.value = null;
return oldValue;
}
}
}
return null;
}
Removes the mapping for this key from this map if present. |
public int size() {
return count;
}
Returns the number of key-value mappings in this map. |
public Collection values() {
if (values == null)
{
values = new AbstractCollection()
{
public Iterator iterator()
{
return getHashIterator(VALUES);
}
public int size()
{
return count;
}
public boolean contains(Object o)
{
return containsValue(o);
}
public void clear()
{
IdentityHashMap.this.clear();
}
};
}
return values;
}
Returns a collection view of the values contained in this map. The
collection is backed by the map, so changes to the map are reflected in
the collection, and vice versa. The collection supports element
removal, which removes the corresponding mapping from this map, via the
Iterator.remove, Collection.remove,
removeAll, retainAll, and clear operations.
It does not support the add or addAll operations. |