aboutsummaryrefslogtreecommitdiffstats
path: root/docs/adk15ProgGuideDB
diff options
context:
space:
mode:
authoracolyer <acolyer>2004-12-17 13:25:52 +0000
committeracolyer <acolyer>2004-12-17 13:25:52 +0000
commit6ede239232cade1dbd454d58f4e853366e422099 (patch)
treeedef2f3c11b9a1dc8a4e9bb2cede357424478d9e /docs/adk15ProgGuideDB
parenta5eb692fe2be04f482da90dd1f8565c3d5bbe1a3 (diff)
downloadaspectj-6ede239232cade1dbd454d58f4e853366e422099.tar.gz
aspectj-6ede239232cade1dbd454d58f4e853366e422099.zip
incorporate tim peierls suggestion from mailing list
Diffstat (limited to 'docs/adk15ProgGuideDB')
-rw-r--r--docs/adk15ProgGuideDB/pertypewithin.xml31
1 files changed, 11 insertions, 20 deletions
diff --git a/docs/adk15ProgGuideDB/pertypewithin.xml b/docs/adk15ProgGuideDB/pertypewithin.xml
index e3f5ec0ae..ec099c1fd 100644
--- a/docs/adk15ProgGuideDB/pertypewithin.xml
+++ b/docs/adk15ProgGuideDB/pertypewithin.xml
@@ -54,21 +54,16 @@
<programlisting><![CDATA[
public aspect InstanceTracking pertypewithin(org.xyz..*) {
-
- private Set<WeakReference<Object>> instances = new HashSet<WeakReference<Object>>();
+
+ // use WeakHashMap for auto-garbage collection of keys
+ private Map<?,Boolean> instances = new WeakHashMap<?,Boolean>();
after(Object o) returning : execution(new(..)) {
- instances.add(new WeakReference<Object>(o);
+ instances.put(o,true);
}
- public Set<Object> getInstances() {
- Set<Object> result = new HashSet<Object>();
- for(WeakReference<Object> ref : instances) {
- if (ref.get() != null) {
- result.add(ref.get());
- }
- }
- return result;
+ public Set<?> getInstances() {
+ return instances.keySet();
}
}
]]></programlisting>
@@ -95,21 +90,17 @@
<programlisting><![CDATA[
public aspect InstanceTracking<T> pertypewithin(org.xyz..*) {
- private Set<WeakReference<T>> instances = new HashSet<WeakReference<T>>();
+ // use WeakHashMap for auto-garbage collection of keys
+ private Map<T, Boolean> instances = new WeakHashMap<T, Boolean>();
after(T t) returning : execution(new(..)) {
- instances.add(new WeakReference<T>(t);
+ instances.put(t, true);
}
public Set<T> getInstances() {
- Set<T> result = new HashSet<T>();
- for(WeakReference<T> ref : instances) {
- if (ref.get() != null) {
- result.add(ref.get());
- }
- }
- return result;
+ return instances.keySet();
}
+
}
]]></programlisting>