src/share/classes/sun/misc/SoftCache.java

Print this page




 292             if (v != null) {
 293                 hash.put(key, ValueCell.create(key, v, queue));
 294                 return v;
 295             }
 296         }
 297         return ValueCell.strip(v, false);
 298     }
 299 
 300     /**
 301      * Update this cache so that the given <code>key</code> maps to the given
 302      * <code>value</code>.  If the cache previously contained a mapping for
 303      * <code>key</code> then that mapping is replaced and the old value is
 304      * returned.
 305      *
 306      * @param  key    The key that is to be mapped to the given
 307      *                <code>value</code>
 308      * @param  value  The value to which the given <code>key</code> is to be
 309      *                mapped
 310      *
 311      * @return  The previous value to which this key was mapped, or
 312      *          <code>null</code> if if there was no mapping for the key
 313      */
 314     public Object put(Object key, Object value) {
 315         processQueue();
 316         ValueCell vc = ValueCell.create(key, value, queue);
 317         return ValueCell.strip(hash.put(key, vc), true);
 318     }
 319 
 320     /**
 321      * Remove the mapping for the given <code>key</code> from this cache, if
 322      * present.
 323      *
 324      * @param  key  The key whose mapping is to be removed
 325      *
 326      * @return  The value to which this key was mapped, or <code>null</code> if
 327      *          there was no mapping for the key
 328      */
 329     public Object remove(Object key) {
 330         processQueue();
 331         return ValueCell.strip(hash.remove(key), true);
 332     }




 292             if (v != null) {
 293                 hash.put(key, ValueCell.create(key, v, queue));
 294                 return v;
 295             }
 296         }
 297         return ValueCell.strip(v, false);
 298     }
 299 
 300     /**
 301      * Update this cache so that the given <code>key</code> maps to the given
 302      * <code>value</code>.  If the cache previously contained a mapping for
 303      * <code>key</code> then that mapping is replaced and the old value is
 304      * returned.
 305      *
 306      * @param  key    The key that is to be mapped to the given
 307      *                <code>value</code>
 308      * @param  value  The value to which the given <code>key</code> is to be
 309      *                mapped
 310      *
 311      * @return  The previous value to which this key was mapped, or
 312      *          <code>null</code> if there was no mapping for the key
 313      */
 314     public Object put(Object key, Object value) {
 315         processQueue();
 316         ValueCell vc = ValueCell.create(key, value, queue);
 317         return ValueCell.strip(hash.put(key, vc), true);
 318     }
 319 
 320     /**
 321      * Remove the mapping for the given <code>key</code> from this cache, if
 322      * present.
 323      *
 324      * @param  key  The key whose mapping is to be removed
 325      *
 326      * @return  The value to which this key was mapped, or <code>null</code> if
 327      *          there was no mapping for the key
 328      */
 329     public Object remove(Object key) {
 330         processQueue();
 331         return ValueCell.strip(hash.remove(key), true);
 332     }