2 * Copyright (c) 2003-2005 The BISON Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package peersim.vector;
21 import peersim.core.*;
22 import peersim.util.*;
25 * This class computes and reports statistics information about a vector.
26 * Provided statistics include average, max, min, variance,
27 * etc. Values are printed according to the string format of {@link
28 * IncrementalStats#toString}.
32 public class VectorObserver extends VectControl {
35 /** The name of this observer in the configuration */
36 private final String prefix;
39 //--------------------------------------------------------------------------
41 //--------------------------------------------------------------------------
44 * Standard constructor that reads the configuration parameters.
45 * Invoked by the simulation engine.
46 * @param prefix the configuration prefix for this class
48 public VectorObserver(String prefix) {
54 //--------------------------------------------------------------------------
56 //--------------------------------------------------------------------------
59 * Prints statistics information about a vector.
60 * Provided statistics include average, max, min, variance,
61 * etc. Values are printed according to the string format of {@link
62 * IncrementalStats#toString}.
63 * @return always false
65 public boolean execute() {
67 IncrementalStats stats = new IncrementalStats();
69 for (int j = 0; j < Network.size(); j++)
71 Number v = getter.get(j);
72 stats.add( v.doubleValue() );
75 System.out.println(prefix+": "+stats);