1 /*
2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
24 */
25
26 package sun.tools.jstat;
27
28 import java.util.*;
29
30 /**
31 * A class to represent the format for a column of data.
32 *
33 * @author Brian Doherty
34 * @since 1.5
35 */
36 public class ColumnFormat extends OptionFormat {
37 private int number;
38 private int width;
39 private Alignment align = Alignment.CENTER;
40 private Scale scale = Scale.RAW;
41 private String format;
42 private String header;
43 private Expression expression;
44 private Object previousValue;
45
46 public ColumnFormat(int number) {
47 super("Column" + number);
48 this.number = number;
49 }
50
51 /*
52 * method to apply various validation rules to the ColumnFormat object.
53 */
54 public void validate() throws ParserException {
55
56 // if we allow column spanning, then this method must change. it
57 // should allow null data statments
58
59 if (expression == null) {
60 // current policy is that a data statement must be specified
61 throw new ParserException("Missing data statement in column " + number);
62 }
63 if (header == null) {
64 // current policy is that if a header is not specified, then we
65 // will use the last component of the name as the header and
66 // insert the default anchor characters for center alignment..
67 throw new ParserException("Missing header statement in column " + number);
68 }
69 if (format == null) {
70 // if no formating is specified, then the format is set to output
71 // the raw data.
72 format="0";
73 }
74 }
75
76 public void setWidth(int width) {
77 this.width = width;
78 }
79
80 public void setAlignment(Alignment align) {
81 this.align = align;
82 }
83
84 public void setScale(Scale scale) {
85 this.scale = scale;
86 }
87
88 public void setFormat(String format) {
89 this.format = format;
90 }
91
92 public void setHeader(String header) {
93 this.header = header;
104 public int getWidth() {
105 return width;
106 }
107
108 public Alignment getAlignment() {
109 return align;
110 }
111
112 public Scale getScale() {
113 return scale;
114 }
115
116 public Expression getExpression() {
117 return expression;
118 }
119
120 public void setExpression(Expression e) {
121 this.expression = e;
122 }
123
124 public void setPreviousValue(Object o) {
125 this.previousValue = o;
126 }
127
128 public Object getPreviousValue() {
129 return previousValue;
130 }
131
132 public void printFormat(int indentLevel) {
133 String indentAmount = " ";
134
135 StringBuilder indent = new StringBuilder("");
136 for (int j = 0; j < indentLevel; j++) {
137 indent.append(indentAmount);
138 }
139
140 System.out.println(indent + name + " {");
141 System.out.println(indent + indentAmount + "name=" + name
142 + ";data=" + expression.toString() + ";header=" + header
143 + ";format=" + format + ";width=" + width
144 + ";scale=" + scale.toString() + ";align=" + align.toString());
145
146 for (Iterator<OptionFormat> i = children.iterator(); i.hasNext(); /* empty */) {
147 OptionFormat of = i.next();
148 of.printFormat(indentLevel+1);
149 }
150
151 System.out.println(indent + "}");
152 }
153
154 public String getValue() {
155 return null;
156 }
157 }
|
1 /*
2 * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
24 */
25
26 package sun.tools.jstat;
27
28 import java.util.*;
29
30 /**
31 * A class to represent the format for a column of data.
32 *
33 * @author Brian Doherty
34 * @since 1.5
35 */
36 public class ColumnFormat extends OptionFormat {
37 private int number;
38 private int width;
39 private Alignment align = Alignment.CENTER;
40 private Scale scale = Scale.RAW;
41 private String format;
42 private String header;
43 private Expression expression;
44 private boolean required = false;
45 private Object previousValue;
46
47 public ColumnFormat(int number) {
48 super("Column" + number);
49 this.number = number;
50 }
51
52 /*
53 * method to apply various validation rules to the ColumnFormat object.
54 */
55 public void validate() throws ParserException {
56
57 // if we allow column spanning, then this method must change. it
58 // should allow null data statments
59
60 if (expression == null) {
61 // current policy is that a data statement must be specified
62 throw new ParserException("Missing data statement in column " + number);
63 }
64 if (header == null) {
65 // current policy is that if a header is not specified, then we
66 // will use the last component of the name as the header and
67 // insert the default anchor characters for center alignment..
68 throw new ParserException("Missing header statement in column " + number);
69 }
70 if (format == null) {
71 // if no formating is specified, then the format is set to output
72 // the raw data.
73 format="0";
74 }
75
76 // Adjust required flag
77 expression.setRequired(required);
78 }
79
80 public void setWidth(int width) {
81 this.width = width;
82 }
83
84 public void setAlignment(Alignment align) {
85 this.align = align;
86 }
87
88 public void setScale(Scale scale) {
89 this.scale = scale;
90 }
91
92 public void setFormat(String format) {
93 this.format = format;
94 }
95
96 public void setHeader(String header) {
97 this.header = header;
108 public int getWidth() {
109 return width;
110 }
111
112 public Alignment getAlignment() {
113 return align;
114 }
115
116 public Scale getScale() {
117 return scale;
118 }
119
120 public Expression getExpression() {
121 return expression;
122 }
123
124 public void setExpression(Expression e) {
125 this.expression = e;
126 }
127
128 public void setRequired(boolean r) {
129 this.required = r;
130 }
131
132 public boolean isRequired() {
133 return this.required;
134 }
135
136 public void setPreviousValue(Object o) {
137 this.previousValue = o;
138 }
139
140 public Object getPreviousValue() {
141 return previousValue;
142 }
143
144 public void printFormat(int indentLevel) {
145 String indentAmount = " ";
146
147 StringBuilder indent = new StringBuilder("");
148 for (int j = 0; j < indentLevel; j++) {
149 indent.append(indentAmount);
150 }
151
152 System.out.println(indent + name + " {");
153 System.out.println(indent + indentAmount + "name=" + name
154 + ";data=" + expression.toString() + ";header=" + header
155 + ";format=" + format + ";width=" + width
156 + ";scale=" + scale.toString() + ";align=" + align.toString()
157 + ";required=" + required);
158
159 for (Iterator<OptionFormat> i = children.iterator(); i.hasNext(); /* empty */) {
160 OptionFormat of = i.next();
161 of.printFormat(indentLevel+1);
162 }
163
164 System.out.println(indent + "}");
165 }
166
167 public String getValue() {
168 return null;
169 }
170 }
|