This repository was archived by the owner on Aug 6, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-24
lines changed
src/main/java/ir/xenoncommunity Expand file tree Collapse file tree 2 files changed +25
-24
lines changed Original file line number Diff line number Diff line change 6
6
@ UtilityClass
7
7
public class MainRunner {
8
8
public void run (){
9
-
9
+ System .out .println ((String ) ArgumentHandler .getArg ("-kir" ));
10
+ System .out .println ((int ) ArgumentHandler .getArg ("-kos" ));
11
+ System .out .println ((boolean ) ArgumentHandler .getArg ("-kiramtot" ));
10
12
}
11
-
12
13
}
Original file line number Diff line number Diff line change 3
3
import ir .xenoncommunity .Main ;
4
4
import lombok .val ;
5
5
import lombok .experimental .UtilityClass ;
6
+ import lombok .var ;
6
7
7
8
@ UtilityClass
8
- public class ArgumentHandler {
9
- public String getArgS (final String argIn ){
9
+ public class ArgumentHandler {
10
+ public < T > T getArg (final String argIn ) {
10
11
for (int index = 0 ; index < Main .args .length ; index ++){
11
- if (Main .args [index ].equals (argIn ))
12
- return Main .args [index +1 ];
13
- }
14
- return "NO ARGS" ;
15
- }
16
- public int getArgI (final String argIn ){
17
- for (int index = 0 ; index < Main .args .length ; index ++){
18
- if (Main .args [index ].equals (argIn ))
19
- return Integer .parseInt (Main .args [index +1 ]);
20
- }
21
- return 0 ;
22
- }
23
- public boolean getArgB (final String argIn ){
24
- for (int index = 0 ; index < Main .args .length ; index ++){
25
- if (Main .args [index ].equals (argIn )){
26
- try {
27
- return Boolean .parseBoolean (Main .args [index +1 ]);
28
- }catch (Exception e ){
29
- return true ;
12
+ if (Main .args [index ].equals (argIn )) {
13
+ var temp = (index + 1 < Main .args .length ) ? (Main .args [index + 1 ]) : ("" );
14
+ if (temp .startsWith ("-" ) ) {
15
+ return (T ) Boolean .valueOf (Boolean .parseBoolean (Main .args [index ]));
16
+ }else {
17
+ switch (temp ){
18
+ case "" :
19
+ return (T ) Boolean .valueOf (true );
20
+ case "true" :
21
+ case "false" :
22
+ return (T ) Boolean .valueOf (Boolean .parseBoolean (temp ));
23
+ case default :
24
+ try {
25
+ return (T ) Integer .valueOf (Integer .parseInt (temp ));
26
+ } catch (Exception e ) {
27
+ return (T ) temp ;
28
+ }
29
+ }
30
30
}
31
31
}
32
32
}
33
- return false ;
33
+ return ( T ) "NO ARGS" ;
34
34
}
35
35
}
You can’t perform that action at this time.
0 commit comments