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

Commit b5008ab

Browse files
committed
update 1.2 (my code sucks)
1 parent 206ea08 commit b5008ab

File tree

1 file changed

+9
-20
lines changed
  • src/main/java/io/github/itzispyder/clickcrystalsmoduletable

1 file changed

+9
-20
lines changed

src/main/java/io/github/itzispyder/clickcrystalsmoduletable/Main.java

+9-20
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import java.awt.datatransfer.StringSelection;
55
import java.io.File;
66
import java.io.FileInputStream;
7-
import java.util.ArrayList;
8-
import java.util.List;
97
import java.util.regex.Matcher;
108
import java.util.regex.Pattern;
119

@@ -23,22 +21,19 @@ public class Main {
2321
public static void main(String[] args) {
2422
StringBuilder result = new StringBuilder();
2523

26-
result.append("| **Module** | **Description** |").append('\n');
27-
result.append("|:----------:|:---------------:|").append('\n');
28-
29-
for (ModuleInfo info : readFiles())
30-
result.append("| ").append(info.name).append(" | ").append(info.desc).append(" |\n");
24+
result.append("| **Module** | **Description** |\n");
25+
result.append("|:----------:|:---------------:|\n");
26+
readFiles(result);
3127

3228
System.out.println(result);
3329
StringSelection data = new StringSelection(result.toString());
3430
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(data, null);
3531
System.out.println("The table above has been successfully copied to system clipboard!");
3632
}
3733

38-
public static List<ModuleInfo> readFiles() {
34+
public static void readFiles(StringBuilder builder) {
3935
try {
4036
String path = "src/main/java/io/github/itzispyder/clickcrystals/modules/modules/";
41-
List<ModuleInfo> list = new ArrayList<>();
4237

4338
for (String cat : categories) {
4439
String subPath = path + cat;
@@ -48,20 +43,18 @@ public static List<ModuleInfo> readFiles() {
4843
if (subFiles == null)
4944
continue;
5045

51-
ModuleInfo info;
46+
String info;
5247
for (File javaFile : subFiles)
53-
if ((info = readFile(javaFile)) != null)
54-
list.add(info);
48+
if ((info = readFileToRow(javaFile)) != null)
49+
builder.append(info);
5550
}
56-
return list;
5751
}
5852
catch (Exception ex) {
5953
ex.printStackTrace();
60-
return new ArrayList<>();
6154
}
6255
}
6356

64-
public static ModuleInfo readFile(File file) throws Exception {
57+
public static String readFileToRow(File file) throws Exception {
6558
FileInputStream fis = new FileInputStream(file);
6659
String contents = new String(fis.readAllBytes());
6760
fis.close();
@@ -73,7 +66,7 @@ public static ModuleInfo readFile(File file) throws Exception {
7366
if ((match = regex.matcher(line)).matches()) {
7467
String name = snake2pascalCase(match.group(1));
7568
String desc = match.group(2).replaceAll("\\\\\"", "\"");
76-
return new ModuleInfo(name, desc);
69+
return "| %s | %s |%n".formatted(name, desc);
7770
}
7871
}
7972
return null;
@@ -92,8 +85,4 @@ public static String capitalize(String s) {
9285
return s.toUpperCase();
9386
return s.substring(0, 1).toUpperCase() + s.substring(1);
9487
}
95-
96-
public record ModuleInfo(String name, String desc) {
97-
98-
}
9988
}

0 commit comments

Comments
 (0)