This repository was archived by the owner on Aug 6, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +63
-81
lines changed
src/main/java/ir/xenoncommunity Expand file tree Collapse file tree 6 files changed +63
-81
lines changed Original file line number Diff line number Diff line change 23
23
<url >https://litarvan.github.io/maven</url >
24
24
</repository >
25
25
</repositories >
26
- <dependencies >
26
+ <dependencies >
27
27
<dependency >
28
- <groupId >net.java.dev.jna</groupId >
29
- <artifactId >platform</artifactId >
30
- <version >3.4.0</version >
31
- </dependency >
32
- <dependency >
33
- <groupId >com.google.guava</groupId >
34
- <artifactId >guava</artifactId >
35
- <version >17.0</version >
36
- </dependency >
37
- <dependency >
38
- <groupId >com.google.code.gson</groupId >
39
- <artifactId >gson</artifactId >
40
- <version >2.10.1</version >
41
- </dependency >
42
- <dependency >
43
- <groupId >javax.vecmath</groupId >
44
- <artifactId >vecmath</artifactId >
45
- <version >1.5.2</version >
46
- </dependency >
47
- <dependency >
48
- <groupId >org.projectlombok</groupId >
49
- <artifactId >lombok</artifactId >
50
- <version >1.18.30</version >
51
- <scope >compile</scope >
52
- </dependency >
53
- <dependency >
54
- <groupId >org.reflections</groupId >
55
- <artifactId >reflections</artifactId >
56
- <version >0.10.2</version >
28
+ <groupId >org.jetbrains</groupId >
29
+ <artifactId >annotations</artifactId >
30
+ <version >24.1.0</version >
57
31
</dependency >
58
32
</dependencies >
59
33
<build >
Original file line number Diff line number Diff line change 1
1
package ir .xenoncommunity ;
2
2
3
- import lombok . experimental . UtilityClass ;
3
+ import ir . xenoncommunity . utils . CommandLineParser ;
4
4
5
- public class Main {
6
- public static String [] args ;
7
- public static void main ( final String [] args ){
8
- Main . args = args ;
9
- MainRunner .run ();
5
+ public class Main {
6
+ public static void main ( String [] args ) {
7
+ CommandLineParser parser = new CommandLineParser ( args );
8
+ MainRunner runner = new MainRunner ( parser ) ;
9
+ runner .run ();
10
10
}
11
11
}
Original file line number Diff line number Diff line change 1
1
package ir .xenoncommunity ;
2
2
3
- import lombok .experimental .UtilityClass ;
4
- import ir .xenoncommunity .utils .ArgumentHandler ;
3
+ import ir .xenoncommunity .utils .CommandLineParser ;
5
4
6
- @ UtilityClass
7
- public class MainRunner {
8
- public void run (){
9
- System .out .println ((String ) ArgumentHandler .getArg ("-kir" ));
10
- System .out .println ((int ) ArgumentHandler .getArg ("-kos" ));
11
- System .out .println ((boolean ) ArgumentHandler .getArg ("-kiramtot" ));
12
- System .out .println ((boolean ) ArgumentHandler .getArg ("-kosam" ));
13
- System .out .println ((boolean ) ArgumentHandler .getArg ("-kooooos" ));
14
- System .out .println ((boolean ) ArgumentHandler .getArg ("-rot" ));
5
+ public class MainRunner {
6
+ private final CommandLineParser parser ;
15
7
8
+ public MainRunner (CommandLineParser parser ) {
9
+ this .parser = parser ;
10
+ }
11
+
12
+ public void run () {
13
+ System .out .println (parser .get ("-examplestring" , String .class ));
14
+ System .out .println (parser .get ("-exampleinteger" , Integer .class ));
15
+ System .out .println (parser .get ("-exampleboolean" , Boolean .class ));
16
16
}
17
17
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package ir .xenoncommunity .utils ;
2
+
3
+ import org .jetbrains .annotations .Nullable ;
4
+
5
+ public class CommandLineParser {
6
+
7
+ private final String [] args ;
8
+
9
+ public CommandLineParser (String [] args ) {
10
+ this .args = args ;
11
+ }
12
+
13
+ @ Nullable
14
+ public <T > T get (String arg , Class <T > type ) {
15
+ for (int i = 0 ; i < args .length - 1 ; i ++) {
16
+ if (args [i ].equals (arg )) {
17
+ String value = args [i + 1 ];
18
+ return convertToType (value , type );
19
+ }
20
+ }
21
+ return null ;
22
+ }
23
+
24
+ private <T > T convertToType (String value , Class <T > type ) {
25
+ if (type .equals (String .class )) {
26
+ return type .cast (value );
27
+ } else if (type .equals (Integer .class )) {
28
+ return type .cast (Integer .valueOf (value ));
29
+ } else if (type .equals (Boolean .class )) {
30
+ return type .cast (Boolean .valueOf (value ));
31
+ } else {
32
+ throw new IllegalArgumentException ("Unsupported type" );
33
+ }
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments