Ejemplo n.º 1
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());
      }
    }
  }
Ejemplo n.º 2
0
  /** Clones result COPYING all data into new variables. */
  public Object clone() {
    final ParseResult cloned = new ParseResult();

    for (int i = 0; i < this.symbols.size(); i++) {
      cloned.symbols.add(this.symbols.get(i));
    }

    for (final Map.Entry<String, Map<Field, Double>> entry1 : this.values.entrySet()) {
      final Map<Field, Double> vals = new HashMap<Field, Double>();
      for (final Map.Entry<Field, Double> entry2 : entry1.getValue().entrySet()) {
        vals.put(entry2.getKey(), entry2.getValue());
      }
      cloned.values.put(entry1.getKey(), vals);
    }

    for (final Calendar c : this.calendars) {
      cloned.calendars.add((Calendar) c.clone());
    }

    return cloned;
  }