/** * Removes the entry with the given key if the entry's expiration time is * less than <code>now</code>. If the entry has a negative expiration time, * the entry is never removed. */ private void removeIfExpired(final Object key, final long now) { final Long expirationTimeObject = expirationMap.get(key); if (isExpired(now, expirationTimeObject)) { remove(key); } }
/** * Removes all entries in the map whose expiration time is less than * <code>now</code>. The exceptions are entries with negative expiration * times; those entries are never removed. * * @see #isExpired(long, Long) */ private void removeAllExpired(final long now) { final Iterator<Map.Entry<Object, Long>> iter = expirationMap.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<Object, Long> expirationEntry = iter.next(); if (isExpired(now, expirationEntry.getValue())) { // remove entry from collection super.remove(expirationEntry.getKey()); // remove entry from expiration map iter.remove(); } } }