SimpleMeasurementConsumer.java

biz/hammurapi/metrics/SimpleMeasurementConsumer.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 073 [java.lang.StringBuffer] In Java 5 use StringBuilder instead of StringBuffer if access is single-threaded, e.g. StringBuffer is used as a local variable . 2 69:17
Java Inspector 089 Constructor is not properly documented 2 43:9
Java Inspector 089 Parameter keepMeasurements is not documented 2 43:9
Java Inspector 089 Constructor is not properly documented 2 51:9
Java Inspector 089 Undocumented method 2 55:9
Java Inspector 089 Undocumented method 2 64:9
Java Inspector 089 Undocumented method 2 68:9
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 75:36

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.metrics;
24
25import java.util.Collections;
26import java.util.HashMap;
27import java.util.Iterator;
28import java.util.LinkedList;
29import java.util.Map;
30
31/**
32 * Collects metrics in in-memory collection
33 * @author Pavel Vlasov
34 * @version $Revision: 1.2 $
35 */
36public class SimpleMeasurementConsumer implements MeasurementConsumer, MetricSource {
37 private Map metrics=new HashMap();
38 private boolean keepMeasurements;
39
40 /**
41 * @param keepMeasurements
42 */
43 public SimpleMeasurementConsumer(boolean keepMeasurements) {
44 super();
45 this.keepMeasurements = keepMeasurements;
46 }
47
48 /**
49 *
50 */
51 public SimpleMeasurementConsumer() {
52 super();
53 }
54
55 public synchronized void addMeasurement(String name, double value, long time) {
56 Metric metric=(Metric) metrics.get(name);
57 if (metric==null) {
58 metric=new SimpleMetric(name, keepMeasurements);
59 metrics.put(name, metric);
60 }
61 metric.add(value, time);
62 }
63
64 public Map getMetrics() {
65 return metrics;
66 }
67
68 public String toString() {
69 StringBuffer ret=new StringBuffer();
70 LinkedList list = new LinkedList(metrics.values());
71 Collections.sort(list);
72 Iterator it=list.iterator();
73 while (it.hasNext()) {
74 ret.append(it.next());
75 ret.append("\n");
76 }
77 return ret.toString();
78 }
79}
80