make clear() only clear entries that aren't locked.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@952 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2002-11-26 21:14:36 +00:00
parent eede8f6c0e
commit 44fc9cf753
@@ -1,5 +1,5 @@
//
// $Id: LockableLRUHashMap.java,v 1.1 2002/11/15 01:50:46 ray Exp $
// $Id: LockableLRUHashMap.java,v 1.2 2002/11/26 21:14:36 ray Exp $
package com.samskivert.util;
@@ -21,6 +21,21 @@ public class LockableLRUHashMap extends LRUHashMap
super(baseMaxSize);
}
/**
* Clear all entries but those that are currently locked.
*/
public void clear ()
{
// unfortunately there's not a better way to do this because all the
// appropriate variables have package access
Object[] keys = keySet().toArray();
for (int ii=0, nn=keys.length; ii < nn; ii++) {
if (! _locks.contains(keys[ii])) {
remove(keys[ii]);
}
}
}
/**
* Lock the specified key from being removed.
* This has the side effect of increasing the maximum size by 1.