src/main/java/com/stoyanr/evictor/map/ConcurrentMapWithTimedEvictionDecorator.java
/**
     * Replaces the entry for a key only if currently mapped to some value, for
     * the specified duration. This is equivalent to
     * 
     * <pre>
     * if (map.containsKey(key)) {
     *     return map.put(key, value, evictMs);
     * } else
     *     return null;
     * </pre>
     * 
     * except that the action is performed atomically.
     * 
     * @param key
     *            key with which the specified value is associated
     * 
     * @param value
     *            value to be associated with the specified key
     * 
     * @param evictMs
     *            the time in ms during which the entry can stay in the map
     *            (time-to-live). When this time has elapsed, the entry will be
     *            evicted from the map automatically. A value of 0 for this
     *            argument means "forever", i.e. <tt>replace(key, value, 0)</tt>
     *            is equivalent to <tt>replace(key, value)</tt>.
     * 
     * @return the previous value associated with the specified key, or
     *         <tt>null</tt> if there was no mapping for the key. (A
     *         <tt>null</tt> return can also indicate that the map previously
     *         associated <tt>null</tt> with the key, if the delegate map
     *         supports null values.)
     * 
     * @throws UnsupportedOperationException
     *             if the <tt>put</tt> operation is not supported by the
     *             delegate map
     * 
     * @throws ClassCastException
     *             if the class of the specified key or value prevents it from
     *             being stored in this map
     * 
     * @throws NullPointerException
     *             if the specified key is null and the delegate map does not
     *             permit null keys, or if the specified value is null
     * 
     * @throws IllegalArgumentException
     *             if some property of the specified key or value prevents it
     *             from being stored in this map, or if evictMs is negative
     */
Replaces the entry for a key only if currently mapped to some value, for
the specified duration. This is equivalent to


if (map.containsKey(key)) {
return map.put(key, value, evictMs);
} else
return null;


except that the action is performed atomically.

@param key
key with which the specified value is associated

@param value
value to be associated with the specified key

@param evictMs
the time in ms during which the entry can stay in the map
(time-to-live). When this time has elapsed, the entry will be
evicted from the map automatically. A value of 0 for this
argument means "forever", i.e.

@return the previous value associated with the specified key, or
null if there was no mapping for the key. (A
null return can also indicate that the map previously
associated null with the key, if the delegate map
supports null values.)

@throws UnsupportedOperationException
if the put operation is not supported by the
delegate map

@throws ClassCastException
if the class of the specified key or value prevents it from
being stored in this map

@throws NullPointerException
if the specified key is null and the delegate map does not
permit null keys, or if the specified value is null

@throws IllegalArgumentException
if some property of the specified key or value prevents it
from being stored in this map, or if evictMs is negative
Replaces the entry for a key only if currently mapped to some value for the specified duration . This is equivalent to if ( map . containsKey ( key )) { return map . put ( key value evictMs ) ; } else return null ; except that the action is performed atomically . @param key key with which the specified value is associated @param value value to be associated with the specified key @param evictMs the time in ms during which the entry can stay in the map ( time - to - live ) . When this time has elapsed the entry will be evicted from the map automatically . A value of 0 for this argument means " forever " i . e . @return the previous value associated with the specified key or null if there was no mapping for the key . ( A null return can also indicate that the map previously associated null with the key if the delegate map supports null values . ) @throws UnsupportedOperationException if the put operation is not supported by the delegate map @throws ClassCastException if the class of the specified key or value prevents it from being stored in this map @throws NullPointerException if the specified key is null and the delegate map does not permit null keys or if the specified value is null @throws IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map or if evictMs is negative
@Override
    public V replace(K key, V value, long evictMs) {
        EvictibleEntry<K, V> oe = this.delegate.get(key);
        if ((oe == null) || evictIfExpired(oe)) {
            return null;
        }
        EvictibleEntry<K, V> e = new EvictibleEntry<K, V>(this, key, value, evictMs);
        oe = this.delegate.replace(key, e);
        if (oe != null) {
            cancelEviction(oe);
            scheduleEviction(e);
        }
        return (oe != null) ? oe.getValue() : null;
    }
@ Override public V replace ( K key , V value , long evictMs ) { EvictibleEntry < K , V > oe = this . delegate . get ( key ) ; if ( ( oe == null ) || evictIfExpired ( oe ) ) { return null ; } EvictibleEntry < K , V > e = new EvictibleEntry < K , V > ( this , key , value , evictMs ) ; oe = this . delegate . replace ( key , e ) ; if ( oe != null ) { cancelEviction ( oe ) ; scheduleEviction ( e ) ; } return ( oe != null ) ? oe . getValue ( ) : null ; }
Replaces the entry for a key only if currently mapped to some value, for
 the specified duration.
Replaces the entry for a key only if currently mapped to some value for the specified duration .
// Avoid replacing an expired entry // Attempt replacement and schedule eviction if successful // An entry is being replaced, cancel the automatic eviction of the // old entry // and schedule it for the new entry