From 44fc9cf7538f3b77244b6e69c2195ac0d61c3db9 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 26 Nov 2002 21:14:36 +0000 Subject: [PATCH] make clear() only clear entries that aren't locked. git-svn-id: https://samskivert.googlecode.com/svn/trunk@952 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/util/LockableLRUHashMap.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java b/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java index 57395606..59df46c8 100644 --- a/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java +++ b/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java @@ -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.