KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > sendopts > OptionGroups


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.sendopts;
21
22 /** Factory method that composes individual options into groups.
23  * In some situations it is useful and sometimes even necessary to
24  * enforce certain relationships among options provided by some,
25  * potentially different modules. Factory methods defined here in allow such
26  * compositions as they take multiple options and convert them
27  * into one group option.
28  * <p>
29  * The following table gives short overview of the behaviour of different
30  * factory methods. Supposed <b>n</b> individual options were passed as
31  * arguments to each method. The <em>Min</em> and <em>Max</em> shown the
32  * number that is needed for the group option to be "consistent":
33  *
34  * <table border=1>
35  * <theader>
36  * <td>Method</td>
37  * <td>Min</td>
38  * <td>Max</td>
39  * </theader>
40  *
41  * <tr>
42  * <td>{@link OptionGroups#allOf}</td>
43  * <td>n</td>
44  * <td>n</td>
45  * </tr>
46  *
47  * <tr>
48  * <td>{@link OptionGroups#oneOf}</td>
49  * <td>1</td>
50  * <td>1</td>
51  * </tr>
52  *
53  * <tr>
54  * <td>{@link OptionGroups#someOf}</td>
55  * <td>1</td>
56  * <td>n</td>
57  * </tr>
58  *
59  * <tr>
60  * <td>{@link OptionGroups#anyOf}</td>
61  * <td>0</td>
62  * <td>n</td>
63  * </tr>
64  * </table>
65  *
66  * <p>
67  * Please note that the {@link OptionGroups#anyOf} is in fact always consistent,
68  * regardless any number of the given options appears on the command line or not.
69  * As such it serves slightly different purpose than the other methods listed
70  * in the table.
71  * <p>
72  * More detailed description of the behaviour of each method is given in
73  * their appropriate javadoc.
74  *
75  * @author Jaroslav Tulach
76  */

77 public final class OptionGroups {
78     private OptionGroups() {
79     }
80     
81     /** Combines a set of multiple options into one compound one. Useful
82      * for {@link OptionProcessor} that want to process more than one
83      * option and want to do all the logic of choosing which options can
84      * be used together with others by themselves. The newly created
85      * options will be contained in the map passed to
86      * {@link OptionProcessor#process} method if at least one of the
87      * parameters appeared on the command line. The value associated with
88      * the compound option is always going to be <code>new String[0]</code>, however
89      * the map will contain all options that appeared and their values which
90      * can then be processed one by one.
91      *
92      * @param options the sub options to check on the command line
93      * @return compound option that <q>is activated</q> if at least one of the
94      * options appears on the command line
95      */

96     public static Option someOf(Option... options) {
97         return new Option(2, options);
98     }
99     
100     /** A voluntary selector that allows any of the specified options to appear
101      * on the command line, but if they do not appear, the command line is
102      * still consistent. If at least one of the given sub options appears on
103      * the command line, the map passed to
104      * {@link OptionProcessor#process} will contain the returned compound option
105      * with associated value of <code>new String[0]</code>.
106      *
107      * @param options the sub options to check on the command line
108      * @return compound option that <q>is activated</q> if at least one of the
109      * options appears on the command line
110      */

111     public static Option anyOf(Option... options) {
112         return new Option(3, options);
113     }
114
115     /** Creates a selector option that forces exactly one of the sub options
116      * to appear on the command line. If more than
117      * one of the options appears on the command line, then an error is
118      * reported by the infrastructure. If none of the sub options is present
119      * than this selector option is not also present.
120      * If present in the {@link OptionProcessor#process}'s
121      * map, then the selector option is always associated with <code>new String[0]</code>
122      * value, however there is also one of the sub options, with its associated
123      * value.
124      *
125      * @param options the options to select one from
126      * @return the selector option
127      */

128     public static Option oneOf(Option... options) {
129         return new Option(0, options);
130     }
131     
132     /** Creates a compound option that forces all of the sub options
133      * to appear on the command line. If less of them is present, an error
134      * is reported by the infrastructure.
135      * If present in the {@link OptionProcessor#process}'s
136      * map, then the compound option is always associated with <code>new String[0]</code>
137      * value, however there are all the sub options, with their associated
138      * values.
139      *
140      * @param options the options to select one from
141      * @return the selector option
142      */

143     public static Option allOf(Option... options) {
144         return new Option(1, options);
145     }
146 }
147
Popular Tags