Author: tn
Date: Sat Apr 27 11:57:01 2013
New Revision: 1476557
URL: http://svn.apache.org/r1476557
Log:
[COLLECTIONS-310] SetUniqueList#subList now returns an unmodifiable list.
Modified:
commons/proper/collections/trunk/src/changes/changes.xml
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1476557&r1=1476556&r2=1476557&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Sat Apr 27
11:57:01 2013
@@ -276,6 +276,10 @@
Use of final keyword where applicable, minor performance improvements by
properly
initializing the capacity of newly created collections when known in
advance.
</action>
+ <action issue="COLLECTIONS-307" dev="tn" type="update" due-to="Christian
Semrau, Thomas Vahrst">
+ "SetUniqueList#subList()" will now return an unmodifiable list as
changes to it
+ may invalidate the parent list.
+ </action>
<action issue="COLLECTIONS-307" dev="bayard" type="fix" due-to="Christian
Semrau">
"SetUniqueList#subList()#contains(Object)" will now correctly check the
subList
rather than the parent list.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java?rev=1476557&r1=1476556&r2=1476557&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
(original)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
Sat Apr 27 11:57:01 2013
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Set;
+import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.set.UnmodifiableSet;
import org.apache.commons.collections4.iterators.AbstractIteratorDecorator;
import org.apache.commons.collections4.iterators.AbstractListIteratorDecorator;
@@ -319,11 +320,17 @@ public class SetUniqueList<E> extends Ab
return new SetListListIterator<E>(super.listIterator(index), set);
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * NOTE: from 4.0, an unmodifiable list will be returned, as changes to the
+ * subList can invalidate the parent list.
+ */
@Override
public List<E> subList(final int fromIndex, final int toIndex) {
final List<E> superSubList = super.subList(fromIndex, toIndex);
final Set<E> subSet = createSetBasedOnList(set, superSubList);
- return new SetUniqueList<E>(superSubList, subSet);
+ return ListUtils.unmodifiableList(new SetUniqueList<E>(superSubList,
subSet));
}
/**
Modified:
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java?rev=1476557&r1=1476556&r2=1476557&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
(original)
+++
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
Sat Apr 27 11:57:01 2013
@@ -43,6 +43,7 @@ public class SetUniqueListTest<E> extend
return new SetUniqueList<E>(new ArrayList<E>(), new HashSet<E>());
}
+ //-----------------------------------------------------------------------
@Override
public void testListIteratorSet() {
// override to block
@@ -461,6 +462,16 @@ public class SetUniqueListTest<E> extend
assertEquals(4, decoratedList.size());
}
+ public void testSubListIsUnmodifiable() {
+ resetFull();
+ List<E> subList = getCollection().subList(1, 3);
+ try {
+ subList.remove(0);
+ fail("subList should be unmodifiable");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
@SuppressWarnings("unchecked")
public void testCollections307() {
List<E> list = new ArrayList<E>();