Esempio n. 1
0
  @Override
  public String next() throws IOException {

    // restore queue
    for (int i = 0; i < numTop; i++) {
      top[i].current = top[i].fields.next();
      if (top[i].current != null) {
        queue.add(top[i]);
      } else {
        // no more fields in this sub-reader
      }
    }

    numTop = 0;

    // gather equal top fields
    if (queue.size() > 0) {
      while (true) {
        top[numTop++] = queue.pop();
        if (queue.size() == 0 || !(queue.top()).current.equals(top[0].current)) {
          break;
        }
      }
      currentField = top[0].current;
    } else {
      currentField = null;
    }

    return currentField;
  }
Esempio n. 2
0
  /**
   * The subs array must be newly initialized FieldsEnum (ie, {@link FieldsEnum#next} has not been
   * called.
   */
  public MultiFieldsEnum(MultiFields fields, FieldsEnum[] subs, ReaderSlice[] subSlices)
      throws IOException {
    this.fields = fields;
    queue = new FieldMergeQueue(subs.length);
    top = new FieldsEnumWithSlice[subs.length];
    List<FieldsEnumWithSlice> enumWithSlices = new ArrayList<FieldsEnumWithSlice>();

    // Init q
    for (int i = 0; i < subs.length; i++) {
      assert subs[i] != null;
      final String field = subs[i].next();
      if (field != null) {
        // this FieldsEnum has at least one field
        final FieldsEnumWithSlice sub = new FieldsEnumWithSlice(subs[i], subSlices[i], i);
        enumWithSlices.add(sub);
        sub.current = field;
        queue.add(sub);
      }
    }
  }