I guess Thilo is pointing out the second screwup:

        while (it.hasNext()) {
            a = (Annotation) it.get();
            it.moveToNext();

should be

        while (it.hasNext()) {
            a = (Annotation) it.next();

Eddie

On Feb 6, 2008 3:52 AM, Thilo Goetz <[EMAIL PROTECTED]> wrote:

> Eddie Epstein wrote:
> ...
> > Some code below.
> >
> >         FSIterator it = jcas.getAnnotationIndex().iterator();
> >         FSTypeConstraint constraint = cas.getConstraintFactory
> > ().createTypeConstraint();
> >         constraint.add((new Person(jcas)).getType());
> >         constraint.add((new Organization(jcas)).getType());
> >         constraint.add((new Company(jcas)).getType());
> >         it = jcas.createFilteredIterator(it, constraint);
> >
> >         it.moveToFirst();
> >         Annotation a = null;
> >         int pB = -1;
> >         int pE = -1;
> >         LinkedList<Annotation> toDel = new LinkedList<Annotation>();
> >         while (it.hasNext()) {
> >             a = (Annotation) it.get();
> >             it.moveToNext();
> >             if (a instanceof Person) {
> >                 // grab position for testing subsequent FS
> >                 pB = a.getBegin();
> >                 pE = a.getEnd();
> >             }
> >             else {
> >                 // not a Person; see if it has same position as the last
> > Person
> >                 if (pB == a.getBegin() && pE == a.getEnd()) {
> >                     toDel.add(a);
> >                 }
> >             }
> >         }
> >
> >         // must modify index outside iterator loop
> >         for (int i = 0; i < toDel.size(); i++) {
> >             toDel.get(i).removeFromIndexes();
> >         }
> >
> >
> > Regards,
> > Eddie
> >
>
> This has nothing to do with the problem at hand, but let me quote from
> our javadocs:
>
> > public interface FSIterator
> > extends Iterator
> >
> > Iterator over feature structures.
> >
> > This iterator interface extends java.util.Iterator, and supports the
> standard hasNext and next methods. If finer control, including reverse
> iteration, is needed, see below.
> >
> > Note: do not use the APIs described below *together* with the standard
> Java iterator methods next() and hasNext(). On any given iterator, use
> either the one or the other, but not both together. Otherwise, next/hasNext
> may exhibit incorrect behavior.
> >
>
> This is not an idle warning.  Mixing the iterator paradigms *will*
> result in unexpected and incorrect behavior.
>
> --Thilo
>
>
>

Reply via email to