By the way, I am just going to commit SequencedSet.
(actually, it needs commons-collections.jar)
Now it's in org.jboss.ejb.plugins.cmp.jdbc package.
Should I move it to org.jboss.util.collection either?

alex

Friday, October 25, 2002, 11:15:59 PM, you wrote:

JD> Do you mind if this moves to org.jboss.util.collection?  So we can keeps
JD> things organized?

JD> --jason


>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:jboss-cvs-
>> [EMAIL PROTECTED]] On Behalf Of Bill Burke
>> Sent: Wednesday, October 23, 2002 2:43 PM
>> To: [EMAIL PROTECTED]
>> Subject: [jboss-cvs] jboss-common/src/main/org/jboss/util
>> WeakValueHashMap.java
>> 
>>   User: patriot1burke
>>   Date: 02/10/23 14:43:08
>> 
>>   Added:       src/main/org/jboss/util WeakValueHashMap.java
>>   Log:
>>   no message
>> 
>>   Revision  Changes    Path
>>   1.1                  jboss-
>> common/src/main/org/jboss/util/WeakValueHashMap.java
>> 
>>   Index: WeakValueHashMap.java
>>   ===================================================================
>>   /***************************************
>>    *                                     *
>>    *  JBoss: The OpenSource J2EE WebOS   *
>>    *                                     *
>>    *  Distributable under LGPL license.  *
>>    *  See terms of license at gnu.org.   *
>>    *                                     *
>>    ***************************************/
>> 
>>   package org.jboss.util;
>> 
>>   import java.util.Iterator;
>>   import java.util.Map;
>>   import java.util.AbstractMap;
>>   import java.util.HashMap;
>>   import java.util.Set;
>>   import java.util.AbstractSet;
>>   import java.util.NoSuchElementException;
>> 
>>   import java.lang.ref.WeakReference;
>>   import java.lang.ref.ReferenceQueue;
>> 
>> 
>>   /**
>>    * This Map will remove entries when the value in the map has been
>>    * cleaned from garbage collection
>>    *
>>    * @version <tt>$Revision: 1.1 $</tt>
>>    * @author  <a href="mailto:bill@;jboss.org">Bill Burke</a>
>>    */
>>   public class WeakValueHashMap extends AbstractMap implements Map
>>   {
>>      private static class WeakValueRef extends WeakReference
>>      {
>>         public Object key;
>> 
>>         private WeakValueRef(Object key, Object val, ReferenceQueue q)
JD> {
>>            super(val, q);
>>            this.key = key;
>>         }
>> 
>>         private static WeakValueRef create(Object key, Object val,
>> ReferenceQueue q) {
>>            if (val == null) return null;
>>            else return new WeakValueRef(key, val, q);
>>         }
>> 
>>      }
>>      public Set entrySet()
>>      {
>>         processQueue();
>>         return hash.entrySet();
>>      }
>> 
>>      /* Hash table mapping WeakKeys to values */
>>      private Map hash;
>> 
>>      /* Reference queue for cleared WeakKeys */
>>      private ReferenceQueue queue = new ReferenceQueue();
>> 
>> 
>>      /* Remove all invalidated entries from the map, that is, remove
JD> all
>> entries
>>         whose values have been discarded.
>>       */
>>      private void processQueue() {
>>         WeakValueRef ref;
>>         while ((ref = (WeakValueRef)queue.poll()) != null) {
>>            hash.remove(ref.key);
>>         }
>>      }
>> 
>> 
>> 
>> 
>>      /* -- Constructors -- */
>> 
>>      /**
>>       * Constructs a new, empty <code>WeakHashMap</code> with the
JD> given
>>       * initial capacity and the given load factor.
>>       *
>>       * @param  initialCapacity  The initial capacity of the
>>       *                          <code>WeakHashMap</code>
>>       *
>>       * @param  loadFactor       The load factor of the
>> <code>WeakHashMap</code>
>>       *
>>       * @throws IllegalArgumentException  If the initial capacity is
JD> less
>> than
>>       *                                   zero, or if the load factor
JD> is
>>       *                                   nonpositive
>>       */
>>      public WeakValueHashMap(int initialCapacity, float loadFactor) {
>>         hash = new HashMap(initialCapacity, loadFactor);
>>      }
>> 
>>      /**
>>       * Constructs a new, empty <code>WeakHashMap</code> with the
JD> given
>>       * initial capacity and the default load factor, which is
>>       * <code>0.75</code>.
>>       *
>>       * @param  initialCapacity  The initial capacity of the
>>       *                          <code>WeakHashMap</code>
>>       *
>>       * @throws IllegalArgumentException  If the initial capacity is
JD> less
>> than
>>       *                                   zero
>>       */
>>      public WeakValueHashMap(int initialCapacity) {
>>         hash = new HashMap(initialCapacity);
>>      }
>> 
>>      /**
>>       * Constructs a new, empty <code>WeakHashMap</code> with the
JD> default
>>       * initial capacity and the default load factor, which is
>>       * <code>0.75</code>.
>>       */
>>      public WeakValueHashMap() {
>>         hash = new HashMap();
>>      }
>> 
>>      /**
>>       * Constructs a new <code>WeakHashMap</code> with the same
JD> mappings
>> as the
>>       * specified <tt>Map</tt>.  The <code>WeakHashMap</code> is
JD> created
>> with an
>>       * initial capacity of twice the number of mappings in the
JD> specified
>> map
>>       * or 11 (whichever is greater), and a default load factor, which
JD> is
>>       * <tt>0.75</tt>.
>>       *
>>       * @param   t the map whose mappings are to be placed in this
JD> map.
>>       * @since        1.3
>>       */
>>      public WeakValueHashMap(Map t) {
>>         this(Math.max(2*t.size(), 11), 0.75f);
>>         putAll(t);
>>      }
>> 
>> 
>> 
>>      /* -- Simple queries -- */
>> 
>>      /**
>>       * Returns the number of key-value mappings in this map.
>>       * <strong>Note:</strong> <em>In contrast with most
JD> implementations
>> of the
>>       * <code>Map</code> interface, the time required by this
JD> operation is
>>       * linear in the size of the map.</em>
>>       */
>>      public int size() {
>>         processQueue();
>>         return hash.size();
>>      }
>> 
>>      /**
>>       * Returns <code>true</code> if this map contains no key-value
>> mappings.
>>       */
>>      public boolean isEmpty() {
>>         processQueue();
>>         return hash.isEmpty();
>>      }
>> 
>>      /**
>>       * Returns <code>true</code> if this map contains a mapping for
JD> the
>>       * specified key.
>>       *
>>       * @param   key   The key whose presence in this map is to be
JD> tested
>>       */
>>      public boolean containsKey(Object key) {
>>         processQueue();
>>         return hash.containsKey(key);
>>      }
>> 
>>      /* -- Lookup and modification operations -- */
>> 
>>      /**
>>       * Returns the value to which this map maps the specified
>> <code>key</code>.
>>       * If this map does not contain a value for this key, then return
>>       * <code>null</code>.
>>       *
>>       * @param  key  The key whose associated value, if any, is to be
>> returned
>>       */
>>      public Object get(Object key) {
>>         processQueue();
>>         WeakReference ref = (WeakReference)hash.get(key);
>>         if (ref != null) return ref.get();
>>         return null;
>>      }
>> 
>>      /**
>>       * Updates this map so that the given <code>key</code> maps to
JD> the
>> given
>>       * <code>value</code>.  If the map previously contained a mapping
JD> for
>>       * <code>key</code> then that mapping is replaced and the
JD> previous
>> value is
>>       * returned.
>>       *
>>       * @param  key    The key that is to be mapped to the given
>>       *                <code>value</code>
>>       * @param  value  The value to which the given <code>key</code>
JD> is to
>> be
>>       *                mapped
>>       *
>>       * @return  The previous value to which this key was mapped, or
>>       *          <code>null</code> if if there was no mapping for the
JD> key
>>       */
>>      public Object put(Object key, Object value)
>>      {
>>         processQueue();
>>         Object rtn = hash.put(key, WeakValueRef.create(key, value,
>> queue));
>>         if (rtn != null) rtn = ((WeakReference)rtn).get();
>>         return rtn;
>>      }
>> 
>>      /**
>>       * Removes the mapping for the given <code>key</code> from this
JD> map,
>> if
>>       * present.
>>       *
>>       * @param  key  The key whose mapping is to be removed
>>       *
>>       * @return  The value to which this key was mapped, or
>> <code>null</code> if
>>       *          there was no mapping for the key
>>       */
>>      public Object remove(Object key)
>>      {
>>         processQueue();
>>         return hash.remove(key);
>>      }
>> 
>>      /**
>>       * Removes all mappings from this map.
>>       */
>>      public void clear() {
>>         processQueue();
>>         hash.clear();
>>      }
>> 
>>   }

-- 
Best regards,
 Alex Loubyansky




-------------------------------------------------------
This sf.net email is sponsored by: Influence the future 
of Java(TM) technology. Join the Java Community 
Process(SM) (JCP(SM)) program now. 
http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to