@@ -95,6 +95,12 @@ public class OptCfg {
9595 */
9696 public final Converter <?> converter ;
9797
98+ /**
99+ * Is the function interface that is executed after parsing command line
100+ * arguments.
101+ */
102+ public final Postparser <?> postparser ;
103+
98104 /**
99105 * Is the constructor that takes the all field values as parameters.
100106 * <p>
@@ -120,8 +126,10 @@ public class OptCfg {
120126 * @param defaults The default value(s).
121127 * @param desc The description of the option.
122128 * @param argInHelp The display of the option argument.
123- * @param converter The converter to convert the option argument string to
124- * the specified type value.
129+ * @param converter The {@link Converter} object to convert the option
130+ * argument string to the specified type value.
131+ * @param postparser The {@link Postparser} object that is executed after
132+ * parsing command line arguments.
125133 */
126134 public <T > OptCfg (
127135 String storeKey ,
@@ -132,7 +140,8 @@ public <T> OptCfg(
132140 List <T > defaults ,
133141 String desc ,
134142 String argInHelp ,
135- Converter <T > converter
143+ Converter <T > converter ,
144+ Postparser <T > postparser
136145 ) {
137146 var init = new Init <T >();
138147 init .storeKey = storeKey ;
@@ -144,6 +153,7 @@ public <T> OptCfg(
144153 init .desc = desc ;
145154 init .argInHelp = argInHelp ;
146155 init .converter = converter ;
156+ init .postparser = postparser ;
147157
148158 fillmissing (init );
149159
@@ -156,6 +166,7 @@ public <T> OptCfg(
156166 this .desc = init .desc ;
157167 this .argInHelp = init .argInHelp ;
158168 this .converter = init .converter ;
169+ this .postparser = init .postparser ;
159170 }
160171
161172 /**
@@ -194,6 +205,7 @@ public <T> OptCfg(NamedParam<T> ...params) {
194205 this .desc = init .desc ;
195206 this .argInHelp = init .argInHelp ;
196207 this .converter = init .converter ;
208+ this .postparser = init .postparser ;
197209 }
198210
199211 @ SuppressWarnings ("unchecked" )
@@ -217,21 +229,22 @@ private void fillmissing(Init<?> init) {
217229 }
218230
219231 if (init .type != null && init .converter == null ) {
220- if (init .type .equals (Integer .class )) {
232+ var type = init .type ;
233+ if (type .equals (int .class ) || type .equals (Integer .class )) {
221234 init .converter = (Converter )new IntConverter ();
222- } else if (init . type .equals (Double .class )) {
235+ } else if (type . equals ( double . class ) || type .equals (Double .class )) {
223236 init .converter = (Converter )new DoubleConverter ();
224- } else if (init . type .equals (Long .class )) {
237+ } else if (type . equals ( long . class ) || type .equals (Long .class )) {
225238 init .converter = (Converter )new LongConverter ();
226- } else if (init . type .equals (BigDecimal .class )) {
239+ } else if (type .equals (BigDecimal .class )) {
227240 init .converter = (Converter )new BigDecimalConverter ();
228- } else if (init . type .equals (BigInteger .class )) {
241+ } else if (type .equals (BigInteger .class )) {
229242 init .converter = (Converter )new BigIntConverter ();
230- } else if (init . type .equals (Float .class )) {
243+ } else if (type . equals ( float . class ) || type .equals (Float .class )) {
231244 init .converter = (Converter )new FloatConverter ();
232- } else if (init . type .equals (Short .class )) {
245+ } else if (type . equals ( short . class ) || type .equals (Short .class )) {
233246 init .converter = (Converter )new ShortConverter ();
234- } else if (init . type .equals (Byte .class )) {
247+ } else if (type . equals ( byte . class ) || type .equals (Byte .class )) {
235248 init .converter = (Converter )new ByteConverter ();
236249 }
237250 }
@@ -247,6 +260,7 @@ private static class Init<T> {
247260 String desc ;
248261 String argInHelp ;
249262 Converter <T > converter ;
263+ Postparser <T > postparser ;
250264 }
251265
252266 /**
@@ -412,5 +426,35 @@ static <T> NamedParam<T> argInHelp(String argInHelp) {
412426 static <T > NamedParam <T > converter (Converter <T > converter ) {
413427 return init -> ((Init <T >)init ).converter = converter ;
414428 }
429+
430+ /**
431+ * Is the static method to set the {@code postparser} field like a named
432+ * parameter.
433+ *
434+ * @param <T> The type of the option argument value.
435+ *
436+ * @param postparser The value of the {@code postparser} field.
437+ * @return The {@link NamedParam} object for {@code postparser} field.
438+ */
439+ static <T > NamedParam <T > postparser (Postparser <T > postparser ) {
440+ return init -> ((Init <T >)init ).postparser = postparser ;
441+ }
442+ }
443+
444+ /**
445+ * Is the functional interface to process option arguments after parsing
446+ * command line arguments.
447+ *
448+ * @param <T> The type of the option argument value.
449+ */
450+ @ FunctionalInterface
451+ public interface Postparser <T > {
452+ /**
453+ * Processes the option arguments.
454+ *
455+ * @param optArgs The variadic parameters of the option arguments.
456+ * @throws ReasonedException If an abnormality occurs during processing.
457+ */
458+ void process (List <T > optArgs ) throws ReasonedException ;
415459 }
416460}
0 commit comments