Path: blob/master/src/jdk.jcmd/share/classes/sun/tools/jstat/OptionFormat.java
41159 views
/*1* Copyright (c) 2004, 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.*;28import sun.jvmstat.monitor.MonitorException;2930/**31* A class for describing the output format specified by a command32* line option that was parsed from an option description file.33*34* @author Brian Doherty35* @since 1.536*/37public class OptionFormat {38protected String name;39protected List<OptionFormat> children;4041public OptionFormat(String name) {42this.name = name;43this.children = new ArrayList<OptionFormat>();44}4546public boolean equals(Object o) {47if (o == this) {48return true;49}50if (!(o instanceof OptionFormat)) {51return false;52}53OptionFormat of = (OptionFormat)o;54return (this.name.compareTo(of.name) == 0);55}5657public int hashCode() {58return name.hashCode();59}6061public void addSubFormat(OptionFormat f) {62children.add(f);63}6465public OptionFormat getSubFormat(int index) {66return children.get(index);67}6869public void insertSubFormat(int index, OptionFormat f) {70children.add(index, f);71}7273public String getName() {74return name;75}7677public void apply(Closure c) throws MonitorException {7879for (Iterator<OptionFormat> i = children.iterator(); i.hasNext(); /* empty */) {80OptionFormat o = i.next();81c.visit(o, i.hasNext());82}8384for (Iterator <OptionFormat>i = children.iterator(); i.hasNext(); /* empty */) {85OptionFormat o = i.next();86o.apply(c);87}88}8990public void printFormat() {91printFormat(0);92}9394public void printFormat(int indentLevel) {95String indentAmount = " ";96StringBuilder indent = new StringBuilder("");9798for (int j = 0; j < indentLevel; j++) {99indent.append(indentAmount);100}101System.out.println(indent + name + " {");102103// iterate over all children and call their printFormat() methods104for (OptionFormat of : children) {105of.printFormat(indentLevel+1);106}107System.out.println(indent + "}");108}109}110111112