/[classpath]/classpath/java/util/WeakHashMap.java
ViewVC logotype

Diff of /classpath/java/util/WeakHashMap.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18.2.1 by gnu_andrew, Mon Jan 10 18:25:48 2005 UTC revision 1.18.2.2 by tromey, Wed Jan 12 01:12:48 2005 UTC
# Line 353  public class WeakHashMap<K,V> extends Ab Line 353  public class WeakHashMap<K,V> extends Ab
353     *     *
354     * @author Jochen Hoenicke     * @author Jochen Hoenicke
355     */     */
356    private static class WeakBucket extends WeakReference    private static class WeakBucket<K, V> extends WeakReference<K>
357    {    {
358      /**      /**
359       * The value of this entry.  The key is stored in the weak       * The value of this entry.  The key is stored in the weak
360       * reference that we extend.       * reference that we extend.
361       */       */
362      Object value;      V value;
363    
364      /**      /**
365       * The next bucket describing another entry that uses the same       * The next bucket describing another entry that uses the same
366       * slot.       * slot.
367       */       */
368      WeakBucket next;      WeakBucket<K, V> next;
369    
370      /**      /**
371       * The slot of this entry. This should be       * The slot of this entry. This should be
# Line 388  public class WeakHashMap<K,V> extends Ab Line 388  public class WeakHashMap<K,V> extends Ab
388       * @param slot the slot.  This must match the slot where this bucket       * @param slot the slot.  This must match the slot where this bucket
389       *        will be enqueued.       *        will be enqueued.
390       */       */
391      public WeakBucket(Object key, ReferenceQueue queue, Object value,      public WeakBucket(K key, ReferenceQueue queue, V value,
392                        int slot)                        int slot)
393      {      {
394        super(key, queue);        super(key, queue);
# Line 401  public class WeakHashMap<K,V> extends Ab Line 401  public class WeakHashMap<K,V> extends Ab
401       * current bucket.  It also keeps a strong reference to the       * current bucket.  It also keeps a strong reference to the
402       * key; bad things may happen otherwise.       * key; bad things may happen otherwise.
403       */       */
404      class WeakEntry implements Map.Entry      class WeakEntry implements Map.Entry<K, V>
405      {      {
406        /**        /**
407         * The strong ref to the key.         * The strong ref to the key.
408         */         */
409        Object key;        K key;
410    
411        /**        /**
412         * Creates a new entry for the key.         * Creates a new entry for the key.
413         * @param key the key         * @param key the key
414         */         */
415        public WeakEntry(Object key)        public WeakEntry(K key)
416        {        {
417          this.key = key;          this.key = key;
418        }        }
# Line 430  public class WeakHashMap<K,V> extends Ab Line 430  public class WeakHashMap<K,V> extends Ab
430         * Returns the key.         * Returns the key.
431         * @return the key         * @return the key
432         */         */
433        public Object getKey()        public K getKey()
434        {        {
435          return key == NULL_KEY ? null : key;          return key == NULL_KEY ? null : key;
436        }        }
# Line 439  public class WeakHashMap<K,V> extends Ab Line 439  public class WeakHashMap<K,V> extends Ab
439         * Returns the value.         * Returns the value.
440         * @return the value         * @return the value
441         */         */
442        public Object getValue()        public V getValue()
443        {        {
444          return value;          return value;
445        }        }
# Line 450  public class WeakHashMap<K,V> extends Ab Line 450  public class WeakHashMap<K,V> extends Ab
450         * @param newVal the new value         * @param newVal the new value
451         * @return the old value         * @return the old value
452         */         */
453        public Object setValue(Object newVal)        public V setValue(V newVal)
454        {        {
455          Object oldVal = value;          V oldVal = value;
456          value = newVal;          value = newVal;
457          return oldVal;          return oldVal;
458        }        }
# Line 495  public class WeakHashMap<K,V> extends Ab Line 495  public class WeakHashMap<K,V> extends Ab
495       */       */
496      WeakEntry getEntry()      WeakEntry getEntry()
497      {      {
498        final Object key = this.get();        final K key = this.get();
499        if (key == null)        if (key == null)
500          return null;          return null;
501        return new WeakEntry(key);        return new WeakEntry(key);
# Line 762  public class WeakHashMap<K,V> extends Ab Line 762  public class WeakHashMap<K,V> extends Ab
762    public V get(Object key)    public V get(Object key)
763    {    {
764      cleanQueue();      cleanQueue();
765      WeakBucket.WeakEntry entry = internalGet(key);      WeakBucket<K, V>.WeakEntry entry = internalGet(key);
766      return entry == null ? null : entry.getValue();      return entry == null ? null : entry.getValue();
767    }    }
768    
# Line 774  public class WeakHashMap<K,V> extends Ab Line 774  public class WeakHashMap<K,V> extends Ab
774     *         null if the key wasn't in this map, or if the mapped value     *         null if the key wasn't in this map, or if the mapped value
775     *         was explicitly set to null.     *         was explicitly set to null.
776     */     */
777    public Object put(K key, V value)    public V put(K key, V value)
778    {    {
779      cleanQueue();      cleanQueue();
780      WeakBucket.WeakEntry entry = internalGet(key);      WeakBucket<K, V>.WeakEntry entry = internalGet(key);
781      if (entry != null)      if (entry != null)
782        return entry.setValue(value);        return entry.setValue(value);
783    
# Line 799  public class WeakHashMap<K,V> extends Ab Line 799  public class WeakHashMap<K,V> extends Ab
799    public V remove(Object key)    public V remove(Object key)
800    {    {
801      cleanQueue();      cleanQueue();
802      WeakBucket.WeakEntry entry = internalGet(key);      WeakBucket<K, V>.WeakEntry entry = internalGet(key);
803      if (entry == null)      if (entry == null)
804        return null;        return null;
805    

Legend:
Removed from v.1.18.2.1  
changed lines
  Added in v.1.18.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26