// Assignment 4 - Pipe-and-Filter KWIC Indexing.
// Concurrent Programming, CS 498-598
// Summer 2002
//
// This code is unmaintained and may be obsolete (as well as being incorrect).
// See the answer to assignment 4 for possible updates.


class
OutputFilter 
extends FilterRunnableTemplate {

  protected void
  end_loop() {

    // The output filter does nothing on termination.

    }


  protected boolean
  isMisbehavingObject(Object o) {
    KWICIndexEntryGroup kie = (KWICIndexEntryGroup) o;
    return 
      (kie.count() == 1) && (kie.get(0).toString().compareTo("output") == 0);
    }


  protected boolean
  isValidObject(Object o) {

    // The output filter expects to a receive KWIC index entry group from the
    // upstream (sort) filter.

    return o instanceof KWICIndexEntryGroup;
    }


  protected void
  misbehave() {
    throw new RuntimeException();
    }


  protected void
  output_object(Object o) {
    KWICIndexEntryGroup ieg = (KWICIndexEntryGroup) o;
    for (int i = 0; i < ieg.count(); i++)
      System.out.println(ieg.get(i));
    }


  OutputFilter(String fn, buffer ib) {
    super(fn, ib, null);
    }


  protected void
  process_input(Object o) {

    // The only thing the output filter does with the input is output
    // it (it's nice when things work out like that, isn't it?).

    output_object(o);
    }
  }


syntax highlighted by Code2HTML, v. 0.9