コード例 #1
0
  /**
   * Implementation of the virtual <code>update(Observable, Object)</code> method of the <code>
   * Observer</code> interface. This method will be called automatically from an <code>Observable
   * </code> object within its <code>notifyObservers()</code> method. <br>
   * If no Object (a<code>null</code> value) is passed as arg, the actual value of the ValueSupplier
   * will be fetched with the <code>value()</code> method of the ValueSupplier. Otherwise it is
   * expected that the actual value is passed in the Object arg.
   *
   * @param o java.util.Observable : The Observable calling this method within its own <code>
   *     notifyObservers()</code> method.
   * @param arg Object : The Object with which this <code>TallyRunning</code> is updated. Normally a
   *     double number which is added to the statistics or <code>null</code>.
   */
  public void update(Observable o, Object arg) {
    if (o == null) // null was passed instead of an Observable
    {
      sendWarning(
          "Attempt to update a TallyRunning with no reference to an "
              + "Observable. The actual value of '"
              + getValueSupplier().getName()
              + "' will be fetched and processed anyway.",
          "TallyRunning: " + this.getName() + " Method: update (Observable " + "o, Object arg)",
          "The passed Observable: o in this method is only a null pointer.",
          "The update()-method was not called via notifyObservers() from an "
              + "Observable. Who was calling it? Why don't you let the Observable do"
              + " the work?");
    }

    super.update(o, arg); // call the update() method of Tally

    long obs = getObservations();
    double lastVal = getLastValue();
    int index = (int) ((obs - 1) % this._n);

    this._sumLastN += lastVal - this._valuesLastN[index];
    this._sumSquareLastN += lastVal * lastVal - this._valuesLastN[index] * this._valuesLastN[index];
    // note: in case obs < n, this.valuesLastN[index] will be zero

    this._valuesLastN[index] = lastVal;
  }
コード例 #2
0
  /**
   * Updates this <code>TallyRunning</code> object by fetching the actual value of the <code>
   * ValueSupplier</code> and processing it. The <code>ValueSupplier</code> is passed in the
   * constructor of this <code>TallyRunning</code> object. This <code>update()</code> method
   * complies with the one described in DESMO, see [Page91].
   */
  public void update() {
    super.update(); // call the update() method of Tally

    long obs = getObservations();
    double lastVal = getLastValue();
    int index = (int) ((obs - 1) % this._n);

    this._sumLastN += lastVal - this._valuesLastN[index];
    this._sumSquareLastN += lastVal * lastVal - this._valuesLastN[index] * this._valuesLastN[index];
    // note: in case obs < n, this.valuesLastN[index] will be zero

    this._valuesLastN[index] = lastVal;
  }
コード例 #3
0
  /** Resets this TallyRunning object by resetting all variables to 0.0 . */
  public void reset() {
    super.reset(); // reset the Tally, too.

    this._sumLastN = this._sumSquareLastN = 0.0;
  }