commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (COLLECTIONS-359) A ∩ B != B ∩ A when duplicates are present in a list
Date Sun, 18 Jul 2010 07:44:49 GMT

     [ https://issues.apache.org/jira/browse/COLLECTIONS-359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell closed COLLECTIONS-359.
-------------------------------------

    Fix Version/s: 4.0-beta-1
       Resolution: Fixed

Thanks Mark. Patch applied.

svn ci -m "Applying Mark Shead's patch to COLLECTIONS-359. The intersection method was not
handling duplicates correctly. "
Sending        src/java/org/apache/commons/collections/ListUtils.java
Sending        src/test/org/apache/commons/collections/TestListUtils.java
Transmitting file data ..
Committed revision 965173.


> A  ∩ B  !=  B  ∩ A when duplicates are present in a list
> --------------------------------------------------------
>
>                 Key: COLLECTIONS-359
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-359
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Collection
>    Affects Versions: 3.2
>            Reporter: Mark Shead
>             Fix For: 4.0-beta-1
>
>         Attachments: COLLECTIONS-359.patch
>
>
> When duplicates are present in a list, ListUtils.intersection doesn't behave as expected.
The intersection of two lists should give the same result regardless of which list comes first.
ListUtils.intersection(A,B) should equal ListUtils.intersection(B,A).  This is not the case
when the list contains duplicates.
> Right now:
>  [a, b]  ∩  [a, a, b, b] =  [a, a, b, b]
> and
>  [a, a, b, b]  ∩  [a, b] =  [a, b]
> Expected behavior:
>  [a, a, b, b]  ∩  [a, b] =  [a, b]
>  [a, b]  ∩  [a, a, b, b] =  [a, b]
> Code demonstrating the problem.
> 		List A = new ArrayList();
> 		List B = new ArrayList();
> 		A.add("a");
> 		A.add("b");
> 		B.add("a");
> 		B.add("a");
> 		B.add("b");
> 		B.add("b");
> 		System.out.println("List A: " + A);
> 		System.out.println("List B: " + B);
> 		System.out.println("A ∩ B = " + ListUtils.intersection(A,B));
> 		System.out.println("B ∩ A = " +ListUtils.intersection(B,A));
> output:
> List A: [a, b]
> List B: [a, a, b, b]
> A ∩ B = [a, a, b, b]
> B ∩ A = [a, b]

-- 
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