Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/jstat/ColumnFormat.java
38918 views
/*1* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jstat;2627import java.util.*;2829/**30* A class to represent the format for a column of data.31*32* @author Brian Doherty33* @since 1.534*/35public class ColumnFormat extends OptionFormat {36private int number;37private int width;38private Alignment align = Alignment.CENTER;39private Scale scale = Scale.RAW;40private String format;41private String header;42private Expression expression;43private Object previousValue;4445public ColumnFormat(int number) {46super("Column" + number);47this.number = number;48}4950/*51* method to apply various validation rules to the ColumnFormat object.52*/53public void validate() throws ParserException {5455// if we allow column spanning, then this method must change. it56// should allow null data statments5758if (expression == null) {59// current policy is that a data statement must be specified60throw new ParserException("Missing data statement in column " + number);61}62if (header == null) {63// current policy is that if a header is not specified, then we64// will use the last component of the name as the header and65// insert the default anchor characters for center alignment..66throw new ParserException("Missing header statement in column " + number);67}68if (format == null) {69// if no formating is specified, then the format is set to output70// the raw data.71format="0";72}73}7475public void setWidth(int width) {76this.width = width;77}7879public void setAlignment(Alignment align) {80this.align = align;81}8283public void setScale(Scale scale) {84this.scale = scale;85}8687public void setFormat(String format) {88this.format = format;89}9091public void setHeader(String header) {92this.header = header;93}9495public String getHeader() {96return header;97}9899public String getFormat() {100return format;101}102103public int getWidth() {104return width;105}106107public Alignment getAlignment() {108return align;109}110111public Scale getScale() {112return scale;113}114115public Expression getExpression() {116return expression;117}118119public void setExpression(Expression e) {120this.expression = e;121}122123public void setPreviousValue(Object o) {124this.previousValue = o;125}126127public Object getPreviousValue() {128return previousValue;129}130131public void printFormat(int indentLevel) {132String indentAmount = " ";133134StringBuilder indent = new StringBuilder("");135for (int j = 0; j < indentLevel; j++) {136indent.append(indentAmount);137}138139System.out.println(indent + name + " {");140System.out.println(indent + indentAmount + "name=" + name141+ ";data=" + expression.toString() + ";header=" + header142+ ";format=" + format + ";width=" + width143+ ";scale=" + scale.toString() + ";align=" + align.toString());144145for (Iterator i = children.iterator(); i.hasNext(); /* empty */) {146OptionFormat of = (OptionFormat)i.next();147of.printFormat(indentLevel+1);148}149150System.out.println(indent + "}");151}152153public String getValue() {154return null;155}156}157158159