uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marshall Schor <...@schor.com>
Subject generics: createFilteredIterator
Date Fri, 07 Aug 2009 18:32:38 GMT
The createFilteredIterator method in CASImpl takes an FSIterator and an
FSMatchConstraint, and returns another iterator.

The generification of this is:
  public<T extends FeatureStructure> FSIterator<T>
createFilteredIterator(FSIterator<T> it, FSMatchConstraint cons) {
    return new FilteredIterator<T>(it, cons);}

This means that the type of the objects being returned will be the same
as the type of the objects of the iterator passed in.

If the effect of the filtering is to filter the first iterator down to a
subset of the types of the original, this cannot be represented with
this signature.

An alternate generification might be as follows, with type T being the
type the input iterator gives out, and U being the type the filtered
iterator produces:

  public<T extends FeatureStructure, U extends T> FSIterator<U>
createFilteredIterator(FSIterator<T> it, FSMatchConstraint cons) {
    return new FilteredIterator<T, U>(it, cons);}

with the corresponding changes to the class FilteredIterator, and the
CAS interface (to match this new signature).

With these changes, users can write code:
  public static void t3(CAS aCas, FSIterator<FeatureStructure> it,
FSMatchConstraint cons) {
    FSIterator<Subtype> s = aCas.createFilteredIterator(it, cons);

Without these changes, users would be forced to have the filtered
iterator's generic type always equal to the original type.

Is this something we should change (given that we only get one chance to
do our generification)?

-Marshall (looking forward to increasing his understanding of generics... )

View raw message