1- /**
1+ /*
22 * Copyright 2003-2005 The Apache Software Foundation
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
3434 * A base implementation of Parent providing limited ground work for further
3535 * Parent implementations.
3636 */
37- public abstract class ParentImpl extends OptionImpl implements Parent {
38-
37+ public abstract class ParentImpl
38+ extends OptionImpl implements Parent {
3939 private static final char NUL = '\0' ;
40-
4140 private final Group children ;
42-
4341 private final Argument argument ;
44-
4542 private final String description ;
4643
47- protected ParentImpl (
48- final Argument argument ,
49- final Group children ,
50- final String description ,
51- final int id ,
52- final boolean required ) {
53- super (id ,required );
44+ protected ParentImpl (final Argument argument ,
45+ final Group children ,
46+ final String description ,
47+ final int id ,
48+ final boolean required ) {
49+ super (id , required );
5450 this .children = children ;
5551 this .argument = argument ;
5652 this .description = description ;
5753 }
5854
5955 /*
6056 * (non-Javadoc)
61- *
57+ *
6258 * @see org.apache.commons.cli2.Option#process(org.apache.commons.cli2.CommandLine,
6359 * java.util.ListIterator)
6460 */
65- public void process (
66- final WriteableCommandLine commandLine ,
67- final ListIterator arguments )
61+ public void process (final WriteableCommandLine commandLine ,
62+ final ListIterator arguments )
6863 throws OptionException {
69-
7064 if (argument != null ) {
7165 handleInitialSeparator (arguments , argument .getInitialSeparator ());
7266 }
@@ -77,51 +71,49 @@ public void process(
7771 argument .processValues (commandLine , arguments , this );
7872 }
7973
80- if (children != null && children .canProcess (commandLine , arguments )) {
74+ if (( children != null ) && children .canProcess (commandLine , arguments )) {
8175 children .process (commandLine , arguments );
8276 }
8377 }
8478
8579 /*
8680 * (non-Javadoc)
87- *
81+ *
8882 * @see org.apache.commons.cli2.Option#canProcess(java.lang.String)
8983 */
90- public boolean canProcess (final WriteableCommandLine commandLine , final String arg ) {
91-
84+ public boolean canProcess (final WriteableCommandLine commandLine ,
85+ final String arg ) {
9286 final Set triggers = getTriggers ();
93-
87+
9488 if (argument != null ) {
9589 final char separator = argument .getInitialSeparator ();
96-
90+
9791 // if there is a valid separator character
9892 if (separator != NUL ) {
9993 final int initialIndex = arg .indexOf (separator );
100-
94+
10195 // if there is a separator present
10296 if (initialIndex > 0 ) {
10397 return triggers .contains (arg .substring (0 , initialIndex ));
10498 }
10599 }
106100 }
107-
101+
108102 return triggers .contains (arg );
109103 }
110104
111105 /*
112106 * (non-Javadoc)
113- *
107+ *
114108 * @see org.apache.commons.cli2.Option#prefixes()
115109 */
116110 public Set getPrefixes () {
117- return (children == null )
118- ? Collections .EMPTY_SET
119- : children .getPrefixes ();
111+ return (children == null ) ? Collections .EMPTY_SET : children .getPrefixes ();
120112 }
121113
122114 /*
123115 * (non-Javadoc)
124- *
116+ *
125117 * @see org.apache.commons.cli2.Option#validate(org.apache.commons.cli2.CommandLine)
126118 */
127119 public void validate (WriteableCommandLine commandLine )
@@ -139,21 +131,19 @@ public void validate(WriteableCommandLine commandLine)
139131
140132 /*
141133 * (non-Javadoc)
142- *
134+ *
143135 * @see org.apache.commons.cli2.Option#appendUsage(java.lang.StringBuffer,
144136 * java.util.Set, java.util.Comparator)
145137 */
146- public void appendUsage (
147- final StringBuffer buffer ,
148- final Set helpSettings ,
149- final Comparator comp ) {
150-
138+ public void appendUsage (final StringBuffer buffer ,
139+ final Set helpSettings ,
140+ final Comparator comp ) {
151141 final boolean displayArgument =
152- this .argument != null
153- && helpSettings .contains (DisplaySetting .DISPLAY_PARENT_ARGUMENT );
142+ ( this .argument != null ) &&
143+ helpSettings .contains (DisplaySetting .DISPLAY_PARENT_ARGUMENT );
154144 final boolean displayChildren =
155- this .children != null
156- && helpSettings .contains (DisplaySetting .DISPLAY_PARENT_CHILDREN );
145+ ( this .children != null ) &&
146+ helpSettings .contains (DisplaySetting .DISPLAY_PARENT_CHILDREN );
157147
158148 if (displayArgument ) {
159149 buffer .append (' ' );
@@ -175,24 +165,21 @@ public String getDescription() {
175165
176166 /*
177167 * (non-Javadoc)
178- *
168+ *
179169 * @see org.apache.commons.cli2.Option#helpLines(int, java.util.Set,
180170 * java.util.Comparator)
181171 */
182- public List helpLines (
183- final int depth ,
184- final Set helpSettings ,
185- final Comparator comp ) {
172+ public List helpLines (final int depth ,
173+ final Set helpSettings ,
174+ final Comparator comp ) {
186175 final List helpLines = new ArrayList ();
187176 helpLines .add (new HelpLineImpl (this , depth ));
188177
189- if (helpSettings .contains (DisplaySetting .DISPLAY_PARENT_ARGUMENT )
190- && argument != null ) {
178+ if (helpSettings .contains (DisplaySetting .DISPLAY_PARENT_ARGUMENT ) && (argument != null )) {
191179 helpLines .addAll (argument .helpLines (depth + 1 , helpSettings , comp ));
192180 }
193181
194- if (helpSettings .contains (DisplaySetting .DISPLAY_PARENT_CHILDREN )
195- && children != null ) {
182+ if (helpSettings .contains (DisplaySetting .DISPLAY_PARENT_CHILDREN ) && (children != null )) {
196183 helpLines .addAll (children .helpLines (depth + 1 , helpSettings , comp ));
197184 }
198185
@@ -218,46 +205,45 @@ public Group getChildren() {
218205 * @param arguments the current position in the arguments iterator
219206 * @param separator the separator char to split on
220207 */
221- private void handleInitialSeparator (
222- final ListIterator arguments ,
223- final char separator ) {
224-
208+ private void handleInitialSeparator (final ListIterator arguments ,
209+ final char separator ) {
225210 // next token
226- final String newArgument = (String )arguments .next ();
227-
211+ final String newArgument = (String ) arguments .next ();
212+
228213 // split the token
229214 final int initialIndex = newArgument .indexOf (separator );
230-
215+
231216 if (initialIndex > 0 ) {
232217 arguments .remove ();
233218 arguments .add (newArgument .substring (0 , initialIndex ));
234219 arguments .add (newArgument .substring (initialIndex + 1 ));
235220 arguments .previous ();
236221 }
237- arguments .previous ();
222+
223+ arguments .previous ();
224+ }
225+
226+ /*
227+ * @see org.apache.commons.cli2.Option#findOption(java.lang.String)
228+ */
229+ public Option findOption (final String trigger ) {
230+ final Option found = super .findOption (trigger );
231+
232+ if ((found == null ) && (children != null )) {
233+ return children .findOption (trigger );
234+ } else {
235+ return found ;
236+ }
238237 }
239-
240- /*
241- * @see org.apache.commons.cli2.Option#findOption(java.lang.String)
242- */
243- public Option findOption (final String trigger ) {
244- final Option found = super .findOption (trigger );
245- if (found ==null && children !=null ){
246- return children .findOption (trigger );
247- }
248- else {
249- return found ;
250- }
251- }
252-
238+
253239 public void defaults (final WriteableCommandLine commandLine ) {
254240 super .defaults (commandLine );
255-
256- if (argument != null ) {
257- argument .defaultValues (commandLine ,this );
241+
242+ if (argument != null ) {
243+ argument .defaultValues (commandLine , this );
258244 }
259-
260- if (children != null ) {
245+
246+ if (children != null ) {
261247 children .defaults (commandLine );
262248 }
263249 }
0 commit comments