FileDocCategorySizeDatePackage
IdentityMap.javaAPI DocHibernate 3.2.55969Wed Feb 01 12:59:08 GMT 2006org.hibernate.util

IdentityMap

public final class IdentityMap extends Object implements Map
A Map where keys are compared by object identity, rather than equals().

Fields Summary
private final Map
map
private transient Map$Entry[]
entryArray
private transient boolean
dirty
Constructors Summary
private IdentityMap(Map underlyingMap)

		map = underlyingMap;
		dirty = true;
	
Methods Summary
public voidclear()

		dirty = true;
		entryArray = null;
		map.clear();
	
public static java.util.Map$Entry[]concurrentEntries(java.util.Map map)
Return the map entries (as instances of Map.Entry in a collection that is safe from concurrent modification). ie. we may safely add new instances to the underlying Map during iteration of the entries().

param
map
return
Collection

		return ( (IdentityMap) map ).entryArray();
	
public booleancontainsKey(java.lang.Object key)

		IdentityKey k = new IdentityKey(key);
		return map.containsKey(k);
	
public booleancontainsValue(java.lang.Object val)

		return map.containsValue(val);
	
public static java.util.Mapdeserialize(java.lang.Object o)
Workaround for a JDK 1.4.1 bug where IdentityHashMaps are not correctly deserialized.

param
o
return
Map

		return new IdentityMap( (Map) o );
	
public static java.util.Listentries(java.util.Map map)

		return ( (IdentityMap) map ).entryList();
	
public java.util.Map$Entry[]entryArray()

		if (dirty) {
			entryArray = new Map.Entry[ map.size() ];
			Iterator iter = map.entrySet().iterator();
			int i=0;
			while ( iter.hasNext() ) {
				Map.Entry me = (Map.Entry) iter.next();
				entryArray[i++] = new IdentityMapEntry( ( (IdentityKey) me.getKey() ).key, me.getValue() );
			}
			dirty = false;
		}
		return entryArray;
	
public java.util.ListentryList()

		ArrayList list = new ArrayList( map.size() );
		Iterator iter = map.entrySet().iterator();
		while ( iter.hasNext() ) {
			Map.Entry me = (Map.Entry) iter.next();
			list.add( new IdentityMapEntry( ( (IdentityKey) me.getKey() ).key, me.getValue() ) );
		}
		return list;
	
public java.util.SetentrySet()

		Set set = new HashSet( map.size() );
		Iterator iter = map.entrySet().iterator();
		while ( iter.hasNext() ) {
			Map.Entry me = (Map.Entry) iter.next();
			set.add( new IdentityMapEntry( ( (IdentityKey) me.getKey() ).key, me.getValue() ) );
		}
		return set;
	
public java.lang.Objectget(java.lang.Object key)

		IdentityKey k = new IdentityKey(key);
		return map.get(k);
	
public static java.util.Mapinstantiate(int size)
Return a new instance of this class, with an undefined iteration order

return
Map


	              	 
	     
		return new IdentityMap( new HashMap(size) );
	
public static java.util.MapinstantiateSequenced(int size)
Return a new instance of this class, with iteration order defined by the order that entries were added

		return new IdentityMap( new SequencedHashMap(size) );
	
public static java.util.Mapinvert(java.util.Map map)

		Map result = instantiate( map.size() );
		Iterator iter = map.entrySet().iterator();
		while ( iter.hasNext() ) {
			Map.Entry me = (Map.Entry) iter.next();
			result.put( me.getValue(), me.getKey() );
		}
		return result;
	
public booleanisEmpty()

		return map.isEmpty();
	
public static java.util.IteratorkeyIterator(java.util.Map map)

		return ( (IdentityMap) map ).keyIterator();
	
public java.util.IteratorkeyIterator()

		return new KeyIterator( map.keySet().iterator() );
	
public java.util.SetkeySet()

		// would need an IdentitySet for this!
		throw new UnsupportedOperationException();
	
public java.lang.Objectput(java.lang.Object key, java.lang.Object value)

		dirty = true;
		return map.put( new IdentityKey(key), value );
	
public voidputAll(java.util.Map otherMap)

		Iterator iter = otherMap.entrySet().iterator();
		while ( iter.hasNext() ) {
			Map.Entry me = (Map.Entry) iter.next();
			put( me.getKey(), me.getValue() );
		}
	
public java.lang.Objectremove(java.lang.Object key)

		dirty = true;
		IdentityKey k = new IdentityKey(key);
		return map.remove(k);
	
public static java.lang.Objectserialize(java.util.Map map)
Workaround for a JDK 1.4.1 bug where IdentityHashMaps are not correctly deserialized.

param
map
return
Object

		return ( (IdentityMap) map ).map;
	
public intsize()

		return map.size();
	
public java.lang.StringtoString()

		return map.toString();
	
public java.util.Collectionvalues()

		return map.values();