[utilities COMMIT] in /java-support/trunk/src: main/java/net/shibboleth/utilities/java/support/collection/Transformed...
noreply at shibboleth.net
noreply at shibboleth.net
Thu Jan 19 13:56:28 GMT 2012
Author: rdw
Date: Thu Jan 19 13:56:27 2012
New Revision: 212
URL: http://svn.shibboleth.net/view/utilities?rev=212&view=rev
Log:
Test for TransformedInputList. features more Reorganization of the test directory and addition of our own ListIterator
Added:
java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/TransformedInputListTest.java (with props)
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/TransformedInputList.java
java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTestSupport.java
java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/LazyListTest.java
java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ListTestSupport.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/TransformedInputList.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/TransformedInputList.java?rev=212&r1=211&r2=212&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/TransformedInputList.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/TransformedInputList.java Thu Jan 19 13:56:27 2012
@@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.List;
+import java.util.ListIterator;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -29,6 +30,7 @@
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ForwardingList;
+import com.google.common.collect.ForwardingListIterator;
//TODO(lajoie) think about Java serialization, can we mark this as serializable? what happens if the function/delegate aren't?
@@ -99,6 +101,17 @@
return null;
}
+
+ /** {@inheritDoc} */
+ public ListIterator<E> listIterator() {
+ return standardListIterator();
+ }
+
+ /** {@inheritDoc} */
+ public ListIterator<E> listIterator(int index) {
+ return new DelegatingListIterator(index);
+ }
+
/** {@inheritDoc} */
public List<E> subList(int fromIndex, int toIndex) {
@@ -120,4 +133,50 @@
protected void addToDelegate(@Nullable E element) {
delegate.add(element);
}
+
+ /**
+ * We need to implement a list iterator to override add and set.
+ */
+ protected class DelegatingListIterator extends ForwardingListIterator<E> {
+
+
+ /**
+ * The delegated ListIterator.
+ */
+ private final ListIterator<E> innerDelegate;
+
+ /**
+ * Constructor.
+ *
+ * @param index where in the outer class to start the iterator.
+ */
+ protected DelegatingListIterator(int index) {
+ innerDelegate = delegate.listIterator(index);
+ }
+
+ /** {@inheritDoc} */
+ protected ListIterator<E> delegate() {
+ return innerDelegate;
+ }
+
+ @Override
+ public void add(E element) {
+ Optional<? extends E> processedElement = transform.apply(element);
+
+ if (processedElement.isPresent()) {
+ delegate().add(processedElement.get());
+ }
+ }
+
+ @Override
+ public void set(E element) {
+ Optional<? extends E> processedElement = transform.apply(element);
+
+ if (processedElement.isPresent()) {
+ delegate().set(element);
+ }
+ }
+
+
+ }
}
Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTestSupport.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTestSupport.java?rev=212&r1=211&r2=212&view=diff
==============================================================================
--- java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTestSupport.java (original)
+++ java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/CollectionTestSupport.java Thu Jan 19 13:56:27 2012
@@ -17,6 +17,7 @@
package net.shibboleth.utilities.java.support.collection;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -24,6 +25,7 @@
import net.shibboleth.utilities.java.support.logic.TransformAndCheckFunction;
import org.testng.Assert;
+import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Functions;
@@ -34,7 +36,7 @@
* Helper class for testing {@link TransformedInputList} and {@link TransformedInputSet}
*
*/
-public class CollectionTestSupport<E> {
+public class CollectionTestSupport {
[... 254 lines stripped ...]
More information about the commits
mailing list