/**
   * Reads next line and notifies susbscribed observers.
   *
   * @return true if more lines would be available, false if there was no possible to read the line,
   *     since the EOF has been reached.
   */
  public boolean next() {
    if (this.isClosed) return false;
    if (this.nomore) return false;
    try {
      final boolean unpoll[] = new boolean[symbols.length];
      long minTime = nextMilliseconds[0];
      for (int i = 1; i < symbols.length; i++) {
        if (nextMilliseconds[i] > minTime) unpoll[i] = true;
        else if (nextMilliseconds[i] < minTime) {
          minTime = nextMilliseconds[i];
          for (int j = 0; j < i; j++) unpoll[j] = true;
        }
      }

      boolean somethingToReturn = false;
      final ParseResult compossedResult = new ParseResult();
      for (int i = 0; i < symbols.length; i++) {
        if (unpoll[i] || this.nextLine[i] == null) {
          // Nothing to send to listeners.
        } else {
          somethingToReturn = true;
          final ParseResult localResult = this.lineParser.parse(this.nextLine[i]);
          // Move to next valid line.
          String line = partReader[i].readLine();
          while (line != null && !this.lineParser.isValid(line)) {
            line = partReader[i].readLine();
          }
          if (line != null) {
            if (!symbols[i].equals(localResult.getSymbol(0))) {
              this.nextLine[i] = null;
            } else {
              this.nextLine[i] = line;
              this.nextMilliseconds[i] = this.lineParser.getUTCTimestamp(line).getTimeInMillis();
            }
          } else {
            this.nextLine[i] = null;
          }
          compossedResult.merge(localResult);
        }
      }
      if (somethingToReturn) {
        for (int i = 0; i < this.spreadTradesMgr.length; i++) {
          this.spreadTradesMgr[i].accumulate(compossedResult);
        }
      } else {
        this.nomore = true;
        for (int i = 0; i < this.spreadTradesMgr.length; i++) {
          this.spreadTradesMgr[i].endAccumulation();
        }
      }
      return somethingToReturn;
    } catch (Exception e) {
      log.log(Level.SEVERE, "Exception dealing with file '" + filePath + "'", e);
      return false;
    }
  }
Пример #2
0
  /** Gets given data into this object. */
  public void merge(final ParseResult other) {
    if (this.calendars.size() == 0) {
      this.calendars.add((Calendar) other.getLocalTimestamp(0).clone());
    }
    if (!other.getUTCTimestampCopy().equals(this.getUTCTimestampCopy())) {
      throw new IllegalArgumentException(
          "Cannot merge result data in "
              //            System.out.println("Cannot merge result data in "
              + "different times ("
              + other.getUTCTimestampCopy()
              + " is not as expected "
              + this.getUTCTimestampCopy()
              + ")\n"
              + "Original result is related to "
              + this.symbols
              + " and "
              + "unexpected result is related to "
              + other.symbols);
    }

    for (Map.Entry<String, Map<Field, Double>> symbolVals : other.values.entrySet()) {
      boolean symbolFound = false;
      for (int i = 0; i < this.symbols.size(); i++) {
        if (this.symbols.get(i).equals(symbolVals.getKey())) {
          symbolFound = true;
          break;
        }
      }
      if (!symbolFound) {
        final String s = symbolVals.getKey();
        this.addSymbol(s);
        for (int i = 0; i < this.symbols.size(); i++) {
          if (this.symbols.get(i).equals(s)) {
            final Calendar c = (Calendar) other.getLocalTimestamp(s).clone();
            final long millis = c.getTimeInMillis();
            c.setTimeZone(other.getLocalTimestamp(s).getTimeZone());
            c.setTimeInMillis(millis);
            if (this.calendars.size() <= i) this.newTimestamp(i);
            this.calendars.set(i, c);
            break;
          }
        }
      }

      for (Map.Entry<Field, Double> fieldValue : symbolVals.getValue().entrySet()) {
        this.putValue(symbolVals.getKey(), fieldValue.getKey(), fieldValue.getValue());
      }
    }
  }