Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 85424 invoked from network); 24 Nov 2003 22:49:39 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 24 Nov 2003 22:49:39 -0000 Received: (qmail 42188 invoked by uid 500); 24 Nov 2003 22:49:21 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 42137 invoked by uid 500); 24 Nov 2003 22:49:20 -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 42124 invoked from network); 24 Nov 2003 22:49:20 -0000 Received: from unknown (HELO rhenium.btinternet.com) (194.73.73.93) by daedalus.apache.org with SMTP; 24 Nov 2003 22:49:20 -0000 Received: from host81-128-81-247.in-addr.btopenworld.com ([81.128.81.247] helo=oemcomputer) by rhenium.btinternet.com with smtp (Exim 3.22 #25) id 1AOPWI-0000FR-00 for commons-dev@jakarta.apache.org; Mon, 24 Nov 2003 22:49:26 +0000 Message-ID: <005d01c3b2dd$97ecc920$f7518051@oemcomputer> From: "Stephen Colebourne" To: "Jakarta Commons Developers List" References: <00d401c3b2af$01e14fb0$6601a8c0@trilobyte> <3FC24191.30908@phreaker.net> Subject: Re: [collections] Re: /PROPOSAL 1/ Additions to IteratorUtils Date: Mon, 24 Nov 2003 22:52:09 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N It seems like an odd thing to want to do. If you need to know the size, hold the data in a collection. Stephen ----- Original Message ----- > In the current CVS HEAD, you can do > > IteratorUtils.toArray(Iterator).length > or > IteratorUtils.toList(Iterator).size() > > But, your suggestion may be a good addition also. > > Also, I think that the method definitions you've provided will all cause > infinite loops -- hasNext() will always return true if you don't call > next(). We'd need to find a way to copy the iterator so we don't modify > it's state when we count the elements. > > Anyone else have an opinion? > > > > > Lee Crawford wrote: > > I'd like to propose the following simple additions to the > > o.a.c.c.IteratorUtils > > class. > > > > The following is a simple convenience method for counting the number of > > elements > > in an iteration, something that I find myself recreating somewhat > > frequently: > > > > public static > > int countElements (final Iterator iter) { > > int cnt = 0; > > while (iter.hasNext ()) { > > cnt ++; > > } > > return cnt; > > } > > > > There isn't an EnumeratorUtils present that might contain an equivalent: > > > > > > public static > > int countElements (final Enumerator enum) { > > int cnt = 0; > > while (enum.hasNext ()) { > > cnt ++; > > } > > return cnt; > > } > > > > Or the slightly less performant: > > > > public static > > int countElements (final Enumerator enum) { > > return IteratorUtils.countElements (asIterator (enum)); > > } > > > > Thoughts? > > > > --lee > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org