added removeAll method to cache

This commit is contained in:
Sebastian Sdorra
2011-11-07 12:49:39 +01:00
parent fc90b92b97
commit 8a7091398b
3 changed files with 213 additions and 2 deletions

View File

@@ -40,6 +40,12 @@ import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.Filter;
//~--- JDK imports ------------------------------------------------------------
import java.util.Iterator;
/**
*
* @author Sebastian Sdorra
@@ -126,6 +132,36 @@ public class EhCache<K, V> implements Cache<K, V>
return cache.remove(key);
}
/**
* Method description
*
*
* @param filter
*
* @return
*/
@Override
public boolean removeAll(Filter<K> filter)
{
boolean result = true;
Iterator<K> it = cache.getKeys().iterator();
while (it.hasNext())
{
K key = it.next();
if (filter.accept(key))
{
if (!cache.remove(key))
{
result = false;
}
}
}
return result;
}
//~--- get methods ----------------------------------------------------------
/**