jdk/src/jdk.management/share/classes/com/sun/management/internal/DiagnosticCommandArgumentInfo.java
changeset 30355 e37c7eba132f
parent 25859 3317bb8137f4
equal deleted inserted replaced
30354:ca83b4cae363 30355:e37c7eba132f
       
     1 /*
       
     2  * Copyright (c) 2013, 2015, 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
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.management.internal;
       
    27 
       
    28 /**
       
    29  * Diagnostic Command Argument information. It contains the description
       
    30  * of one parameter of the diagnostic command. A parameter can either be an
       
    31  * option or an argument. Options are identified by the option name while
       
    32  * arguments are identified by their position in the command line. The generic
       
    33  * syntax of a diagnostic command is:
       
    34  *  <blockquote>
       
    35  *    &lt;command name&gt; [&lt;option&gt;=&lt;value&gt;] [&lt;argument_value&gt;]
       
    36  * </blockquote>
       
    37  * Example:
       
    38  * <blockquote>
       
    39  * command_name option1=value1 option2=value argumentA argumentB argumentC
       
    40  * </blockquote>
       
    41  * In this command line, the diagnostic command receives five parameters, two
       
    42  * options named {@code option1} and {@code option2}, and three arguments.
       
    43  * argumentA's position is 0, argumentB's position is 1 and argumentC's
       
    44  * position is 2.
       
    45  *
       
    46  * @since 1.8
       
    47  */
       
    48 
       
    49 class DiagnosticCommandArgumentInfo {
       
    50     private final String name;
       
    51     private final String description;
       
    52     private final String type;
       
    53     private final String defaultValue;
       
    54     private final boolean mandatory;
       
    55     private final boolean option;
       
    56     private final boolean multiple;
       
    57     private final int position;
       
    58 
       
    59     /**
       
    60      * Returns the argument name.
       
    61      *
       
    62      * @return the argument name
       
    63      */
       
    64     String getName() {
       
    65         return name;
       
    66     }
       
    67 
       
    68    /**
       
    69      * Returns the argument description.
       
    70      *
       
    71      * @return the argument description
       
    72      */
       
    73     String getDescription() {
       
    74         return description;
       
    75     }
       
    76 
       
    77     /**
       
    78      * Returns the argument type.
       
    79      *
       
    80      * @return the argument type
       
    81      */
       
    82     String getType() {
       
    83         return type;
       
    84     }
       
    85 
       
    86     /**
       
    87      * Returns the default value as a String if a default value
       
    88      * is defined, null otherwise.
       
    89      *
       
    90      * @return the default value as a String if a default value
       
    91      * is defined, null otherwise.
       
    92      */
       
    93     String getDefault() {
       
    94         return defaultValue;
       
    95     }
       
    96 
       
    97     /**
       
    98      * Returns {@code true} if the argument is mandatory,
       
    99      *         {@code false} otherwise.
       
   100      *
       
   101      * @return {@code true} if the argument is mandatory,
       
   102      *         {@code false} otherwise
       
   103      */
       
   104     boolean isMandatory() {
       
   105         return mandatory;
       
   106     }
       
   107 
       
   108     /**
       
   109      * Returns {@code true} if the argument is an option,
       
   110      *         {@code false} otherwise. Options have to be specified using the
       
   111      *         &lt;key&gt;=&lt;value&gt; syntax on the command line, while other
       
   112      *         arguments are specified with a single &lt;value&gt; field and are
       
   113      *         identified by their position on command line.
       
   114      *
       
   115      * @return {@code true} if the argument is an option,
       
   116      *         {@code false} otherwise
       
   117      */
       
   118     boolean isOption() {
       
   119         return option;
       
   120     }
       
   121 
       
   122     /**
       
   123      * Returns {@code true} if the argument can be specified multiple times,
       
   124      *         {@code false} otherwise.
       
   125      *
       
   126      * @return {@code true} if the argument can be specified multiple times,
       
   127      *         {@code false} otherwise
       
   128      */
       
   129     boolean isMultiple() {
       
   130         return multiple;
       
   131     }
       
   132 
       
   133     /**
       
   134      * Returns the expected position of this argument if it is not an option,
       
   135      *         -1 otherwise. Argument position if defined from left to right,
       
   136      *         starting at zero and ignoring the diagnostic command name and
       
   137      *         options.
       
   138      *
       
   139      * @return the expected position of this argument if it is not an option,
       
   140      *         -1 otherwise.
       
   141      */
       
   142     int getPosition() {
       
   143         return position;
       
   144     }
       
   145 
       
   146     DiagnosticCommandArgumentInfo(String name, String description,
       
   147                                          String type, String defaultValue,
       
   148                                          boolean mandatory, boolean option,
       
   149                                          boolean multiple, int position) {
       
   150         this.name = name;
       
   151         this.description = description;
       
   152         this.type = type;
       
   153         this.defaultValue = defaultValue;
       
   154         this.mandatory = mandatory;
       
   155         this.option = option;
       
   156         this.multiple = multiple;
       
   157         this.position = position;
       
   158     }
       
   159 }