/**
   * 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>Tally</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 Histogram with no reference to an "
              + "Observable. The actual value of '"
              + getValueSupplier().getName()
              + "' will be fetched and processed anyway.",
          "Histogram: " + 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); // update Accumulate

    if (this.nextToLastValue != null) {
      int n = this.findCellIndex(this.nextToLastValue);
      TimeSpan delta = TimeOperations.diff(this.presentTime(), this.nextToLastTime);
      _table[n] = TimeOperations.add(_table[n], delta);
    }
    this.nextToLastTime = this.presentTime();
    this.nextToLastValue = this.getLastValue();
  }
  /**
   * Resets this Histogram object by resetting the counters for each cell to zero. That means the
   * array of the cell counters will be reset, but the interval and the number of sections this
   * interval is divided into will remain the same. The parameters of the interval can be changed
   * with the <code>changeParameters</code> method after the reset.
   */
  public void reset() {
    super.reset(); // reset the Tally, too.

    // reset the array of cells #### only if the table already exists! Ruth 24/01/2008
    if (_table != null) {
      initTable();
    }
  }
  /**
   * Updates this <code>Histogram</code> object with the double value given as parameter. In some
   * cases it might be more convenient to pass the value this <code>Histogram</code> will be updated
   * with directly within the <code>update(double val)</code> method instead of going via the <code>
   * ValueSupplier</code>.
   *
   * @param val double : The value with which this <code>Histogram</code> will be updated.
   */
  public void update(double value) {
    super.update(value); // update Accumulate

    if (this.nextToLastValue != null) {
      int n = this.findCellIndex(this.nextToLastValue);
      TimeSpan delta = TimeOperations.diff(this.presentTime(), this.nextToLastTime);
      _table[n] = TimeOperations.add(_table[n], delta);
    }
    this.nextToLastTime = this.presentTime();
    this.nextToLastValue = value;
  }