From commons-user-return-12828-apmail-jakarta-commons-user-archive=jakarta.apache.org@jakarta.apache.org Tue Jul 12 18:23:40 2005 Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 89373 invoked from network); 12 Jul 2005 18:23:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Jul 2005 18:23:40 -0000 Received: (qmail 68276 invoked by uid 500); 12 Jul 2005 18:23:14 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 68130 invoked by uid 500); 12 Jul 2005 18:23:13 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 68083 invoked by uid 99); 12 Jul 2005 18:23:13 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2005 11:23:12 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=URIBL_SBL X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [129.219.110.120] (HELO post5.inre.asu.edu) (129.219.110.120) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2005 11:23:09 -0700 Received: from conversion.post5.inre.asu.edu by asu.edu (PMDF V6.1-1X6 #30769) id <0IJJ009011QC4W@asu.edu> for commons-user@jakarta.apache.org; Tue, 12 Jul 2005 11:23:00 -0700 (MST) Received: from smtp.asu.edu (smtp.asu.edu [129.219.110.107]) by asu.edu (PMDF V6.1-1X6 #30769) with ESMTP id <0IJJ006G31QC90@asu.edu> for commons-user@jakarta.apache.org; Tue, 12 Jul 2005 11:23:00 -0700 (MST) Received: from A2000018 (wsmoak.vpia.asu.edu [209.147.173.40]) by smtp.asu.edu (8.12.10/8.12.10/asu_smtp_relay,nullclient,tcp_wrapped) with SMTP id j6CIMuj5024130 for ; Tue, 12 Jul 2005 11:23:00 -0700 (MST) Date: Tue, 12 Jul 2005 11:22:44 -0700 From: Wendy Smoak Subject: Re: [collections] Name that data structure To: commons-user@jakarta.apache.org Message-id: <032f01c5870e$bc795f90$28ad93d1@irm.local> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Mailer: Microsoft Outlook Express 6.00.2800.1437 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit X-Priority: 3 X-MSMail-priority: Normal References: <006701c57fc3$1674c9b0$020ea8c0@imbrium1> <9c97dc7805070314392133a4e7@mail.gmail.com> <6.2.3.4.0.20050704094703.025299b0@exder.exder.se> <42CA4CC9.4040603@discursive.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Tim, I'm using your suggestion, and thanks for providing a complete example! I needed that. :) (It's here if anyone needs to refer to it: http://www.mail-archive.com/commons-user%40jakarta.apache.org/msg11963.html ) As written, however, it doesn't rearrange the values when you re-visit an item. In your example, after '1' gets added for the second time, the list should be 2,3,4,1 and instead it is still 1,2,3,4. (And that means '1' will be evicted too soon.) To fix that, I tried to simply remove any item before I add it, so it will always go to the end of the list as a new item: public static void add(Buffer recentVisited, String page) { recentVisited.remove( page ); try { recentVisited.add( page ); } catch( IllegalArgumentException iae ) { // do nothing, buffer will complain if predicate fails. } System.out.println( recentVisited ); } And was surprised to get : run: [java] [Page 1] [java] [Page 1, Page 2] [java] [Page 1, Page 2, Page 3] [java] [Page 1, Page 2, Page 3, Page 4] [java] [Page 2, Page 3, Page 4, Page 1] <--- it's working! [java] [Page 3, Page 4, Page 1, Page 2] [java] java.lang.ArrayIndexOutOfBoundsException: -1 ... [java] Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 [java] at org.apache.commons.collections.buffer.BoundedFifoBuffer$1.remove(BoundedFifo Buffer.java:347) [java] at java.util.AbstractCollection.remove(AbstractCollection.java:255) [java] at org.apache.commons.collections.collection.AbstractCollectionDecorator.remove (AbstractCollectionDecorator.java:103) [java] at RecentlyVisited.add(RecentlyVisited.java:53) [java] at RecentlyVisited.main(RecentlyVisited.java:39) It's coming from the third instance of add( recentVisited, "Page 1" ); in the example code. I put together a simple example that demonstrates the problem: http://wiki.wendysmoak.com/cgi-bin/wiki.pl?CircularFifoBuffer Bug? Surely I'm not doing anything wrong by calling remove(...) on a Collection? (Inefficient though it may be, first I just want to see it work.) Meanwhile, is there another way I can get the buffer to be in the correct LRU order? The LRUMap did work, but it's ugly having to put the empty String into the Map, when I don't need key/value pairs. Thanks, -- Wendy Smoak --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org