src/main/java/com/stoyanr/evictor/map/ConcurrentMapWithTimedEvictionDecorator.java
/**
     * Replaces the entry for a key only if currently mapped to a given value,
     * for the specified duration. This is equivalent to
     * 
     * <pre>
     * if (map.containsKey(key) &amp;&amp; map.get(key).equals(oldValue)) {
     *     map.put(key, newValue, evictMs);
     *     return true;
     * } else
     *     return false;
     * </pre>
     * 
     * except that the action is performed atomically.
     * 
     * @param key
     *            key with which the specified value is associated
     * 
     * @param oldValue
     *            value expected to be associated with the specified key
     * 
     * @param newValue
     *            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, oldValue, newValue, 0)</tt> is equivalent to
     *            <tt>put(key, oldValue, newValue)</tt>.
     * 
     * @return <tt>true</tt> if the value was replaced
     * 
     * @throws UnsupportedOperationException
     *             if the <tt>put</tt> operation is not supported by the
     *             delegate map
     * 
     * @throws ClassCastException
     *             if the class of a 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 a 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 a given value,
for the specified duration. This is equivalent to



except that the action is performed atomically.

@param key
key with which the specified value is associated

@param oldValue
value expected to be associated with the specified key

@param newValue
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.
replace(key, oldValue, newValue, 0) is equivalent to
put(key, oldValue, newValue).

@return true if the value was replaced

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

@throws ClassCastException
if the class of a 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 a 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 a given value for the specified duration . This is equivalent to except that the action is performed atomically . @param key key with which the specified value is associated @param oldValue value expected to be associated with the specified key @param newValue 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 . replace ( key oldValue newValue 0 ) is equivalent to put ( key oldValue newValue ) . @return true if the value was replaced @throws UnsupportedOperationException if the put operation is not supported by the delegate map @throws ClassCastException if the class of a 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 a specified key or value prevents it from being stored in this map or if evictMs is negative
@Override
    public boolean replace(K key, V oldValue, V newValue, long evictMs) {
        if (oldValue == null) {
            throw new NullPointerException("Old value cannot be nul");
        }
        EvictibleEntry<K, V> oe = delegate.get(key);
        if ((oe == null) || evictIfExpired(oe) || !oldValue.equals(oe.getValue())) {
            return false;
        }
        EvictibleEntry<K, V> e = new EvictibleEntry<K, V>(this, key, newValue, evictMs);
        boolean replaced = delegate.replace(key, oe, e);
        if (replaced) {
            cancelEviction(oe);
            scheduleEviction(e);
        }
        return replaced;
    }
@ Override public boolean replace ( K key , V oldValue , V newValue , long evictMs ) { if ( oldValue == null ) { throw new NullPointerException ( "Old value cannot be nul" ) ; } EvictibleEntry < K , V > oe = delegate . get ( key ) ; if ( ( oe == null ) || evictIfExpired ( oe ) || ! oldValue . equals ( oe . getValue ( ) ) ) { return false ; } EvictibleEntry < K , V > e = new EvictibleEntry < K , V > ( this , key , newValue , evictMs ) ; boolean replaced = delegate . replace ( key , oe , e ) ; if ( replaced ) { cancelEviction ( oe ) ; scheduleEviction ( e ) ; } return replaced ; }
Replaces the entry for a key only if currently mapped to a given value,
 for the specified duration.
Replaces the entry for a key only if currently mapped to a given 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