Author: tn Date: Tue Jun 19 19:20:16 2012 New Revision: 1351804 URL: http://svn.apache.org/viewvc?rev=1351804&view=rev Log: [COLLECTIONS-408] improve performance of remove and removeAll methods, add missing javadoc. Thanks to Adrian Nistor for reporting.
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java?rev=1351804&r1=1351803&r2=1351804&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java Tue Jun 19 19:20:16 2012 @@ -67,7 +67,9 @@ public class SetUniqueList<E> extends Ab * If the list contains duplicates, these are removed (first indexed one kept). * A <code>HashSet</code> is used for the set behaviour. * - * @param list the list to decorate, must not be null + * @param <E> the element type + * @param list the list to decorate, must not be null + * @return a new {@link SetUniqueList} * @throws IllegalArgumentException if list is null */ public static <E> SetUniqueList<E> setUniqueList(List<E> list) { @@ -236,8 +238,10 @@ public class SetUniqueList<E> extends Ab @Override public boolean remove(Object object) { - boolean result = super.remove(object); - set.remove(object); + boolean result = set.remove(object); + if (result) { + super.remove(object); + } return result; } @@ -250,8 +254,10 @@ public class SetUniqueList<E> extends Ab @Override public boolean removeAll(Collection<?> coll) { - boolean result = super.removeAll(coll); - set.removeAll(coll); + boolean result = false; + for (Iterator<?> it = coll.iterator(); it.hasNext();) { + result |= remove(it.next()); + } return result; } @@ -300,6 +306,14 @@ public class SetUniqueList<E> extends Ab return new SetUniqueList<E>(superSubList, subSet); } + /** + * Create a new {@link Set} with the same type as the provided {@code set} + * and populate it with all elements of {@code list}. + * + * @param set the {@link Set} to be used as return type, must not be null + * @param list the {@link List} to populate the {@link Set} + * @return a new {@link Set} populated with all elements of the provided {@link List} + */ @SuppressWarnings("unchecked") protected Set<E> createSetBasedOnList(Set<E> set, List<E> list) { Set<E> subSet;