KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > util > ObjectIdDictionary


1 package com.thoughtworks.xstream.core.util;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 /**
7  * Store IDs against given object references.
8  * <p/>
9  * Behaves the same way as java.util.IdentityHashMap, but in JDK1.3 as well.
10  */

11 public class ObjectIdDictionary {
12
13     private Map JavaDoc map = new HashMap JavaDoc();
14
15     public void associateId(Object JavaDoc obj, String JavaDoc id) {
16         map.put(id(obj), id);
17     }
18
19     public String JavaDoc lookupId(Object JavaDoc obj) {
20         return (String JavaDoc) map.get(id(obj));
21     }
22
23     private Object JavaDoc id(Object JavaDoc obj) {
24         return new Integer JavaDoc(System.identityHashCode(obj));
25     }
26
27 }
28
Popular Tags