Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WeakKeyedReference |
|
| 0.0;0 |
1 | /* | |
2 | * RCache - A collection of simple reference-based cache implementations. | |
3 | * Copyright (C) 2007 Rodrigo Ruiz | |
4 | * | |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Lesser General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2.1 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | * | |
19 | * Alternatively, the contents of this file may be used under the terms | |
20 | * of the Apache 2.0 license (the "Apache License"), in which case its | |
21 | * provisions are applicable instead of those above. If you wish to allow use | |
22 | * of your version of this file only* under the terms of the Apache License | |
23 | * and not to allow others to use your version of this file under the LGPL, | |
24 | * indicate your decision by* deleting the provisions above and replace them | |
25 | * with the notice and other provisions required by the Apache License. If | |
26 | * you do not delete the provisions above, a recipient may use your version of | |
27 | * this file under either the LGPL or the Apache License. | |
28 | */ | |
29 | package net.sourceforge.rcache; | |
30 | ||
31 | import java.lang.ref.ReferenceQueue; | |
32 | import java.lang.ref.WeakReference; | |
33 | ||
34 | /** | |
35 | * <p>KeyedReference implementation based on {@link WeakReference}.</p> | |
36 | * | |
37 | * @author Rodrigo Ruiz | |
38 | * @param <K> the type of keys maintained by this cache | |
39 | * @param <V> the type of cached values | |
40 | */ | |
41 | public final class WeakKeyedReference<K, V> extends WeakReference<V> | |
42 | implements KeyedReference<K, V> { | |
43 | ||
44 | /** | |
45 | * The key for this value in the cache. | |
46 | */ | |
47 | private final K key; | |
48 | ||
49 | /** | |
50 | * WeakKeyedReference constructor. | |
51 | * | |
52 | * @param key the key | |
53 | * @param value the object to cache | |
54 | * @param rq a reference queue | |
55 | */ | |
56 | public WeakKeyedReference(K key, V value, ReferenceQueue<V> rq) { | |
57 | 22 | super(value, rq); |
58 | 22 | this.key = key; |
59 | 22 | } |
60 | ||
61 | /** | |
62 | * Get the reference key. | |
63 | * | |
64 | * @return The key | |
65 | */ | |
66 | public K getKey() { | |
67 | 3 | return key; |
68 | } | |
69 | } |