1 package prefuse.activity; 2 3 import java.util.HashMap ; 4 5 20 public class ActivityMap { 21 22 private HashMap m_map; 23 private ActivityMap m_parent; 24 25 28 public ActivityMap() { 29 this(null); 30 } 31 32 37 public ActivityMap(ActivityMap parent) { 38 m_map = new HashMap (); 39 m_parent = parent; 40 } 41 42 45 public void clear() { 46 m_map.clear(); 47 } 48 49 54 public int size() { 55 return m_map.size(); 56 } 57 58 66 public Activity get(String key) { 67 Activity a = (Activity)m_map.get(key); 68 return (a==null && m_parent!=null ? m_parent.get(key) : a); 69 } 70 71 78 public Activity runAt(String key, long time) { 79 Activity a = get(key); 80 if ( a != null ) 81 ActivityManager.scheduleAt(a,time); 82 return a; 83 } 84 85 91 public Activity run(String key) { 92 Activity a = get(key); 93 if ( a != null ) 94 ActivityManager.scheduleNow(a); 95 return a; 96 } 97 98 109 public Activity runAfter(String beforeKey, String afterKey) { 110 Activity before = get(beforeKey); 111 Activity after = get(afterKey); 112 if ( before != null && after != null ) 113 ActivityManager.scheduleAfter(before, after); 114 return after; 115 } 116 117 128 public Activity alwaysRunAfter(String beforeKey, String afterKey) { 129 Activity before = get(beforeKey); 130 Activity after = get(afterKey); 131 if ( before != null && after != null ) 132 ActivityManager.alwaysScheduleAfter(before, after); 133 return after; 134 } 135 136 142 public Activity cancel(String key) { 143 Activity a = get(key); 144 if ( a != null ) 145 a.cancel(); 146 return a; 147 } 148 149 155 public Activity put(String key, Activity activity) { 156 return (Activity)m_map.put(key, activity); 157 } 158 159 164 public void remove(Object key) { 165 m_map.remove(key); 166 } 167 168 173 public Object [] keys() { 174 return m_map.keySet().toArray(); 175 } 176 177 182 public Object [] allKeys() { 183 Object [] a1 = m_map.keySet().toArray(); 184 if ( m_parent != null ) { 185 Object [] a2 = m_parent.allKeys(); 186 if ( a2 != null && a2.length > 0 ) { 187 Object [] o = new Object [a1.length+a2.length]; 188 System.arraycopy(a1,0,o,0,a1.length); 189 System.arraycopy(a2,0,o,a1.length,a2.length); 190 return o; 191 } 192 } 193 return a1; 194 } 195 196 201 public void setParent(ActivityMap parent) { 202 m_parent = parent; 203 } 204 205 210 public ActivityMap getParent() { 211 return m_parent; 212 } 213 214 } | Popular Tags |