DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31444>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31444

New CollectionUtils feature and tests: chooseRandomElement from collection

           Summary: New CollectionUtils feature and tests:
                    chooseRandomElement from collection
           Product: Commons
           Version: unspecified
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Collections
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I find myself needing to do this every so often, but there's no Java collections or 
Commons Collections 
functionality. CollectionUtils seemed like a good place for something like this to 
rest. I will attach the 
Java source for CollectionUtils.java from CVS around 6:30pm PDT complete with the new 
functions 
(there are two, plus a new static data member). Also, I will attach the source for 
TestCollectionUtils.java 
which includes tests for this new functionality. The new code is at the end of each 
class.

The function takes any collection, but is smart enough to use List's get() method if 
the collection is a 
list, resulting in constant time (or at least, much faster) behavior on classes which 
implement 
RandomAccess. Otherwise, the function simply picks a random index and linearly 
iterates to it, 
resulting in linear time complexity.

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

Reply via email to