Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 75942 invoked from network); 14 Feb 2002 21:00:14 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 14 Feb 2002 21:00:14 -0000 Received: (qmail 16229 invoked by uid 97); 14 Feb 2002 20:58:17 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 16212 invoked by uid 97); 14 Feb 2002 20:58:16 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 16198 invoked by uid 97); 14 Feb 2002 20:58:16 -0000 Date: 14 Feb 2002 20:57:59 -0000 Message-ID: <20020214205759.37883.qmail@icarus.apache.org> From: morgand@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestLRUMap.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N morgand 02/02/14 12:57:59 Modified: collections/src/test/org/apache/commons/collections TestLRUMap.java Log: unit tests for subclass behaviour Revision Changes Path 1.6 +72 -4 jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java Index: TestLRUMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TestLRUMap.java 13 Feb 2002 23:55:41 -0000 1.5 +++ TestLRUMap.java 14 Feb 2002 20:57:59 -0000 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.5 2002/02/13 23:55:41 morgand Exp $ - * $Revision: 1.5 $ - * $Date: 2002/02/13 23:55:41 $ + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.6 2002/02/14 20:57:59 morgand Exp $ + * $Revision: 1.6 $ + * $Date: 2002/02/14 20:57:59 $ * * ==================================================================== * @@ -71,7 +71,7 @@ * * @author James Strachan * @author Morgan Delagrange - * @version $Id: TestLRUMap.java,v 1.5 2002/02/13 23:55:41 morgand Exp $ + * @version $Id: TestLRUMap.java,v 1.6 2002/02/14 20:57:59 morgand Exp $ */ public class TestLRUMap extends TestHashMap { @@ -150,5 +150,73 @@ map2.containsKey(new Integer(4))); } + /** + * You should be able to subclass LRUMap and perform a + * custom action when items are removed automatically + * by the LRU algorithm (the removeLRU() method). + */ + public void testLRUSubclass() { + LRUCounter counter = new LRUCounter(3); + counter.put(new Integer(1),"foo"); + counter.put(new Integer(2),"foo"); + counter.put(new Integer(3),"foo"); + counter.put(new Integer(1),"foo"); + counter.put(new Integer(4),"foo"); + counter.put(new Integer(5),"foo"); + counter.put(new Integer(2),"foo"); + counter.remove(new Integer(5)); + + assertTrue("size should be 2, but was " + counter.size(), counter.size() == 2); + assertTrue("removedCount should be 2 but was " + counter.removedCount, + counter.removedCount == 2); + } + + /** + * You should be able to subclass LRUMap and perform a + * custom action when items are removed automatically + * or when remove is called manually + * by overriding the remove(Object) method. + */ + public void testRemoveSubclass() { + RemoveCounter counter = new RemoveCounter(3); + counter.put(new Integer(1),"foo"); + counter.put(new Integer(2),"foo"); + counter.put(new Integer(3),"foo"); + counter.put(new Integer(1),"foo"); + counter.put(new Integer(4),"foo"); + counter.put(new Integer(5),"foo"); + counter.put(new Integer(2),"foo"); + counter.remove(new Integer(5)); + + assertTrue("size should be 2, but was " + counter.size(), counter.size() == 2); + assertTrue("removedCount should be 3 but was " + counter.removedCount, + counter.removedCount == 3); + } + + private class LRUCounter extends LRUMap { + int removedCount = 0; + + LRUCounter(int i) { + super(i); + } + + public Object removeLRU() { + ++removedCount; + return super.removeLRU(); + } + } + + private class RemoveCounter extends LRUMap { + int removedCount = 0; + + RemoveCounter(int i) { + super(i); + } + + public Object remove(Object o) { + ++removedCount; + return super.remove(o); + } + } } -- To unsubscribe, e-mail: For additional commands, e-mail: