private void processFeatureStructures()

in uimafit-core/src/main/java/org/apache/uima/fit/component/CasDumpWriter.java [187:241]


  private void processFeatureStructures(CAS aCAS) {
    Set<String> typesToPrint = getTypes(aCAS);
    Iterator<AnnotationFS> annotationIterator = aCAS.getAnnotationIndex().iterator();

    if (sort) {
      List<AnnotationFS> sortedFS = new ArrayList<AnnotationFS>();
      while (annotationIterator.hasNext()) {
        sortedFS.add(annotationIterator.next());
      }

      Collections.sort(sortedFS, new Comparator<AnnotationFS>() {
        @Override
        public int compare(AnnotationFS aO1, AnnotationFS aO2) {
          int begin = aO1.getBegin() - aO2.getBegin();
          if (begin != 0) {
            return begin;
          }

          int end = aO2.getEnd() - aO1.getEnd();
          if (end != 0) {
            return end;
          }

          int name = aO1.getType().getName().compareTo(aO2.getType().getName());
          if (name != 0) {
            return name;
          }

          // Last resort: try the address.
          if (aO1 instanceof FeatureStructureImpl && aO2 instanceof FeatureStructureImpl) {
            return ((FeatureStructureImpl) aO1).getAddress()
                    - ((FeatureStructureImpl) aO2).getAddress();
          }

          // Fall back to name.
          return name;
        }
      });

      annotationIterator = sortedFS.iterator();
    }

    while (annotationIterator.hasNext()) {
      AnnotationFS annotation = annotationIterator.next();
      if (!typesToPrint.contains(annotation.getType().getName())) {
        continue;
      }
      try {
        out.println("[" + annotation.getCoveredText() + "]");
      } catch (IndexOutOfBoundsException e) {
        out.println("<OFFSETS OUT OF BOUNDS>");
      }
      processFeatureStructure(annotation);
    }
  }