/* * Created on Jan 7, 2005 * * @author Mohan Radhakrishnan */ //package com.blueprint.ui.util; import java.lang.ref.ReferenceQueue; import java.lang.ref.SoftReference; import java.util.AbstractMap; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; /* * Undo/redo for each shape. This can be used to maintain * a list of changes to rollback. Since the calls to the * model tier are direct and the reverse calls to update the * UI are Commands, this list is for the latter. */ public class ShapeCommandMap extends AbstractMap { private final Map> internalMap = new HashMap>(); private final ReferenceQueue queue = new ReferenceQueue(); public V put( K key, V value ){ //remove stale entries SoftReference ref = new SoftReference( value, queue ); SoftReference s = internalMap.put( key, ref ); return ( s != null ? s.get() : null ); } /*public V get( K key ){ //remove stale entries SoftReference value = internalMap.get( key ); return ( value != null ? value.get() : null ); }*/ public Set> entrySet(){ Set> commands = new LinkedHashSet>(); for( final Entry> entry : internalMap.entrySet() ){ final V value = entry.getValue().get(); commands.add( new Entry(){ public K getKey(){ return entry.getKey(); } public V getValue(){ return value; } public V setValue( V v ){ entry.setValue( new SoftReference( v, queue ) ); return value; } }); } return commands; } } aspect TriggerBug { public void foo() { ShapeCommandMap map = new ShapeCommandMap(); map.put("hi","there"); } before() : execution(* getValue(..)) { System.out.println("a matching call"); } }