0N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.tools.jstat;
0N/A
0N/Aimport java.util.*;
0N/Aimport sun.jvmstat.monitor.MonitorException;
0N/A
0N/A/**
0N/A * A class for describing the output format specified by a command
0N/A * line option that was parsed from an option description file.
0N/A *
0N/A * @author Brian Doherty
0N/A * @since 1.5
0N/A */
0N/Apublic class OptionFormat {
0N/A protected String name;
0N/A protected List<OptionFormat> children;
0N/A
0N/A public OptionFormat(String name) {
0N/A this.name = name;
0N/A this.children = new ArrayList<OptionFormat>();
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if (o == this) {
0N/A return true;
0N/A }
0N/A if (!(o instanceof OptionFormat)) {
0N/A return false;
0N/A }
0N/A OptionFormat of = (OptionFormat)o;
0N/A return (this.name.compareTo(of.name) == 0);
0N/A }
0N/A
0N/A public int hashCode() {
0N/A return name.hashCode();
0N/A }
0N/A
0N/A public void addSubFormat(OptionFormat f) {
0N/A children.add(f);
0N/A }
0N/A
0N/A public OptionFormat getSubFormat(int index) {
0N/A return children.get(index);
0N/A }
0N/A
0N/A public void insertSubFormat(int index, OptionFormat f) {
0N/A children.add(index, f);
0N/A }
0N/A
0N/A public String getName() {
0N/A return name;
0N/A }
0N/A
0N/A public void apply(Closure c) throws MonitorException {
0N/A
0N/A for (Iterator i = children.iterator(); i.hasNext(); /* empty */) {
0N/A OptionFormat o = (OptionFormat)i.next();
0N/A c.visit(o, i.hasNext());
0N/A }
0N/A
0N/A for (Iterator i = children.iterator(); i.hasNext(); /* empty */) {
0N/A OptionFormat o = (OptionFormat)i.next();
0N/A o.apply(c);
0N/A }
0N/A }
0N/A
0N/A public void printFormat() {
0N/A printFormat(0);
0N/A }
0N/A
0N/A public void printFormat(int indentLevel) {
0N/A String indentAmount = " ";
0N/A StringBuilder indent = new StringBuilder("");
0N/A
0N/A for (int j = 0; j < indentLevel; j++) {
0N/A indent.append(indentAmount);
0N/A }
0N/A System.out.println(indent + name + " {");
0N/A
0N/A // iterate over all children and call their printFormat() methods
0N/A for (OptionFormat of : children) {
0N/A of.printFormat(indentLevel+1);
0N/A }
0N/A System.out.println(indent + "}");
0N/A }
0N/A}