org/objectweb/proactive/benchmarks/timit/util/EventStatistics.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.benchmarks.timit.util;
00032 
00033 import java.io.Serializable;
00034 import org.objectweb.proactive.benchmarks.timit.TimIt;
00035 import org.objectweb.proactive.benchmarks.timit.util.observing.EventDataBag;
00036 
00043 public class EventStatistics implements Serializable {
00047     private static final long serialVersionUID = 3762604865283613499L;
00048 
00049     private String[] counterName;
00050 
00051     private Object[] value;
00052 
00053     private EventDataBag statDataBag;
00054 
00055     private int nb;
00056 
00057     private int padding;
00058 
00059     private boolean empty;
00060 
00061     public EventStatistics() {
00062         this(new String[1], new Object[1], 0, null);
00063         this.empty = true;
00064     }
00065 
00066     public EventStatistics(String[] counterName, Object[] value, int nb,
00067             EventDataBag statDataBag) {
00068         this.counterName = counterName.clone();
00069         this.value = value.clone();
00070         this.statDataBag = statDataBag;
00071         this.nb = nb;
00072         this.empty = false;
00073     }
00074 
00075     public Object getEventValue(int i) {
00076         return this.value[i];
00077     }
00078 
00079     public Object getEventValue(String name) { // returns an EventData
00080         for (int i = 0; i < this.counterName.length; i++) {
00081             if (name.equals(this.counterName[i])) {
00082                 return this.value[i];
00083             }
00084         }
00085         return null;
00086     }
00087 
00088     public Object getEventDataValue(String name) {
00089         for (int i = 0; i < this.counterName.length; i++) {
00090             if (name.equals(this.counterName[i])) {
00091                 return this.statDataBag.getEventData(i).getFinalized();
00092             }
00093         }
00094         return null;
00095     }
00096 
00097     public String getFormValue(int i) {
00098         return TimIt.df.format(this.value[i]);
00099     }
00100 
00101     public String getName(int i) {
00102         return this.counterName[i];
00103     }
00104 
00105     public EventDataBag getStatDataBag() {
00106         return this.statDataBag;
00107     }
00108 
00109     public int getNb() {
00110         return this.nb;
00111     }
00112 
00113     public void setTimerName(int id, String name) {
00114         this.counterName[id] = name;
00115     }
00116 
00117     public String toString() {
00118         if (!this.empty) {
00119             return this.show();
00120         }
00121         return "";
00122     }
00123 
00124     public String show() {
00125         String result = "";
00126 
00127         for (int i = 0; i < this.nb; i++) {
00128             result += this.counterName[i] + " : " + this.value[i] + "\n";
00129         }
00130 
00131         return result;
00132     }
00133 
00134     public final String format(double t) {
00135         return this.paddingString(TimIt.df.format(t), this.padding,
00136                 ' ', true)
00137                 + "    ";
00138     }
00139 
00144     private String paddingString(String s, int n, char c, boolean paddingLeft) {
00145         StringBuffer str = new StringBuffer(s);
00146         int strLength = str.length();
00147         if (n > 0 && n > strLength) {
00148             for (int i = 0; i <= n; i++) {
00149                 if (paddingLeft) {
00150                     if (i < n - strLength) {
00151                         str.insert(0, c);
00152                     }
00153                 } else {
00154                     if (i > strLength) {
00155                         str.append(c);
00156                     }
00157                 }
00158             }
00159         }
00160         return str.toString();
00161     }
00162 }

Generated on Mon Jan 22 15:16:04 2007 for ProActive by  doxygen 1.5.1