01: /*
02: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.tools.jstat;
27:
28: import java.util.*;
29: import sun.jvmstat.monitor.*;
30:
31: /**
32: * A class for formatting raw counter output.
33: *
34: * @author Brian Doherty
35: * @version 1.8, 05/05/07
36: * @since 1.5
37: */
38: public class RawOutputFormatter implements OutputFormatter {
39: private List logged;
40: private String header;
41: private boolean printStrings;
42:
43: public RawOutputFormatter(List logged, boolean printStrings) {
44: this .logged = logged;
45: this .printStrings = printStrings;
46: }
47:
48: public String getHeader() throws MonitorException {
49: if (header == null) {
50: // build the header string and prune out any unwanted monitors
51: StringBuilder headerBuilder = new StringBuilder();
52: for (Iterator i = logged.iterator(); i.hasNext(); /* empty */) {
53: Monitor m = (Monitor) i.next();
54: headerBuilder.append(m.getName() + " ");
55: }
56: header = headerBuilder.toString();
57: }
58: return header;
59: }
60:
61: public String getRow() throws MonitorException {
62: StringBuilder row = new StringBuilder();
63: int count = 0;
64: for (Iterator i = logged.iterator(); i.hasNext(); /* empty */) {
65: Monitor m = (Monitor) i.next();
66: if (count++ > 0) {
67: row.append(" ");
68: }
69: if (printStrings && m instanceof StringMonitor) {
70: row.append("\"").append(m.getValue()).append("\"");
71: } else {
72: row.append(m.getValue());
73: }
74: }
75: return row.toString();
76: }
77: }
|