01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: SoftValueMap.java,v 1.4 2002/11/08 05:06:27 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.util;
12:
13: import java.lang.ref.ReferenceQueue;
14: import java.lang.ref.SoftReference;
15: import java.util.Map;
16:
17: /**
18: * A <code>java.util.Map</code> implementation with soft values.
19: *
20: * <P> The values are stored as soft references. If map entry value object is not
21: * actively being used, i.e. no other object has a strong reference to it, it may
22: * become garbage collected at the discretion of the garbage collector (typically if
23: * the VM is low on memory). If this happens, the entry in the <code>SoftValueMap</code>
24: * corresponding to the value object will also be removed.
25: *
26: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
27: * @version $Revision: 1.4 $
28: *
29: * @see SoftReference
30: */
31:
32: public class SoftValueMap extends ReferenceValueMap {
33: public SoftValueMap() {
34: super ();
35: }
36:
37: public SoftValueMap(int initialCapacity) {
38: super (initialCapacity);
39: }
40:
41: public SoftValueMap(int initialCapacity, float loadFactor) {
42: super (initialCapacity, loadFactor);
43: }
44:
45: public SoftValueMap(Map m) {
46: super (m);
47: }
48:
49: private static class SoftValueReference extends SoftReference
50: implements ReferenceValueMap.ValueReference {
51: private final Object key;
52:
53: SoftValueReference(Object key, Object value, ReferenceQueue q) {
54: super (value, q);
55: this .key = key;
56: }
57:
58: public Object getKey() {
59: return key;
60: }
61: }
62:
63: protected ReferenceValueMap.ValueReference newValueReference(
64: Object key, Object value, ReferenceQueue queue) {
65: return new SoftValueReference(key, value, queue);
66: }
67: }
|