google-code-export / uimafit

Automatically exported from code.google.com/p/uimafit
2 stars 1 forks source link

Iteration over FSArray and FSList #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Moved here from multi-issue 58 - Reported by project member steven.bethard:

I think we should have methods for iterating over FSArrays. Something like:

  public static <T extends FeatureStructure> Iterator<T> iterator(
      final FSArray fsArray,
      final Class<T> type) {
    return new Iterator<T>() {
      private int index = 0;
      public boolean hasNext() {
        return this.index < fsArray.size();
      }
      public T next() {
        T next = type.cast(fsArray.get(this.index));
        this.index += 1;
        return next;
      }
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }

  public static <T extends FeatureStructure> Iterable<T> iterate(
      final FSArray fsArray,
      final Class<T> type) {
    return new Iterable<T>() {
      public Iterator<T> iterator() {
        return JCasUtil.iterator(fsArray, type);
      }
    };
  }

Original issue reported on code.google.com by richard.eckart on 16 Mar 2011 at 8:19

GoogleCodeExporter commented 9 years ago
Added select() methods for ArrayFS and FSList - the latter is only available 
for JCas.

Original comment by richard.eckart on 16 Mar 2011 at 10:13

GoogleCodeExporter commented 9 years ago

Original comment by richard.eckart on 7 Apr 2011 at 12:12