commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Melzer, Steven" <Steven.Mel...@Paymentech.com>
Subject RE: [collections] collections size
Date Wed, 24 Mar 2004 15:32:50 GMT
done.  i added a bugzilla entry with the patch for CollectionUtils and TestCollectionUtils.
 i am new to this, what happens next? 

btw - i didn't understand your comment "simply casting to Collection would
give you an iterator...".  take a look at the code for size(Object) and let me know if i am
missing something.

thanks,
steve

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
Sent: Tuesday, March 23, 2004 5:51 PM
To: Jakarta Commons Users List
Subject: Re: [collections] collections size


Although I can't quite see the use case (simply casting to Collection would
give you an iterator...), adding a size(Object) method to CollectionUtils is
not unreasonable. To achieve this I would need a patch with unit tests
attached to a bugzilla entry ;-)

Stephen

----- Original Message -----
From: "Melzer, Steven" <Steven.Melzer@paymentech.com>
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:yan@studylink.com]
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

  
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message