|
4 | 4 |
|
5 | 5 | importjava.io.File;
|
6 | 6 | importjava.io.IOException;
|
7 |
| -importjava.nio.file.DirectoryStream; |
8 |
| -importjava.nio.file.Files; |
9 |
| -importjava.nio.file.Path; |
10 |
| -importjava.nio.file.Paths; |
| 7 | +importjava.nio.file.*; |
11 | 8 | importjava.util.ArrayList;
|
12 | 9 | importjava.util.List;
|
13 | 10 | importjava.util.regex.Pattern;
|
@@ -44,114 +41,121 @@ public static void main(String[] args) throws IOException {
|
44 | 41 | ind++;
|
45 | 42 | finalbyte[]readmeMd =Files.readAllBytes(Paths.get(file.getAbsolutePath()));
|
46 | 43 | StringreadmeMdText =newString(readmeMd,UTF_8);
|
| 44 | +PathMatchermatcher =FileSystems.getDefault().getPathMatcher("glob:*.{java,kt}"); |
47 | 45 | try (DirectoryStream<Path>dirStream =
|
48 | 46 | Files.newDirectoryStream(
|
49 |
| -Paths.get(file.getAbsolutePath().replace("readme.md","")),"*.java")) { |
| 47 | +Paths.get(file.getAbsolutePath().replace("readme.md","")))) { |
50 | 48 | for (Pathentry :dirStream) {
|
51 |
| -FilejavaFile =entry.toFile(); |
52 |
| -Pathpath =Paths.get(javaFile.getAbsolutePath()); |
53 |
| -finalbyte[]solutionJava =Files.readAllBytes(path); |
54 |
| -StringsolutionJavaText =newString(solutionJava,UTF_8); |
55 |
| -int[]index = {0}; |
56 |
| -String[]fromStr = { |
57 |
| -"(\"{{", |
58 |
| -"=\"{{", |
59 |
| -"\n- [", |
60 |
| -" board = [[", |
61 |
| -" grid = [[", |
62 |
| -" = [[", |
63 |
| -"**,", |
64 |
| -"**]", |
65 |
| -"(**", |
66 |
| -"**)", |
67 |
| -"[[]", |
68 |
| -"<code>", |
69 |
| -"</code>", |
70 |
| -"<sub>", |
71 |
| -"</sub>", |
72 |
| -"<sup>", |
73 |
| -"</sup>", |
74 |
| -"<ins>", |
75 |
| -"</ins>", |
76 |
| -"<", |
77 |
| -">", |
78 |
| -"&" |
79 |
| - }; |
80 |
| -String[]fromStr2 = { |
81 |
| -"[code]","[/code]","[sub]","[/sub]","[sup]","[/sup]","[ins]", |
82 |
| -"[/ins]", |
83 |
| - }; |
84 |
| -String[]toStr = { |
85 |
| -"(\"{ {", |
86 |
| -"=\"{ {", |
87 |
| -"\n-\\[", |
88 |
| -" board = [ [", |
89 |
| -" grid = [ [", |
90 |
| -" =\\[\\[", |
91 |
| -"** ,", |
92 |
| -"** ]", |
93 |
| -"( **", |
94 |
| -"** )", |
95 |
| -"[ []", |
96 |
| -"[code]", |
97 |
| -"[/code]", |
98 |
| -"[sub]", |
99 |
| -"[/sub]", |
100 |
| -"[sup]", |
101 |
| -"[/sup]", |
102 |
| -"[ins]", |
103 |
| -"[/ins]", |
104 |
| -"<", |
105 |
| -">", |
106 |
| -"&" |
107 |
| - }; |
108 |
| -String[]toStr2 = { |
109 |
| -"<code>","</code>","<sub>","</sub>","<sup>","</sup>","<ins>", |
110 |
| -"</ins>", |
111 |
| - }; |
112 |
| -StringreadmeMdJavadoc = |
113 |
| -"/**\n" |
114 |
| - +StringUtils.replaceEach( |
115 |
| -StringUtils.replaceEach( |
116 |
| -PATTERN.splitAsStream(readmeMdText) |
117 |
| - .map( |
118 |
| -line -> { |
119 |
| -StringfirstLine = |
120 |
| -line |
121 |
| - .replace( |
122 |
| -"\\.", |
123 |
| -" -") |
124 |
| - +"\\."; |
125 |
| -Stringstr = |
126 |
| -index[0]++ |
127 |
| - ==0 |
128 |
| - ?firstLine |
129 |
| - :line; |
130 |
| -returnline |
131 |
| - .isEmpty() |
132 |
| - ?" *" |
133 |
| - :" * " |
134 |
| - +str; |
135 |
| - }) |
136 |
| - .collect( |
137 |
| -Collectors.joining( |
138 |
| -"\n")), |
139 |
| -fromStr, |
140 |
| -toStr), |
141 |
| -fromStr2, |
142 |
| -toStr2) |
143 |
| - .replace("`**","` **") |
144 |
| - .replace(",**",", **") |
145 |
| - .replace("<ins>**","<ins> **") |
146 |
| - .replace("**</ins>","** </ins>") |
147 |
| - .replace("/*","{@literal /}*") |
148 |
| - .replace("*/","*{@literal /}") |
149 |
| - +"\n**/"; |
150 |
| -StringpublicClass = |
151 |
| -solutionJavaText.contains("@SuppressWarnings") |
152 |
| - ?"@SuppressWarnings" |
153 |
| - :"public class "; |
154 |
| -Files.write(path,getBytes(solutionJavaText,readmeMdJavadoc,publicClass)); |
| 49 | +if (matcher.matches(entry.getFileName())) { |
| 50 | +FilejavaFile =entry.toFile(); |
| 51 | +Pathpath =Paths.get(javaFile.getAbsolutePath()); |
| 52 | +finalbyte[]solutionJava =Files.readAllBytes(path); |
| 53 | +StringsolutionJavaText =newString(solutionJava,UTF_8); |
| 54 | +int[]index = {0}; |
| 55 | +String[]fromStr = { |
| 56 | +"(\"{{", |
| 57 | +"=\"{{", |
| 58 | +"\n- [", |
| 59 | +" board = [[", |
| 60 | +" grid = [[", |
| 61 | +" = [[", |
| 62 | +"**,", |
| 63 | +"**]", |
| 64 | +"(**", |
| 65 | +"**)", |
| 66 | +"[[]", |
| 67 | +"<code>", |
| 68 | +"</code>", |
| 69 | +"<sub>", |
| 70 | +"</sub>", |
| 71 | +"<sup>", |
| 72 | +"</sup>", |
| 73 | +"<ins>", |
| 74 | +"</ins>", |
| 75 | +"<", |
| 76 | +">", |
| 77 | +"&" |
| 78 | + }; |
| 79 | +String[]fromStr2 = { |
| 80 | +"[code]","[/code]","[sub]","[/sub]","[sup]","[/sup]","[ins]", |
| 81 | +"[/ins]", |
| 82 | + }; |
| 83 | +String[]toStr = { |
| 84 | +"(\"{ {", |
| 85 | +"=\"{ {", |
| 86 | +"\n-\\[", |
| 87 | +" board = [ [", |
| 88 | +" grid = [ [", |
| 89 | +" =\\[\\[", |
| 90 | +"** ,", |
| 91 | +"** ]", |
| 92 | +"( **", |
| 93 | +"** )", |
| 94 | +"[ []", |
| 95 | +"[code]", |
| 96 | +"[/code]", |
| 97 | +"[sub]", |
| 98 | +"[/sub]", |
| 99 | +"[sup]", |
| 100 | +"[/sup]", |
| 101 | +"[ins]", |
| 102 | +"[/ins]", |
| 103 | +"<", |
| 104 | +">", |
| 105 | +"&" |
| 106 | + }; |
| 107 | +String[]toStr2 = { |
| 108 | +"<code>","</code>","<sub>","</sub>","<sup>","</sup>","<ins>", |
| 109 | +"</ins>", |
| 110 | + }; |
| 111 | +StringreadmeMdJavadoc = |
| 112 | +"/**\n" |
| 113 | + +StringUtils.replaceEach( |
| 114 | +StringUtils.replaceEach( |
| 115 | +PATTERN.splitAsStream(readmeMdText) |
| 116 | + .map( |
| 117 | +line -> { |
| 118 | +String |
| 119 | +firstLine = |
| 120 | +line |
| 121 | + .replace( |
| 122 | +"\\.", |
| 123 | +" -") |
| 124 | + +"\\."; |
| 125 | +Stringstr = |
| 126 | +index[ |
| 127 | +0]++ |
| 128 | + ==0 |
| 129 | + ?firstLine |
| 130 | + :line; |
| 131 | +returnline |
| 132 | + .isEmpty() |
| 133 | + ?" *" |
| 134 | + :" * " |
| 135 | + +str; |
| 136 | + }) |
| 137 | + .collect( |
| 138 | +Collectors.joining( |
| 139 | +"\n")), |
| 140 | +fromStr, |
| 141 | +toStr), |
| 142 | +fromStr2, |
| 143 | +toStr2) |
| 144 | + .replace("`**","` **") |
| 145 | + .replace(",**",", **") |
| 146 | + .replace("<ins>**","<ins> **") |
| 147 | + .replace("**</ins>","** </ins>") |
| 148 | + .replace("/*","{@literal /}*") |
| 149 | + .replace("*/","*{@literal /}") |
| 150 | + +"\n**/"; |
| 151 | +StringpublicClass = |
| 152 | +solutionJavaText.contains("@SuppressWarnings") |
| 153 | + ?"@SuppressWarnings" |
| 154 | + :solutionJavaText.contains("public class ") |
| 155 | + ?"public class " |
| 156 | + :"class "; |
| 157 | +Files.write(path,getBytes(solutionJavaText,readmeMdJavadoc,publicClass)); |
| 158 | + } |
155 | 159 | }
|
156 | 160 | }
|
157 | 161 | }
|
|