1 /* Reattore HTTP Server
2
3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 $Id: BaseStat.java,v 1.4 2003/03/03 05:14:39 michaelh Exp $
20 */
21 package juju.reattore.util;
22
23 import java.text.MessageFormat;
24
25 /*** Base implementation of a statistic module.
26 */
27 public abstract class BaseStat implements Stat {
28 private String fmt;
29 private String name;
30
31 /*** Create a new statistic for the given class and leaf name.
32
33 @param clazz The class name, used as the stat base name.
34 @param leaf The name of the stat within this class.
35 */
36 public BaseStat(Class clazz, String leaf) {
37 this.name = clazz.getName() + "." + leaf;
38 this.fmt = getDefaultFormat();
39
40 StatRegistry.register(this);
41 }
42
43 /*** Returns the default format string to use.
44
45 @return The default format string.
46 */
47 protected abstract String getDefaultFormat();
48
49 /*** Returns the argument list used in formatting the summary.
50
51 @return A list of objects for MessageFormat.
52 */
53 protected abstract Object[] getFormatArgs();
54
55 /*** Returns the fully qualified name of this stat.
56
57 @return The fqn.
58 */
59 public String getName() {
60 return name;
61 }
62
63 /*** Sets the format used in summarising this stat.
64
65 @param fmt The format in MessageFormat style.
66 */
67 public void setFormat(String fmt) {
68 this.fmt = fmt;
69 }
70
71 /*** Summarise this statistic as a string.
72
73 @return This stat summarised according to #setFormat.
74 */
75 public String format() {
76 return MessageFormat.format(fmt, getFormatArgs());
77 }
78 }
This page was automatically generated by Maven