1
+ /*******************************************************************************
2
+ * Copyright (c) 2017 Massimiliano Ziccardi
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
1
16
package it .jnrpe .yaclp ;
2
17
3
18
import java .util .ArrayList ;
4
19
import java .util .List ;
5
20
6
21
/**
7
- * Created by ziccardi on 11/01/2017.
22
+ * Builder for mutually exclusive options
8
23
*/
9
24
public class MutuallyExclusiveOptionBuilder {
10
25
private List <IOption > options = new ArrayList <IOption >();
@@ -14,21 +29,40 @@ public class MutuallyExclusiveOptionBuilder {
14
29
MutuallyExclusiveOptionBuilder () {
15
30
}
16
31
32
+ /**
33
+ * Call this method many time to add all the options than can't be specified together.
34
+ * @param option the option
35
+ * @return the builder
36
+ */
17
37
public MutuallyExclusiveOptionBuilder withOption (final IOption option ) {
18
38
this .options .add (option );
19
39
return this ;
20
40
}
21
41
42
+ /**
43
+ * If mandatory, one of the option MUST be present in the command line
44
+ * @param mandatory whether the option is mandatory or not
45
+ * @return the builder
46
+ */
22
47
public MutuallyExclusiveOptionBuilder mandatory (boolean mandatory ) {
23
48
this .mandatory = mandatory ;
24
49
return this ;
25
50
}
26
51
52
+ /**
53
+ * Description for this mutually exlusive option group.
54
+ * @param description the description
55
+ * @return the builder
56
+ */
27
57
public MutuallyExclusiveOptionBuilder description (final String description ) {
28
58
this .description = description ;
29
59
return this ;
30
60
}
31
61
62
+ /**
63
+ * Builds the option as configured.
64
+ * @return the newly build option
65
+ */
32
66
public IOption build () {
33
67
MutuallyExclusiveOptions opt = new MutuallyExclusiveOptions (options .toArray (new IOption [options .size ()]));
34
68
opt .setMandatory (mandatory );
0 commit comments