From 50201e804c982900ec0e564fafbc2713bc1e208d Mon Sep 17 00:00:00 2001 From: mdb Date: Fri, 17 Jan 2003 00:22:43 +0000 Subject: [PATCH] Canned in favor of LRU+regular hash map approach. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1025 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/util/LockableLRUHashMap.java | 84 ------------------- 1 file changed, 84 deletions(-) delete mode 100644 projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java diff --git a/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java b/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java deleted file mode 100644 index 59df46c8..00000000 --- a/projects/samskivert/src/java/com/samskivert/util/LockableLRUHashMap.java +++ /dev/null @@ -1,84 +0,0 @@ -// -// $Id: LockableLRUHashMap.java,v 1.2 2002/11/26 21:14:36 ray Exp $ - -package com.samskivert.util; - -import java.util.HashSet; -import java.util.Map; - -/** - * A LRU HashMap that allows specified keys to be locked such that they - * cannot be removed. - */ -public class LockableLRUHashMap extends LRUHashMap -{ - /** - * Construct a LockableLRUHashMap with the specified maximum number - * of unlocked elements. - */ - public LockableLRUHashMap (int baseMaxSize) - { - 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. - * - * @return false if the key was already locked and the max size was - * not altered. - */ - public boolean lock (Object key) - { - if (_locks.add(key)) { - _maxSize++; - return true; - } - return false; - } - - /** - * Unlock the specified key so that it can be removed. - * This has the side effect of decreasing the maximum size by 1. - * If the map is bigger than the new maximum size, the object with that - * key will be immediately removed. - * - * @return false if the key was not even locked in the first place. - */ - public boolean unlock (Object key) - { - if (_locks.remove(key)) { - _maxSize--; - if (size() > _maxSize) { - remove(key); - } - return true; - } - return false; - } - - // documentation inherited - protected boolean removeEldestEntry (Map.Entry eldest) - { - return (! _locks.contains(eldest.getKey())) && - super.removeEldestEntry(eldest); - } - - /** The set of keys that are locked. */ - protected HashSet _locks = new HashSet(); -}