jdk/src/share/classes/sun/tools/jstat/ColumnFormat.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jstat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A class to represent the format for a column of data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author Brian Doherty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class ColumnFormat extends OptionFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private int number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private Alignment align = Alignment.CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private Scale scale = Scale.RAW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private String format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private String header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private Expression expression;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Object previousValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public ColumnFormat(int number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        super("Column" + number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.number = number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * method to apply various validation rules to the ColumnFormat object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public void validate() throws ParserException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // if we allow column spanning, then this method must change. it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // should allow null data statments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (expression == null) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
    60
            // current policy is that a data statement must be specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            throw new ParserException("Missing data statement in column " + number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (header == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            // current policy is that if a header is not specified, then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            // will use the last component of the name as the header and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            // insert the default anchor characters for center alignment..
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            throw new ParserException("Missing header statement in column " + number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            // if no formating is specified, then the format is set to output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            // the raw data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            format="0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void setWidth(int width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void setAlignment(Alignment align) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        this.align = align;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void setScale(Scale scale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        this.scale = scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void setFormat(String format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        this.format = format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void setHeader(String header) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this.header = header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public String getHeader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return header;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public Alignment getAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return align;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public Scale getScale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public Expression getExpression() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return expression;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void setExpression(Expression e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.expression = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void setPreviousValue(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.previousValue = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Object getPreviousValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return previousValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public void printFormat(int indentLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        String indentAmount = "  ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        StringBuilder indent = new StringBuilder("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        for (int j = 0; j < indentLevel; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            indent.append(indentAmount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        System.out.println(indent + name + " {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        System.out.println(indent + indentAmount + "name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                + ";data=" + expression.toString() + ";header=" + header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                + ";format=" + format + ";width=" + width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                + ";scale=" + scale.toString() + ";align=" + align.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        for (Iterator i = children.iterator();  i.hasNext(); /* empty */) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            OptionFormat of = (OptionFormat)i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            of.printFormat(indentLevel+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        System.out.println(indent + "}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public String getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}