1 package org.sourceforge.jemm.client.events;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.sourceforge.jemm.client.Descriptor;
7
8
9
10
11
12
13
14
15
16 public class EntityContext extends SimpleContext{
17 Object obj;
18 Map<Descriptor, MethodContext> methods;
19
20 public EntityContext(Object obj) {
21 this.obj = obj;
22 methods = new HashMap<Descriptor,MethodContext>();
23 }
24
25
26
27
28
29
30
31 public synchronized void add(Descriptor method, Thread thread) {
32 if(!methods.containsKey(method)) {
33 methods.put(method, new MethodContext(method));
34 }
35
36 MethodContext mContext = methods.get(method);
37 mContext.add(thread);
38 add(thread);
39 }
40
41 public void add(Descriptor method) {
42 add(method,Thread.currentThread());
43 }
44
45 public synchronized boolean has(Descriptor method, Thread thread) {
46 if(methods.containsKey(method)) {
47 MethodContext mContext = methods.get(method);
48 return mContext.has(thread);
49 }
50 return false;
51 }
52
53
54
55
56
57
58
59
60 public boolean has(Descriptor method) {
61 return has(method,Thread.currentThread());
62 }
63
64 public synchronized void remove(Descriptor method, Thread thread) {
65 if(methods.containsKey(method)) {
66 MethodContext mContext = methods.get(method);
67 mContext.remove(thread);
68
69 if(!mContext.hasAny())
70 methods.remove(method);
71
72 }
73 remove(thread);
74 }
75
76 public void remove(Descriptor method) {
77 remove(method,Thread.currentThread());
78 }
79 }