avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 4790] New: - org.apache.avalon.excalibur.collections.ListUtils union method adds duplicate objects
Date Sun, 11 Nov 2001 02:52:24 GMT
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: avalon-dev@jakarta.apache.org
        ReportedBy: bill@kelemen-usa.com


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


Mime
View raw message