| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SoftKeyedReference |
|
| 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.SoftReference; | |
| 33 | ||
| 34 | /** | |
| 35 | * <p>KeyedReference implementation based on | |
| 36 | * {@link java.lang.ref.SoftReference}.</p> | |
| 37 | * | |
| 38 | * @author Rodrigo Ruiz | |
| 39 | * @param <K> the type of keys maintained by this cache | |
| 40 | * @param <V> the type of cached values | |
| 41 | */ | |
| 42 | public final class SoftKeyedReference<K, V> extends SoftReference<V> | |
| 43 | implements KeyedReference<K, V> { | |
| 44 | ||
| 45 | /** | |
| 46 | * The key for this value in the cache. | |
| 47 | */ | |
| 48 | private final K key; | |
| 49 | ||
| 50 | /** | |
| 51 | * SoftKeyedReference constructor. | |
| 52 | * | |
| 53 | * @param key the key | |
| 54 | * @param value the object to cache | |
| 55 | * @param rq a reference queue | |
| 56 | */ | |
| 57 | public SoftKeyedReference(K key, V value, ReferenceQueue<V> rq) { | |
| 58 | 14 | super(value, rq); |
| 59 | 14 | this.key = key; |
| 60 | 14 | } |
| 61 | ||
| 62 | /** | |
| 63 | * Get the reference key. | |
| 64 | * | |
| 65 | * @return The key | |
| 66 | */ | |
| 67 | public K getKey() { | |
| 68 | 1 | return key; |
| 69 | } | |
| 70 | } |