1 17 18 package org.objectweb.jac.util; 19 20 import java.util.HashMap ; 21 22 23 28 public class SharedMap implements Cloneable { 29 HashMap map; 30 boolean shared=false; 31 public SharedMap() { 32 map = new HashMap (); 33 } 34 public SharedMap(HashMap map) { 35 this.map = map; 36 } 37 SharedMap(HashMap map, boolean shared) { 38 this.map = map; 39 this.shared = shared; 40 } 41 public Object clone() { 42 shared = true; 43 return new SharedMap(map,true); 44 } 45 public Object get(Object key) { 46 return map.get(key); 47 } 48 public synchronized void put(Object key, Object value) { 49 if (shared) { 50 map = (HashMap )map.clone(); 52 shared = false; 53 } 54 map.put(key,value); 55 } 56 } 57 | Popular Tags |