[jboss-svn-commits] JBoss Common SVN: r2933 - in common-core/trunk/src: test/java/org/jboss/test/util/test/collection and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Nov 2 03:28:32 EST 2008
Author: alesj
Date: 2008-11-02 03:28:31 -0500 (Sun, 02 Nov 2008)
New Revision: 2933
Added:
common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueMap.java
common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueTreeMap.java
common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueRef.java
common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueTreeMap.java
common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueRef.java
common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueTreeMap.java
common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueHashMapUnitTestCase.java
common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueTreeMapUnitTestCase.java
common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueHashMapUnitTestCase.java
common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueTreeMapUnitTestCase.java
Removed:
common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueMapUnitTestCase.java
common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueMapUnitTestCase.java
Modified:
common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueHashMap.java
common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueHashMap.java
common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueHashMap.java
Log:
[JBCOMMON-72]; initial ValueTreeMap commit.
Modified: common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueHashMap.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueHashMap.java 2008-11-01 12:02:00 UTC (rev 2932)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueHashMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -21,15 +21,11 @@
*/
package org.jboss.util.collection;
-import java.lang.ref.ReferenceQueue;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Comparator;
+import java.util.SortedMap;
-
/**
* This Map will remove entries when the value in the map has been
* cleaned from garbage collection
@@ -40,171 +36,49 @@
* @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public abstract class ReferenceValueHashMap<K, V> extends AbstractMap<K, V>
+public abstract class ReferenceValueHashMap<K, V> extends ReferenceValueMap<K, V>
{
- /** Hash table mapping keys to ref values */
- private Map<K, ValueRef<K, V>> hash;
-
- /** Reference queue for cleared RefKeys */
- private ReferenceQueue<V> queue = new ReferenceQueue<V>();
-
- protected ReferenceValueHashMap(int initialCapacity, float loadFactor)
+ protected ReferenceValueHashMap()
{
- hash = new HashMap<K, ValueRef<K, V>>(initialCapacity, loadFactor);
}
protected ReferenceValueHashMap(int initialCapacity)
{
- hash = new HashMap<K, ValueRef<K, V>>(initialCapacity);
+ super(initialCapacity);
}
- protected ReferenceValueHashMap()
+ protected ReferenceValueHashMap(int initialCapacity, float loadFactor)
{
- hash = new HashMap<K, ValueRef<K, V>>();
+ super(initialCapacity, loadFactor);
}
protected ReferenceValueHashMap(Map<K, V> t)
{
- this(Math.max(2*t.size(), 11), 0.75f);
- putAll(t);
+ super(t);
}
- @Override
- public int size()
+ protected Map<K, ValueRef<K, V>> createMap(int initialCapacity, float loadFactor)
{
- processQueue();
- return hash.size();
+ return new HashMap<K, ValueRef<K,V>>(initialCapacity, loadFactor);
}
- @Override
- public boolean containsKey(Object key)
+ protected Map<K, ValueRef<K, V>> createMap(int initialCapacity)
{
- processQueue();
- return hash.containsKey(key);
+ return new HashMap<K, ValueRef<K,V>>(initialCapacity);
}
- @Override
- public V get(Object key)
+ protected Map<K, ValueRef<K, V>> createMap()
{
- processQueue();
- ValueRef<K, V> ref = hash.get(key);
- if (ref != null)
- return ref.get();
- return null;
+ return new HashMap<K, ValueRef<K,V>>();
}
- @Override
- public V put(K key, V value)
+ protected Map<K, ValueRef<K, V>> createMap(Comparator<K> kComparator)
{
- processQueue();
- ValueRef<K, V> ref = create(key, value, queue);
- ValueRef<K, V> result = hash.put(key, ref);
- if (result != null)
- return result.get();
- return null;
+ throw new UnsupportedOperationException("Cannot create HashMap with such parameters.");
}
- @Override
- public V remove(Object key)
+ protected Map<K, ValueRef<K, V>> createMap(SortedMap<K, ValueRef<K, V>> kValueRefSortedMap)
{
- processQueue();
- ValueRef<K, V> result = hash.remove(key);
- if (result != null)
- return result.get();
- return null;
+ throw new UnsupportedOperationException("Cannot create HashMap with such parameters.");
}
-
- @Override
- public Set<Entry<K,V>> entrySet()
- {
- processQueue();
- return new EntrySet();
- }
-
- @Override
- public void clear()
- {
- processQueue();
- hash.clear();
- }
-
- /**
- * Remove all entries whose values have been discarded.
- */
- @SuppressWarnings("unchecked")
- private void processQueue()
- {
- ValueRef<K, V> ref = (ValueRef<K, V>) queue.poll();
- while (ref != null)
- {
- // only remove if it is the *exact* same WeakValueRef
- if (ref == hash.get(ref.getKey()))
- hash.remove(ref.getKey());
-
- ref = (ValueRef<K, V>) queue.poll();
- }
- }
-
- /**
- * EntrySet.
- */
- private class EntrySet extends AbstractSet<Entry<K, V>>
- {
- @Override
- public Iterator<Entry<K, V>> iterator()
- {
- return new EntrySetIterator(hash.entrySet().iterator());
- }
-
- @Override
- public int size()
- {
- return ReferenceValueHashMap.this.size();
- }
- }
-
- /**
- * EntrySet iterator
- */
- private class EntrySetIterator implements Iterator<Entry<K, V>>
- {
- /** The delegate */
- private Iterator<Entry<K, ValueRef<K, V>>> delegate;
-
- /**
- * Create a new EntrySetIterator.
- *
- * @param delegate the delegate
- */
- public EntrySetIterator(Iterator<Entry<K, ValueRef<K, V>>> delegate)
- {
- this.delegate = delegate;
- }
-
- public boolean hasNext()
- {
- return delegate.hasNext();
- }
-
- public Entry<K, V> next()
- {
- Entry<K, ValueRef<K, V>> next = delegate.next();
- return next.getValue();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException("remove");
- }
- }
-
- /**
- * Create new value ref instance.
- *
- * @param key the key
- * @param value the value
- * @param q the ref queue
- * @return new value ref instance
- */
- protected abstract ValueRef<K, V> create(K key, V value, ReferenceQueue<V> q);
}
\ No newline at end of file
Copied: common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueMap.java (from rev 2932, common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueHashMap.java)
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueMap.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.collection;
+
+import java.lang.ref.ReferenceQueue;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+
+
+/**
+ * This Map will remove entries when the value in the map has been
+ * cleaned from garbage collection
+ *
+ * @param <K> the key type
+ * @param <V> the value type
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V>
+{
+ /** Hash table mapping keys to ref values */
+ private Map<K, ValueRef<K, V>> map;
+
+ /** Reference queue for cleared RefKeys */
+ private ReferenceQueue<V> queue = new ReferenceQueue<V>();
+
+ protected ReferenceValueMap()
+ {
+ map = createMap();
+ }
+
+ protected ReferenceValueMap(int initialCapacity)
+ {
+ map = createMap(initialCapacity);
+ }
+
+ protected ReferenceValueMap(int initialCapacity, float loadFactor)
+ {
+ map = createMap(initialCapacity, loadFactor);
+ }
+
+ protected ReferenceValueMap(Map<K, V> t)
+ {
+ this(Math.max(2*t.size(), 11), 0.75f);
+ putAll(t);
+ }
+
+ protected ReferenceValueMap(Comparator<K> comparator)
+ {
+ map = createMap(comparator);
+ }
+
+ protected ReferenceValueMap(SortedMap<K, ValueRef<K, V>> sorted)
+ {
+ map = createMap(sorted);
+ }
+
+ /**
+ * Create map.
+ *
+ * @return new map instance
+ */
+ protected abstract Map<K, ValueRef<K, V>> createMap();
+
+ /**
+ * Create map.
+ *
+ * @param initialCapacity the initial capacity
+ * @return new map instance
+ */
+ protected abstract Map<K, ValueRef<K, V>> createMap(int initialCapacity);
+
+ /**
+ * Create map.
+ *
+ * @param initialCapacity the initial capacity
+ * @param loadFactor the load factor
+ * @return new map instance
+ */
+ protected abstract Map<K, ValueRef<K, V>> createMap(int initialCapacity, float loadFactor);
+
+ /**
+ * Create map.
+ *
+ * @param comparator the comparator
+ * @return new map instance
+ */
+ protected abstract Map<K, ValueRef<K, V>> createMap(Comparator<K> comparator);
+
+ /**
+ * Create map.
+ *
+ * @param map the sorted map
+ * @return new map instance
+ */
+ protected abstract Map<K, ValueRef<K, V>> createMap(SortedMap<K, ValueRef<K, V>> map);
+
+ @Override
+ public int size()
+ {
+ processQueue();
+ return map.size();
+ }
+
+ @Override
+ public boolean containsKey(Object key)
+ {
+ processQueue();
+ return map.containsKey(key);
+ }
+
+ @Override
+ public V get(Object key)
+ {
+ processQueue();
+ ValueRef<K, V> ref = map.get(key);
+ if (ref != null)
+ return ref.get();
+ return null;
+ }
+
+ @Override
+ public V put(K key, V value)
+ {
+ processQueue();
+ ValueRef<K, V> ref = create(key, value, queue);
+ ValueRef<K, V> result = map.put(key, ref);
+ if (result != null)
+ return result.get();
+ return null;
+ }
+
+ @Override
+ public V remove(Object key)
+ {
+ processQueue();
+ ValueRef<K, V> result = map.remove(key);
+ if (result != null)
+ return result.get();
+ return null;
+ }
+
+ @Override
+ public Set<Entry<K,V>> entrySet()
+ {
+ processQueue();
+ return new EntrySet();
+ }
+
+ @Override
+ public void clear()
+ {
+ processQueue();
+ map.clear();
+ }
+
+ /**
+ * Remove all entries whose values have been discarded.
+ */
+ @SuppressWarnings("unchecked")
+ private void processQueue()
+ {
+ ValueRef<K, V> ref = (ValueRef<K, V>) queue.poll();
+ while (ref != null)
+ {
+ // only remove if it is the *exact* same WeakValueRef
+ if (ref == map.get(ref.getKey()))
+ map.remove(ref.getKey());
+
+ ref = (ValueRef<K, V>) queue.poll();
+ }
+ }
+
+ /**
+ * EntrySet.
+ */
+ private class EntrySet extends AbstractSet<Entry<K, V>>
+ {
+ @Override
+ public Iterator<Entry<K, V>> iterator()
+ {
+ return new EntrySetIterator(map.entrySet().iterator());
+ }
+
+ @Override
+ public int size()
+ {
+ return ReferenceValueMap.this.size();
+ }
+ }
+
+ /**
+ * EntrySet iterator
+ */
+ private class EntrySetIterator implements Iterator<Entry<K, V>>
+ {
+ /** The delegate */
+ private Iterator<Entry<K, ValueRef<K, V>>> delegate;
+
+ /**
+ * Create a new EntrySetIterator.
+ *
+ * @param delegate the delegate
+ */
+ public EntrySetIterator(Iterator<Entry<K, ValueRef<K, V>>> delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public boolean hasNext()
+ {
+ return delegate.hasNext();
+ }
+
+ public Entry<K, V> next()
+ {
+ Entry<K, ValueRef<K, V>> next = delegate.next();
+ return next.getValue();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("remove");
+ }
+ }
+
+ /**
+ * Create new value ref instance.
+ *
+ * @param key the key
+ * @param value the value
+ * @param q the ref queue
+ * @return new value ref instance
+ */
+ protected abstract ValueRef<K, V> create(K key, V value, ReferenceQueue<V> q);
+}
\ No newline at end of file
Copied: common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueTreeMap.java (from rev 2932, common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueHashMap.java)
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueTreeMap.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/ReferenceValueTreeMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.collection;
+
+import java.util.Comparator;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * This Map will remove entries when the value in the map has been
+ * cleaned from garbage collection
+ *
+ * @param <K> the key type
+ * @param <V> the value type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class ReferenceValueTreeMap<K, V> extends ReferenceValueMap<K, V>
+{
+ protected ReferenceValueTreeMap()
+ {
+ }
+
+ protected ReferenceValueTreeMap(Comparator<K> comparator)
+ {
+ super(comparator);
+ }
+
+ protected ReferenceValueTreeMap(SortedMap<K, ValueRef<K, V>> sorted)
+ {
+ super(sorted);
+ }
+
+ protected Map<K, ValueRef<K, V>> createMap()
+ {
+ return new TreeMap<K, ValueRef<K,V>>();
+ }
+
+ protected Map<K, ValueRef<K, V>> createMap(Comparator<K> comparator)
+ {
+ return new TreeMap<K, ValueRef<K,V>>(comparator);
+ }
+
+ protected Map<K, ValueRef<K, V>> createMap(SortedMap<K, ValueRef<K, V>> map)
+ {
+ return new TreeMap<K, ValueRef<K,V>>(map);
+ }
+
+ protected Map<K, ValueRef<K, V>> createMap(int initialCapacity)
+ {
+ throw new UnsupportedOperationException("Cannot create TreeMap with such parameters.");
+ }
+
+ protected Map<K, ValueRef<K, V>> createMap(int initialCapacity, float loadFactor)
+ {
+ throw new UnsupportedOperationException("Cannot create TreeMap with such parameters.");
+ }
+}
\ No newline at end of file
Modified: common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueHashMap.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueHashMap.java 2008-11-01 12:02:00 UTC (rev 2932)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueHashMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -22,7 +22,6 @@
package org.jboss.util.collection;
import java.lang.ref.ReferenceQueue;
-import java.lang.ref.SoftReference;
import java.util.Map;
/**
@@ -96,59 +95,4 @@
{
return SoftValueRef.create(key, value, q);
}
-
- /**
- * Soft value ref impl
- */
- private static class SoftValueRef<K, V> extends SoftReference<V> implements ValueRef<K, V>
- {
- /** The key */
- public K key;
-
- /**
- * Safely create a new SoftValueRef
- *
- * @param <K> the key type
- * @param <V> the value type
- * @param key the key
- * @param val the value
- * @param q the reference queue
- * @return the reference or null if the value is null
- */
- private static <K, V> SoftValueRef<K, V> create(K key, V val, ReferenceQueue<V> q)
- {
- if (val == null)
- return null;
- else
- return new SoftValueRef<K, V>(key, val, q);
- }
-
- /**
- * Create a new SoftValueRef.
- *
- * @param key the key
- * @param val the value
- * @param q the reference queue
- */
- private SoftValueRef(K key, V val, ReferenceQueue<V> q)
- {
- super(val, q);
- this.key = key;
- }
-
- public K getKey()
- {
- return key;
- }
-
- public V getValue()
- {
- return get();
- }
-
- public V setValue(V value)
- {
- throw new UnsupportedOperationException("setValue");
- }
- }
}
Copied: common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueRef.java (from rev 2932, common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueHashMap.java)
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueRef.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueRef.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.collection;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+/**
+ * Soft value ref.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @param <K> the key type
+ * @param <V> the value type
+ */
+class SoftValueRef<K, V> extends SoftReference<V> implements ValueRef<K, V>
+{
+ /**
+ * The key
+ */
+ public K key;
+
+ /**
+ * Safely create a new SoftValueRef
+ *
+ * @param <K> the key type
+ * @param <V> the value type
+ * @param key the key
+ * @param val the value
+ * @param q the reference queue
+ * @return the reference or null if the value is null
+ */
+ static <K, V> SoftValueRef<K, V> create(K key, V val, ReferenceQueue<V> q)
+ {
+ if (val == null)
+ return null;
+ else
+ return new SoftValueRef<K, V>(key, val, q);
+ }
+
+ /**
+ * Create a new SoftValueRef.
+ *
+ * @param key the key
+ * @param val the value
+ * @param q the reference queue
+ */
+ private SoftValueRef(K key, V val, ReferenceQueue<V> q)
+ {
+ super(val, q);
+ this.key = key;
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ public V getValue()
+ {
+ return get();
+ }
+
+ public V setValue(V value)
+ {
+ throw new UnsupportedOperationException("setValue");
+ }
+}
Copied: common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueTreeMap.java (from rev 2932, common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueHashMap.java)
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueTreeMap.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/SoftValueTreeMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.collection;
+
+import java.lang.ref.ReferenceQueue;
+import java.util.Comparator;
+import java.util.SortedMap;
+
+/**
+ * This Map will remove entries when the value in the map has been
+ * cleaned from garbage collection
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SoftValueTreeMap<K, V> extends ReferenceValueTreeMap<K, V>
+{
+ public SoftValueTreeMap()
+ {
+ }
+
+ public SoftValueTreeMap(Comparator<K> comparator)
+ {
+ super(comparator);
+ }
+
+ public SoftValueTreeMap(SortedMap<K, ValueRef<K, V>> sorted)
+ {
+ super(sorted);
+ }
+
+ protected ValueRef<K, V> create(K key, V value, ReferenceQueue<V> q)
+ {
+ return SoftValueRef.create(key, value, q);
+ }
+}
\ No newline at end of file
Modified: common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueHashMap.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueHashMap.java 2008-11-01 12:02:00 UTC (rev 2932)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueHashMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -22,7 +22,6 @@
package org.jboss.util.collection;
import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
import java.util.Map;
@@ -100,59 +99,4 @@
{
return WeakValueRef.create(key, value, q);
}
-
- /**
- * Weak value ref impl
- */
- private static class WeakValueRef<K, V> extends WeakReference<V> implements ValueRef<K, V>
- {
- /** The key */
- public K key;
-
- /**
- * Safely create a new WeakValueRef
- *
- * @param <K> the key type
- * @param <V> the value type
- * @param key the key
- * @param val the value
- * @param q the reference queue
- * @return the reference or null if the value is null
- */
- private static <K, V> WeakValueRef<K, V> create(K key, V val, ReferenceQueue<V> q)
- {
- if (val == null)
- return null;
- else
- return new WeakValueRef<K, V>(key, val, q);
- }
-
- /**
- * Create a new WeakValueRef.
- *
- * @param key the key
- * @param val the value
- * @param q the reference queue
- */
- private WeakValueRef(K key, V val, ReferenceQueue<V> q)
- {
- super(val, q);
- this.key = key;
- }
-
- public K getKey()
- {
- return key;
- }
-
- public V getValue()
- {
- return get();
- }
-
- public V setValue(V value)
- {
- throw new UnsupportedOperationException("setValue");
- }
- }
}
Added: common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueRef.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueRef.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueRef.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.collection;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+/**
+ * Weak value ref.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @param <K> the key type
+ * @param <V> the value type
+ */
+class WeakValueRef<K, V> extends WeakReference<V> implements ValueRef<K, V>
+{
+ /**
+ * The key
+ */
+ public K key;
+
+ /**
+ * Safely create a new WeakValueRef
+ *
+ * @param <K> the key type
+ * @param <V> the value type
+ * @param key the key
+ * @param val the value
+ * @param q the reference queue
+ * @return the reference or null if the value is null
+ */
+ static <K, V> WeakValueRef<K, V> create(K key, V val, ReferenceQueue<V> q)
+ {
+ if (val == null)
+ return null;
+ else
+ return new WeakValueRef<K, V>(key, val, q);
+ }
+
+ /**
+ * Create a new WeakValueRef.
+ *
+ * @param key the key
+ * @param val the value
+ * @param q the reference queue
+ */
+ private WeakValueRef(K key, V val, ReferenceQueue<V> q)
+ {
+ super(val, q);
+ this.key = key;
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ public V getValue()
+ {
+ return get();
+ }
+
+ public V setValue(V value)
+ {
+ throw new UnsupportedOperationException("setValue");
+ }
+}
\ No newline at end of file
Added: common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueTreeMap.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueTreeMap.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/WeakValueTreeMap.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.collection;
+
+import java.lang.ref.ReferenceQueue;
+import java.util.Comparator;
+import java.util.SortedMap;
+
+/**
+ * This Map will remove entries when the value in the map has been
+ * cleaned from garbage collection
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WeakValueTreeMap<K, V> extends ReferenceValueTreeMap<K, V>
+{
+ public WeakValueTreeMap()
+ {
+ }
+
+ public WeakValueTreeMap(Comparator<K> kComparator)
+ {
+ super(kComparator);
+ }
+
+ public WeakValueTreeMap(SortedMap<K, ValueRef<K, V>> sorted)
+ {
+ super(sorted);
+ }
+
+ protected ValueRef<K, V> create(K key, V value, ReferenceQueue<V> q)
+ {
+ return WeakValueRef.create(key, value, q);
+ }
+}
\ No newline at end of file
Copied: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueHashMapUnitTestCase.java (from rev 2931, common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueMapUnitTestCase.java)
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueHashMapUnitTestCase.java (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueHashMapUnitTestCase.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.util.test.collection;
+
+import java.util.Map;
+
+import org.jboss.util.collection.SoftValueHashMap;
+
+/**
+ * SoftValueHashMap test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SoftValueHashMapUnitTestCase extends AbstractMapUnitTest
+{
+ protected Map createEmptyMap()
+ {
+ return new SoftValueHashMap();
+ }
+}
Deleted: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueMapUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueMapUnitTestCase.java 2008-11-01 12:02:00 UTC (rev 2932)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueMapUnitTestCase.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -1,39 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.util.test.collection;
-
-import java.util.Map;
-
-import org.jboss.util.collection.SoftValueHashMap;
-
-/**
- * SoftValueHashMap test.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class SoftValueMapUnitTestCase extends AbstractMapUnitTest
-{
- protected Map createEmptyMap()
- {
- return new SoftValueHashMap();
- }
-}
Added: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueTreeMapUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueTreeMapUnitTestCase.java (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/SoftValueTreeMapUnitTestCase.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.util.test.collection;
+
+import java.util.Map;
+
+import org.jboss.util.collection.SoftValueTreeMap;
+
+/**
+ * SoftValueTreeMap test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SoftValueTreeMapUnitTestCase extends AbstractMapUnitTest
+{
+ protected Map createEmptyMap()
+ {
+ return new SoftValueTreeMap();
+ }
+}
\ No newline at end of file
Copied: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueHashMapUnitTestCase.java (from rev 2931, common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueMapUnitTestCase.java)
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueHashMapUnitTestCase.java (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueHashMapUnitTestCase.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.util.test.collection;
+
+import java.util.Map;
+
+import org.jboss.util.collection.WeakValueHashMap;
+
+/**
+ * WeakValueHashMap test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class WeakValueHashMapUnitTestCase extends AbstractMapUnitTest
+{
+ protected Map createEmptyMap()
+ {
+ return new WeakValueHashMap();
+ }
+}
\ No newline at end of file
Deleted: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueMapUnitTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueMapUnitTestCase.java 2008-11-01 12:02:00 UTC (rev 2932)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueMapUnitTestCase.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -1,39 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.util.test.collection;
-
-import java.util.Map;
-
-import org.jboss.util.collection.WeakValueHashMap;
-
-/**
- * WeakValueHashMap test.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class WeakValueMapUnitTestCase extends AbstractMapUnitTest
-{
- protected Map createEmptyMap()
- {
- return new WeakValueHashMap();
- }
-}
\ No newline at end of file
Copied: common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueTreeMapUnitTestCase.java (from rev 2931, common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueMapUnitTestCase.java)
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueTreeMapUnitTestCase.java (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/collection/WeakValueTreeMapUnitTestCase.java 2008-11-02 08:28:31 UTC (rev 2933)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.util.test.collection;
+
+import java.util.Map;
+
+import org.jboss.util.collection.WeakValueTreeMap;
+
+/**
+ * WeakValueTreeMap test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class WeakValueTreeMapUnitTestCase extends AbstractMapUnitTest
+{
+ protected Map createEmptyMap()
+ {
+ return new WeakValueTreeMap();
+ }
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list