KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > util > SoftValueMap


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: SoftValueMap.java,v 1.4 2002/11/08 05:06:27 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.util;
12
13 import java.lang.ref.ReferenceQueue JavaDoc;
14 import java.lang.ref.SoftReference JavaDoc;
15 import java.util.Map JavaDoc;
16
17
18 /**
19  * A <code>java.util.Map</code> implementation with soft values.
20  *
21  * <P> The values are stored as soft references. If map entry value object is not
22  * actively being used, i.e. no other object has a strong reference to it, it may
23  * become garbage collected at the discretion of the garbage collector (typically if
24  * the VM is low on memory). If this happens, the entry in the <code>SoftValueMap</code>
25  * corresponding to the value object will also be removed.
26  *
27  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
28  * @version $Revision: 1.4 $
29  *
30  * @see SoftReference
31  */

32
33 public class SoftValueMap extends ReferenceValueMap
34 {
35     public SoftValueMap()
36     {
37         super();
38     }
39
40
41     public SoftValueMap(int initialCapacity)
42     {
43         super(initialCapacity);
44     }
45
46
47     public SoftValueMap(int initialCapacity, float loadFactor)
48     {
49         super(initialCapacity, loadFactor);
50     }
51
52
53     public SoftValueMap(Map JavaDoc m)
54     {
55         super(m);
56     }
57
58
59     private static class SoftValueReference extends SoftReference JavaDoc implements ReferenceValueMap.ValueReference
60     {
61         private final Object JavaDoc key;
62
63         SoftValueReference(Object JavaDoc key, Object JavaDoc value, ReferenceQueue JavaDoc q)
64         {
65             super(value, q);
66             this.key = key;
67         }
68
69         public Object JavaDoc getKey()
70         {
71             return key;
72         }
73     }
74
75     protected ReferenceValueMap.ValueReference newValueReference(Object JavaDoc key, Object JavaDoc value, ReferenceQueue JavaDoc queue)
76     {
77         return new SoftValueReference(key, value, queue);
78     }
79 }
80
Popular Tags