my reason for the code is because the IteratorUtils methods return iterators of 
arbitrary objects and i really don't want the underlying collection.  i just want to 
set up some array sizes based on the list size, but i am not going to perform any 
operation on the list itself, just iterate through it.

my specific example is an html table with an database resultset (returned as a 
Collection) as its backing.  i have a 'select all' button for the table.  i want to 
load an array with the selected items.  i use the IteratorUtils class to rip through a 
Collection that is the data to look for checked items.  so all i ever see is an 
iterator, i never get the collection itself, and i don't need to either.  but, if the 
'select all' button is pressed, i need to load the array with defaults for the entire 
size of the Collection.  i am not going to use the Collection, i just want to know how 
big it is so i can create a loop and populate an array.

it is an obscure issue i agree, but i cannot see a reason not to support the 
functionality either.  if you rely on the IteratorUtil class for arbitrary list 
iteration, you need something like this (and actually several other Collection 
methods) to allow arbitrary lists to be as robust as a typical Collection.  it seems 
reasonable to add functionality to a common API even for less common uses.

steve

-----Original Message-----
From: Janek Bogucki [mailto:[EMAIL PROTECTED]
Sent: Friday, March 19, 2004 6:21 PM
To: Jakarta Commons Users List
Subject: Re: [collections] collections size


On Fri, 2004-03-19 at 19:26, matthew.hawthorne wrote:
> I understand the underlying idea behind your suggestion, but I don't 
> quite get the use case.  Why create conditional llogic to get the size 
> of an arbitrary list, when you'd then have to implement the same 
> conditional logic to get the items out of the list?
> 
> If your goal is to treat all lists in a similar way, I think you'd be 
> better of doing something like:
> 
> public static Collection toCollection(Object list) {
>    if(list instanceof Collection)
>      return list
>    else if (list instanceof Map)
>      return ((Map)list).entrySet()
>    else
>      return Arrays.asList(list)
> }

While I agree with the idea of using a Collection view of the object
when you want to do Collection things on the object, there is a
precedent for this sort of approach in o.a.c.collections in the form of
CollectionUtils.get(Object, int). This could be used to get the items
out of the 'list' although performance would suffer in some cases.

Edited JavaDoc:

     Returns the index-th value in object.

     Supports:

     Map
     List 
     Object Array 
     Collection 
     Iterator or Enumeration

     public static Object get(Object object, int index)

-Janek

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

  
Learn more about Paymentech's payment processing services at www.paymentech.com
THIS MESSAGE IS CONFIDENTIAL.  This e-mail message and any attachments are proprietary 
and confidential information intended only for the use of the recipient(s) named 
above.  If you are not the intended recipient, you may not print, distribute, or copy 
this message or any attachments.  If you have received this communication in error, 
please notify the sender by return e-mail and delete this message and any attachments 
from your computer.
~2

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to