Author: xor
Date: 2008-10-29 15:45:12 +0000 (Wed, 29 Oct 2008)
New Revision: 23171
Modified:
trunk/freenet/src/freenet/support/DoublyLinkedList.java
trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java
Log:
Implement Iterable<T>
Modified: trunk/freenet/src/freenet/support/DoublyLinkedList.java
===================================================================
--- trunk/freenet/src/freenet/support/DoublyLinkedList.java 2008-10-29
14:18:43 UTC (rev 23170)
+++ trunk/freenet/src/freenet/support/DoublyLinkedList.java 2008-10-29
15:45:12 UTC (rev 23171)
@@ -6,7 +6,7 @@
* Framework for managing a doubly linked list.
* @author tavin
*/
-public interface DoublyLinkedList<T> {
+public interface DoublyLinkedList<T> extends Iterable<T> {
public abstract DoublyLinkedList<T> clone();
/**
Modified: trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java
===================================================================
--- trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java 2008-10-29
14:18:43 UTC (rev 23170)
+++ trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java 2008-10-29
15:45:12 UTC (rev 23171)
@@ -1,6 +1,7 @@
package freenet.support;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.NoSuchElementException;
/**
@@ -420,4 +421,26 @@
return old;
}
}
+
+ public Iterator<T> iterator() {
+ return new Iterator<T>() {
+ private Enumeration<T> e = forwardElements();
+
+ public boolean hasNext() {
+ return e.hasMoreElements();
+ }
+
+ public T next() {
+ if(!hasNext())
+ throw new NoSuchElementException();
+
+ return e.nextElement();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ }
}
\ No newline at end of file