commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julius Davies (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-296) Introduce SortedUtils.merge() for merging sorted collections
Date Tue, 20 May 2008 05:00:55 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-296?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12598173#action_12598173
] 

Julius Davies commented on COLLECTIONS-296:
-------------------------------------------

Thanks very much for the feedback!  I worry that consumer won't properly initialize Collection
"res" to the right capacity (a.size() + b.size()).  Also, if the consumer wants to put the
elements in a different collection, they can always use Collection.addAll() with the ArrayList
that's returned.

Here are some more methods I'm thinking of adding:

<code>
boolean isSorted(Collection coll);
boolean isSorted(Collection coll, Comparator c);

int binarySearch(List l, Object o);
int binarySearch(List l, Object o, Comparator c);
</code>

There's another reason I like returning ArrayList:  it can be easily fed into the binarySearch()
method I'm thinking of adding.  LinkedList *can* be fed into binarySearch, but it's a bad
idea!


> Introduce SortedUtils.merge() for merging sorted collections
> ------------------------------------------------------------
>
>                 Key: COLLECTIONS-296
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-296
>             Project: Commons Collections
>          Issue Type: New Feature
>          Components: Core
>            Reporter: Julius Davies
>            Priority: Minor
>         Attachments: SortedUtils.patch
>
>
> Is there any interest in this?
>     /**
>      * Returns a new ArrayList where sorted Collection a and sorted Collection b
>      * are combined such that ordering of the elements according to
>      * Comparator c is retained.  Uses the standard O(n) merge algorithm
>      * for combining two sorted lists.
>      *
>      * @param a Object to combine with sorted Collection b.  Must implement Comparable.
>      * @param b Sorted Collection to combine with Object a.
>      * @param c Comparator by which Collection a and Collection b have been sorted, or
null
>      *          if the Collections are sorted according to their natural ordering.
>      * @return a new sorted ArrayList
>      */
>     public static ArrayList merge(Collection a, Collection b, Comparator c);

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message