[COLLECTIONS-524] ListOrderedSet.listOrderedSet(List) did not remove duplicates from the input list. Thanks to J Goodfellow.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1592910 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
320c0acf89
commit
527213decc
|
@ -22,6 +22,10 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="4.1" date="TBD" description="">
|
<release version="4.1" date="TBD" description="">
|
||||||
|
<action issue="COLLECTIONS-524" dev="tn" type="fix" due-to="J Goodfellow">
|
||||||
|
"ListOrderedSet#listOrderedSet(List)" did not remove duplicates from the
|
||||||
|
input list as advertised in the javadoc.
|
||||||
|
</action>
|
||||||
<action issue="COLLECTIONS-521" dev="tn" type="fix" due-to="Maxime Nay">
|
<action issue="COLLECTIONS-521" dev="tn" type="fix" due-to="Maxime Nay">
|
||||||
"MultiKeyMap" was throwing a "NullPointerException" for various operations
|
"MultiKeyMap" was throwing a "NullPointerException" for various operations
|
||||||
if two key arguments have been used and the second was "null".
|
if two key arguments have been used and the second was "null".
|
||||||
|
|
|
@ -24,7 +24,9 @@ import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.collections4.OrderedIterator;
|
import org.apache.commons.collections4.OrderedIterator;
|
||||||
|
import org.apache.commons.collections4.functors.UniquePredicate;
|
||||||
import org.apache.commons.collections4.iterators.AbstractIteratorDecorator;
|
import org.apache.commons.collections4.iterators.AbstractIteratorDecorator;
|
||||||
import org.apache.commons.collections4.list.UnmodifiableList;
|
import org.apache.commons.collections4.list.UnmodifiableList;
|
||||||
|
|
||||||
|
@ -60,8 +62,7 @@ public class ListOrderedSet<E>
|
||||||
private final List<E> setOrder;
|
private final List<E> setOrder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method to create an ordered set specifying the list and set to
|
* Factory method to create an ordered set specifying the list and set to use.
|
||||||
* use.
|
|
||||||
* <p>
|
* <p>
|
||||||
* The list and set must both be empty.
|
* The list and set must both be empty.
|
||||||
*
|
*
|
||||||
|
@ -102,8 +103,7 @@ public class ListOrderedSet<E>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method to create an ordered set using the supplied list to retain
|
* Factory method to create an ordered set using the supplied list to retain order.
|
||||||
* order.
|
|
||||||
* <p>
|
* <p>
|
||||||
* A <code>HashSet</code> is used for the set behaviour.
|
* A <code>HashSet</code> is used for the set behaviour.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -120,8 +120,8 @@ public class ListOrderedSet<E>
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
throw new IllegalArgumentException("List must not be null");
|
throw new IllegalArgumentException("List must not be null");
|
||||||
}
|
}
|
||||||
|
CollectionUtils.filter(list, UniquePredicate.uniquePredicate());
|
||||||
final Set<E> set = new HashSet<E>(list);
|
final Set<E> set = new HashSet<E>(list);
|
||||||
list.retainAll(set);
|
|
||||||
|
|
||||||
return new ListOrderedSet<E>(set, list);
|
return new ListOrderedSet<E>(set, list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.IteratorUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link AbstractSetTest} for exercising the
|
* Extension of {@link AbstractSetTest} for exercising the
|
||||||
* {@link ListOrderedSet} implementation.
|
* {@link ListOrderedSet} implementation.
|
||||||
|
@ -227,6 +229,25 @@ public class ListOrderedSetTest<E>
|
||||||
assertTrue(stop - start < 5000);
|
assertTrue(stop - start < 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testDuplicates() {
|
||||||
|
final List<E> list = new ArrayList<E>(10);
|
||||||
|
list.add((E) Integer.valueOf(1));
|
||||||
|
list.add((E) Integer.valueOf(2));
|
||||||
|
list.add((E) Integer.valueOf(3));
|
||||||
|
list.add((E) Integer.valueOf(1));
|
||||||
|
|
||||||
|
final ListOrderedSet<E> orderedSet = ListOrderedSet.listOrderedSet(list);
|
||||||
|
|
||||||
|
assertEquals(3, orderedSet.size());
|
||||||
|
assertEquals(3, IteratorUtils.toArray(orderedSet.iterator()).length);
|
||||||
|
|
||||||
|
// insertion order preserved?
|
||||||
|
assertEquals(Integer.valueOf(1), orderedSet.get(0));
|
||||||
|
assertEquals(Integer.valueOf(2), orderedSet.get(1));
|
||||||
|
assertEquals(Integer.valueOf(3), orderedSet.get(2));
|
||||||
|
}
|
||||||
|
|
||||||
static class A {
|
static class A {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue