/** * 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(); }
/** * 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; }
/** * Returns the observations made for the given cell, so far. * * @return long : The observations made for the given cell. * @param cell int : The cell of which want to get the number of observations made for. */ public TimeSpan getObservationsInCell(int cell) { TimeSpan out = TimeSpan.ZERO; if (cell < 0 || cell > this.getCells() + 1) { // cell 0: underflow, cell this.getCells() + 1: overflow sendWarning( "Attempt to get the number of observations from a not " + "known cell. Zero (0) will be returned!", "Histogram: " + this.getName() + " Method: getObservationsInCell" + "( int cell ).", "The passed int: cell in this method is negative or greater than " + "the largest cell number.", "Make sure to ask for the number of observations only for valid " + "cell numbers."); return out; // return zero (0) } out = _table[cell]; // reflect the period since the last update if (this.nextToLastValue != null) { int n = this.findCellIndex(this.nextToLastValue); if (cell == n) { TimeSpan delta = TimeOperations.diff(this.presentTime(), this.nextToLastTime); out = TimeOperations.add(_table[cell], delta); } } return out; }