@@ -95,6 +95,12 @@ public class OptCfg {
95
95
*/
96
96
public final Converter <?> converter ;
97
97
98
+ /**
99
+ * Is the function interface that is executed after parsing command line
100
+ * arguments.
101
+ */
102
+ public final Postparser <?> postparser ;
103
+
98
104
/**
99
105
* Is the constructor that takes the all field values as parameters.
100
106
* <p>
@@ -120,8 +126,10 @@ public class OptCfg {
120
126
* @param defaults The default value(s).
121
127
* @param desc The description of the option.
122
128
* @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.
125
133
*/
126
134
public <T > OptCfg (
127
135
String storeKey ,
@@ -132,7 +140,8 @@ public <T> OptCfg(
132
140
List <T > defaults ,
133
141
String desc ,
134
142
String argInHelp ,
135
- Converter <T > converter
143
+ Converter <T > converter ,
144
+ Postparser <T > postparser
136
145
) {
137
146
var init = new Init <T >();
138
147
init .storeKey = storeKey ;
@@ -144,6 +153,7 @@ public <T> OptCfg(
144
153
init .desc = desc ;
145
154
init .argInHelp = argInHelp ;
146
155
init .converter = converter ;
156
+ init .postparser = postparser ;
147
157
148
158
fillmissing (init );
149
159
@@ -156,6 +166,7 @@ public <T> OptCfg(
156
166
this .desc = init .desc ;
157
167
this .argInHelp = init .argInHelp ;
158
168
this .converter = init .converter ;
169
+ this .postparser = init .postparser ;
159
170
}
160
171
161
172
/**
@@ -194,6 +205,7 @@ public <T> OptCfg(NamedParam<T> ...params) {
194
205
this .desc = init .desc ;
195
206
this .argInHelp = init .argInHelp ;
196
207
this .converter = init .converter ;
208
+ this .postparser = init .postparser ;
197
209
}
198
210
199
211
@ SuppressWarnings ("unchecked" )
@@ -217,21 +229,22 @@ private void fillmissing(Init<?> init) {
217
229
}
218
230
219
231
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 )) {
221
234
init .converter = (Converter )new IntConverter ();
222
- } else if (init . type .equals (Double .class )) {
235
+ } else if (type . equals ( double . class ) || type .equals (Double .class )) {
223
236
init .converter = (Converter )new DoubleConverter ();
224
- } else if (init . type .equals (Long .class )) {
237
+ } else if (type . equals ( long . class ) || type .equals (Long .class )) {
225
238
init .converter = (Converter )new LongConverter ();
226
- } else if (init . type .equals (BigDecimal .class )) {
239
+ } else if (type .equals (BigDecimal .class )) {
227
240
init .converter = (Converter )new BigDecimalConverter ();
228
- } else if (init . type .equals (BigInteger .class )) {
241
+ } else if (type .equals (BigInteger .class )) {
229
242
init .converter = (Converter )new BigIntConverter ();
230
- } else if (init . type .equals (Float .class )) {
243
+ } else if (type . equals ( float . class ) || type .equals (Float .class )) {
231
244
init .converter = (Converter )new FloatConverter ();
232
- } else if (init . type .equals (Short .class )) {
245
+ } else if (type . equals ( short . class ) || type .equals (Short .class )) {
233
246
init .converter = (Converter )new ShortConverter ();
234
- } else if (init . type .equals (Byte .class )) {
247
+ } else if (type . equals ( byte . class ) || type .equals (Byte .class )) {
235
248
init .converter = (Converter )new ByteConverter ();
236
249
}
237
250
}
@@ -247,6 +260,7 @@ private static class Init<T> {
247
260
String desc ;
248
261
String argInHelp ;
249
262
Converter <T > converter ;
263
+ Postparser <T > postparser ;
250
264
}
251
265
252
266
/**
@@ -412,5 +426,35 @@ static <T> NamedParam<T> argInHelp(String argInHelp) {
412
426
static <T > NamedParam <T > converter (Converter <T > converter ) {
413
427
return init -> ((Init <T >)init ).converter = converter ;
414
428
}
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 ;
415
459
}
416
460
}
0 commit comments