org.apache.commons.collections.map

Class IdentityMap

Implemented Interfaces:
Cloneable, Map, Serializable, IterableMap

public class IdentityMap
extends AbstractHashedMap
implements Serializable, Cloneable

A Map implementation that matches keys and values based on == not equals().

This map will violate the detail of various Map and map view contracts. As a general rule, don't compare this map to other maps.

Version:
$Revision: 1.5 $ $Date: 2004/02/18 01:13:19 $
Authors:
java util HashMap
Stephen Colebourne
Since:
Commons Collections 3.0

Nested Class Summary

protected static class
IdentityMap.IdentityEntry
HashEntry

Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractHashedMap

AbstractHashedMap.EntrySet, AbstractHashedMap.EntrySetIterator, AbstractHashedMap.HashEntry, AbstractHashedMap.HashIterator, AbstractHashedMap.HashMapIterator, AbstractHashedMap.KeySet, AbstractHashedMap.KeySetIterator, AbstractHashedMap.Values, AbstractHashedMap.ValuesIterator

Field Summary

Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap

DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, GETKEY_INVALID, GETVALUE_INVALID, MAXIMUM_CAPACITY, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, data, entrySet, keySet, loadFactor, modCount, size, threshold, values

Constructor Summary

IdentityMap()
Constructs a new empty map with default size and load factor.
IdentityMap(Map map)
Constructor copying elements from another map.
IdentityMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity.
IdentityMap(int initialCapacity, float loadFactor)
Constructs a new, empty map with the specified initial capacity and load factor.

Method Summary

Object
clone()
Clones the map without cloning the keys or values.
protected AbstractHashedMap.HashEntry
createEntry(AbstractHashedMap.HashEntry next, int hashCode, Object key, Object value)
Creates an entry to store the data.
protected int
hash(Object key)
Gets the hash code for the key specified.
protected boolean
isEqualKey(Object key1, Object key2)
Compares two keys for equals.
protected boolean
isEqualValue(Object value1, Object value2)
Compares two values for equals.

Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap

addEntry, addMapping, calculateNewCapacity, calculateThreshold, checkCapacity, clear, clone, containsKey, containsValue, convertKey, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, destroyEntry, doReadObject, doWriteObject, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, get, getEntry, hash, hashCode, hashIndex, init, isEmpty, isEqualKey, isEqualValue, keySet, mapIterator, put, putAll, remove, removeEntry, removeMapping, reuseEntry, size, toString, updateEntry, values

Constructor Details

IdentityMap

public IdentityMap()
Constructs a new empty map with default size and load factor.

IdentityMap

public IdentityMap(Map map)
Constructor copying elements from another map.
Parameters:
map - the map to copy

IdentityMap

public IdentityMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity.
Parameters:
initialCapacity - the initial capacity

IdentityMap

public IdentityMap(int initialCapacity,
                   float loadFactor)
Constructs a new, empty map with the specified initial capacity and load factor.
Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor

Method Details

clone

public Object clone()
Clones the map without cloning the keys or values.
Overrides:
clone in interface AbstractHashedMap
Returns:
a shallow clone

createEntry

protected AbstractHashedMap.HashEntry createEntry(AbstractHashedMap.HashEntry next,
                                                  int hashCode,
                                                  Object key,
                                                  Object value)
Creates an entry to store the data. This implementation creates an IdentityEntry instance.
Overrides:
createEntry in interface AbstractHashedMap
Parameters:
next - the next entry in sequence
hashCode - the hash code to use
key - the key to store
value - the value to store
Returns:
the newly created entry

hash

protected int hash(Object key)
Gets the hash code for the key specified. This implementation uses the identity hash code.
Overrides:
hash in interface AbstractHashedMap
Parameters:
key - the key to get a hash code for
Returns:
the hash code

isEqualKey

protected boolean isEqualKey(Object key1,
                             Object key2)
Compares two keys for equals. This implementation uses ==.
Overrides:
isEqualKey in interface AbstractHashedMap
Parameters:
key1 - the first key to compare
key2 - the second key to compare
Returns:
true if equal by identity

isEqualValue

protected boolean isEqualValue(Object value1,
                               Object value2)
Compares two values for equals. This implementation uses ==.
Overrides:
isEqualValue in interface AbstractHashedMap
Parameters:
value1 - the first value to compare
value2 - the second value to compare
Returns:
true if equal by identity

Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.