DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4790>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4790 org.apache.avalon.excalibur.collections.ListUtils union method adds duplicate objects Summary: org.apache.avalon.excalibur.collections.ListUtils union method adds duplicate objects Product: Avalon Version: 4.0b3 Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Normal Priority: Other Component: Excalibur AssignedTo: [email protected] ReportedBy: [EMAIL PROTECTED] I found a bug in org.apache.avalon.excalibur.collections.ListUtils in the union method (CVS $Revision: 1.2 $ $Date: 2001/08/07 10:57:04): public static List union( final List list1, final List list2 ) { final ArrayList result = new ArrayList( list1 ); result.addAll( list2 ); return result; } addAll( list2 ) is adding all objects of list2 into the result without checking if any of these is already in the result. If list1 and list2 have common objects, then result will have these common objects duplicated. The following code fixes this: public static List union( final List list1, final List list2 ) { final ArrayList result = new ArrayList(list1); final Iterator iterator = list2.iterator(); while( iterator.hasNext() ) { final Object o = iterator.next(); if ( !result.contains( o ) ) { result.add( o ); } } return result; } I'm using version 4.0. Bill -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
