summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2010-12-29 01:57:23 +0000
committerBrian S. O'Neill <bronee@gmail.com>2010-12-29 01:57:23 +0000
commit39894a777bd166f9fbe5d8c329bac42e8c73b1d4 (patch)
treea805e1d85968b771f4cc136927854e9f2faa02d1 /src
parent5c877a749c0633a0fa6ef146b89d9a559637bc99 (diff)
Use new Cojen utility classes.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/util/QuickConstructorGenerator.java8
-rw-r--r--src/main/java/com/amazon/carbonado/util/SoftValuedCache.java75
2 files changed, 79 insertions, 4 deletions
diff --git a/src/main/java/com/amazon/carbonado/util/QuickConstructorGenerator.java b/src/main/java/com/amazon/carbonado/util/QuickConstructorGenerator.java
index a746c1f..e8c914e 100644
--- a/src/main/java/com/amazon/carbonado/util/QuickConstructorGenerator.java
+++ b/src/main/java/com/amazon/carbonado/util/QuickConstructorGenerator.java
@@ -43,7 +43,9 @@ import org.cojen.util.WeakIdentityMap;
* but the actual object type is not.
*
* @author Brian S O'Neill
+ * @deprecated use {@link org.cojen.util.QuickConstructorGenerator}
*/
+@Deprecated
public class QuickConstructorGenerator {
// Map<factory class, Map<object type, factory instance>>
@SuppressWarnings("unchecked")
@@ -86,6 +88,12 @@ public class QuickConstructorGenerator {
*/
@SuppressWarnings("unchecked")
public static synchronized <F> F getInstance(Class<?> objectType, Class<F> factory) {
+ try {
+ return org.cojen.util.QuickConstructorGenerator.getInstance(objectType, factory);
+ } catch (NoClassDefFoundError e) {
+ // Use older code instead.
+ }
+
SoftValuedCache<Class<?>, Object> innerCache = cCache.get(factory);
if (innerCache == null) {
innerCache = SoftValuedCache.newCache(7);
diff --git a/src/main/java/com/amazon/carbonado/util/SoftValuedCache.java b/src/main/java/com/amazon/carbonado/util/SoftValuedCache.java
index 3e9e767..c1562a6 100644
--- a/src/main/java/com/amazon/carbonado/util/SoftValuedCache.java
+++ b/src/main/java/com/amazon/carbonado/util/SoftValuedCache.java
@@ -27,13 +27,17 @@ import java.lang.ref.SoftReference;
* thread. Cache permits null keys, but not null values.
*
* @author Brian S O'Neill
+ * @deprecated use Cojen {@link org.cojen.util.Cache} interface
*/
+@Deprecated
public abstract class SoftValuedCache<K, V> {
- // Design note: Public class is abstract to make it easy to swap out this
- // implementation with something available in a shared collection library.
-
public static <K, V> SoftValuedCache<K, V> newCache(int capacity) {
- return new Impl<K, V>(capacity);
+ try {
+ return new Wrapper<K, V>(capacity);
+ } catch (NoClassDefFoundError e) {
+ // Use older implementation for compatibility.
+ return new Impl<K, V>(capacity);
+ }
}
public abstract int size();
@@ -58,6 +62,69 @@ public abstract class SoftValuedCache<K, V> {
public abstract String toString();
+ private static class Wrapper<K, V> extends SoftValuedCache<K, V> {
+ private final org.cojen.util.Cache<K, V> mCache;
+
+ Wrapper(int capacity) {
+ mCache = new org.cojen.util.SoftValueCache<K, V>(capacity);
+ }
+
+ @Override
+ public int size() {
+ return mCache.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return mCache.isEmpty();
+ }
+
+ @Override
+ public V get(K key) {
+ return mCache.get(key);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ return mCache.put(key, value);
+ }
+
+ @Override
+ public V putIfAbsent(K key, V value) {
+ return mCache.putIfAbsent(key, value);
+ }
+
+ @Override
+ public V remove(K key) {
+ return mCache.remove(key);
+ }
+
+ @Override
+ public boolean remove(K key, V value) {
+ return mCache.remove(key, value);
+ }
+
+ @Override
+ public boolean replace(K key, V oldValue, V newValue) {
+ return mCache.replace(key, oldValue, newValue);
+ }
+
+ @Override
+ public V replace(K key, V value) {
+ return mCache.replace(key, value);
+ }
+
+ @Override
+ public void clear() {
+ mCache.clear();
+ }
+
+ @Override
+ public String toString() {
+ return mCache.toString();
+ }
+ }
+
private static class Impl<K, V> extends SoftValuedCache<K, V> {
private static final float LOAD_FACTOR = 0.75f;