ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1664380 - /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/ListIterable.java
Date Thu, 05 Mar 2015 15:39:26 GMT
Author: tmill
Date: Thu Mar  5 15:39:25 2015
New Revision: 1664380

URL: http://svn.apache.org/r1664380
Log:
Convenience class for iterating over UIMA lists.

Added:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/ListIterable.java

Added: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/ListIterable.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/ListIterable.java?rev=1664380&view=auto
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/ListIterable.java (added)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/ListIterable.java Thu
Mar  5 15:39:25 2015
@@ -0,0 +1,42 @@
+package org.apache.ctakes.core.util;
+
+import java.util.Iterator;
+
+import org.apache.uima.jcas.cas.FSList;
+import org.apache.uima.jcas.cas.NonEmptyFSList;
+
+public class ListIterable<T> implements Iterable<T> {
+
+  FSListIterator<T> iter = null;
+  
+  public ListIterable(FSList list){
+    iter = new FSListIterator<>(list);
+  }
+  
+  public Iterator<T> iterator() {
+    return iter;
+  }
+
+  
+}
+
+class FSListIterator<T> implements Iterator<T> {
+  FSList list;
+  public FSListIterator(FSList list){
+    this.list = list;
+  }
+  
+  public boolean hasNext() {
+    return (list instanceof NonEmptyFSList);
+  }
+  
+  public T next() {
+    T element = (T) ((NonEmptyFSList)list).getHead();
+    list = ((NonEmptyFSList)list).getTail();
+    return element;
+  }
+  
+  public void remove() {
+    // don't do anything
+  }
+}



Mime
View raw message