Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

Commit 0c896af

Browse files
Merge pull request #1 from Syrent/main
Dependency Cleanup, Lombok Annotation Removal, and CommandLineParser Refactoring
2 parents 6f121bb + 8bda940 commit 0c896af

File tree

6 files changed

+63
-81
lines changed

6 files changed

+63
-81
lines changed

.idea/discord.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,11 @@
2323
<url>https://litarvan.github.io/maven</url>
2424
</repository>
2525
</repositories>
26-
<dependencies>
26+
<dependencies>
2727
<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>
5731
</dependency>
5832
</dependencies>
5933
<build>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package ir.xenoncommunity;
22

3-
import lombok.experimental.UtilityClass;
3+
import ir.xenoncommunity.utils.CommandLineParser;
44

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();
1010
}
1111
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package ir.xenoncommunity;
22

3-
import lombok.experimental.UtilityClass;
4-
import ir.xenoncommunity.utils.ArgumentHandler;
3+
import ir.xenoncommunity.utils.CommandLineParser;
54

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;
157

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));
1616
}
1717
}

src/main/java/ir/xenoncommunity/utils/ArgumentHandler.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)