[utilities COMMIT] in /java-support/trunk/src: main/java/net/shibboleth/utilities/java/support/collection/LazyList.ja...

noreply at shibboleth.net noreply at shibboleth.net
Tue Mar 27 23:22:50 BST 2012


Author: putmanb
Date: Tue Mar 27 23:22:49 2012
New Revision: 262

URL: http://svn.shibboleth.net/view/utilities?rev=262&view=rev
Log:
Lazy collections iterators should work properly when the collection has only 1 member.
Need to convert the delegate to a full impl type when returning an iterator, or something
that can be iterated (Map entry/key/values sets).  Otherwise the iterator remove() op fails
when size is 1, b/c underlying SingletonSet/List/Map doesn't support removal.

Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyList.java
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyMap.java
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazySet.java
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTest.java
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/MapTest.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyList.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyList.java?rev=262&r1=261&r2=262&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyList.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyList.java Tue Mar 27 23:22:49 2012
@@ -102,6 +102,7 @@
 
     /** {@inheritDoc} */
     public Iterator<ElementType> iterator() {
+        delegate = buildList();
         return delegate.iterator();
     }
 
@@ -112,11 +113,13 @@
 
     /** {@inheritDoc} */
     public ListIterator<ElementType> listIterator() {
+        delegate = buildList();
         return delegate.listIterator();
     }
 
     /** {@inheritDoc} */
     public ListIterator<ElementType> listIterator(final int index) {
+        delegate = buildList();
         return delegate.listIterator(index);
     }
 

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyMap.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyMap.java?rev=262&r1=261&r2=262&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyMap.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazyMap.java Tue Mar 27 23:22:49 2012
@@ -58,6 +58,7 @@
 
     /** {@inheritDoc} */
     public Set<Entry<KeyType, ValueType>> entrySet() {
+        delegate = buildMap();
         return delegate.entrySet();
     }
 
@@ -73,6 +74,7 @@
 
     /** {@inheritDoc} */
     public Set<KeyType> keySet() {
+        delegate = buildMap();
         return delegate.keySet();
     }
 
@@ -106,6 +108,7 @@
 
     /** {@inheritDoc} */
     public Collection<ValueType> values() {
+        delegate = buildMap();
         return delegate.values();
     }
 

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazySet.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazySet.java?rev=262&r1=261&r2=262&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazySet.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/LazySet.java Tue Mar 27 23:22:49 2012
@@ -79,6 +79,7 @@
 
     /** {@inheritDoc} */
     public Iterator<ElementType> iterator() {
+        delegate = createImplementation();
         return delegate.iterator();
     }
 

Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTest.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTest.java?rev=262&r1=261&r2=262&view=diff
==============================================================================
--- java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTest.java (original)
+++ java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTest.java Tue Mar 27 23:22:49 2012
@@ -150,6 +150,15 @@
         } catch (IllegalStateException e) {
             // TODO: handle exception
         }
+        
+        testCollection.clear();
+        // Test that can remove from collection via the iterator if only has a single member
+        testCollection.add(STRING_1);
+        iterator = testCollection.iterator();
+        Assert.assertTrue(iterator.hasNext(), "Should have a first element");
+        iterator.next();

[... 57 lines stripped ...]


More information about the commits mailing list