Skip to content

Commit c7d39ec

Browse files
committed
21
1 parent c168663 commit c7d39ec

5 files changed

Lines changed: 104 additions & 73 deletions

File tree

pom.xml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,6 @@
104104
<version>20230227</version>
105105
<!-- <type>bundle</type>-->
106106
</dependency>
107-
<!-- <dependency>-->
108-
<!-- <groupId>junit</groupId>-->
109-
<!-- <artifactId>junit</artifactId>-->
110-
<!-- <version>4.13</version>-->
111-
<!-- <scope>test</scope>-->
112-
<!-- </dependency>-->
113-
<!-- <dependency>-->
114-
<!-- <groupId>org.junit.vintage</groupId>-->
115-
<!-- <artifactId>junit-vintage-engine</artifactId>-->
116-
<!-- <version>5.7.1</version>-->
117-
<!-- <scope>test</scope>-->
118-
<!-- </dependency>-->
119107
<dependency>
120108
<groupId>org.junit.jupiter</groupId>
121109
<artifactId>junit-jupiter</artifactId>
@@ -190,8 +178,8 @@
190178
<groupId>org.apache.maven.plugins</groupId>
191179
<artifactId>maven-compiler-plugin</artifactId>
192180
<configuration>
193-
<source>21</source>
194-
<target>21</target>
181+
<source>${java.version}</source>
182+
<target>${java.version}</target>
195183
</configuration>
196184
</plugin>
197185
<plugin>

src/main/java/com/anma/java/core/java21/SealedOne.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public class SealedOne {
44
void sealed() {
5-
Req
5+
66
}
77
}
Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,60 @@
1-
package com.anma.java.core.java21;
2-
3-
import java.nio.file.Files;
4-
import java.nio.file.Path;
5-
import java.nio.file.Paths;
6-
import java.util.Locale;
7-
8-
import static java.lang.StringTemplate.STR;
9-
10-
public class StrTemplating {
11-
12-
record Rectangle(String name, double width, double height) {
13-
double area() {
14-
return width * height;
15-
}
16-
}
17-
18-
Rectangle[] zone = new Rectangle[] {
19-
new Rectangle("First", 17.8, 31.4),
20-
new Rectangle("Second", 9.6, 12.2),
21-
};
22-
23-
String table = STR."""
24-
Description\tWidth\tHeight\tArea
25-
\{zone[0].name}\t\t\{zone[0].width}\t\{zone[0].height}\t\{zone[0].area()}
26-
\{zone[1].name}\t\t\{zone[1].width}\t\{zone[1].height}\t\{zone[1].area()}
27-
Total \{zone[0].area() + zone[1].area()}
28-
""";
29-
30-
System.out.println(table);
31-
void templating() {
32-
String time = STR."Today is \{java.time.LocalDate.now()}";
33-
System.out.println(time);
34-
String canLang = STR."The language code of \{
35-
Locale.CANADA_FRENCH} is \{
36-
Locale.CANADA_FRENCH.getLanguage()}";
37-
38-
System.out.println(canLang);
39-
}
40-
41-
void templateTwo() {
42-
Path filePath = Paths.get("Stemp.java");
43-
String msg = STR."The file \{filePath} \{
44-
// The Files class is in the package java.nio.file
45-
Files.exists(filePath) ? "does" : "does not"} exist";
46-
System.out.println(msg);
47-
48-
String currentTime = STR."The time is \{
49-
DateTimeFormatter
50-
.ofPattern("HH:mm:ss")
51-
.format(LocalTime.now())
52-
} right now";
53-
System.out.println(currentTime);
54-
55-
}
56-
57-
58-
}
1+
//package com.anma.java.core.java21;
2+
//
3+
//import java.nio.file.Files;
4+
//import java.nio.file.Path;
5+
//import java.nio.file.Paths;
6+
//import java.time.LocalTime;
7+
//import java.time.format.DateTimeFormatter;
8+
//import java.util.Locale;
9+
//
10+
//import static java.lang.StringTemplate.STR;
11+
//
12+
//public class StrTemplating {
13+
//
14+
// record Rectangle(String name, double width, double height) {
15+
// double area() {
16+
// return width * height;
17+
// }
18+
// }
19+
//
20+
// Rectangle[] zone = new Rectangle[] {
21+
// new Rectangle("First", 17.8, 31.4),
22+
// new Rectangle("Second", 9.6, 12.2),
23+
// };
24+
//
25+
// String table = STR."""
26+
// Description\tWidth\tHeight\tArea
27+
// \{zone[0].name}\t\t\{zone[0].width}\t\{zone[0].height}\t\{zone[0].area()}
28+
// \{zone[1].name}\t\t\{zone[1].width}\t\{zone[1].height}\t\{zone[1].area()}
29+
// Total \{zone[0].area() + zone[1].area()}
30+
// """;
31+
//
32+
// System.out.println(table);
33+
// void templating() {
34+
// String time = STR."Today is \{java.time.LocalDate.now()}";
35+
// System.out.println(time);
36+
// String canLang = STR."The language code of \{
37+
// Locale.CANADA_FRENCH} is \{
38+
// Locale.CANADA_FRENCH.getLanguage()}";
39+
//
40+
// System.out.println(canLang);
41+
// }
42+
//
43+
// void templateTwo() {
44+
// Path filePath = Paths.get("Stemp.java");
45+
// String msg = STR."The file \{filePath} \{
46+
// // The Files class is in the package java.nio.file
47+
// Files.exists(filePath) ? "does" : "does not"} exist";
48+
// System.out.println(msg);
49+
//
50+
// String currentTime = STR."The time is \{
51+
// DateTimeFormatter
52+
// .ofPattern("HH:mm:ss")
53+
// .format(LocalTime.now())
54+
// } right now";
55+
// System.out.println(currentTime);
56+
//
57+
// }
58+
//
59+
//
60+
//}

src/main/java/com/anma/java/core/util/RandomExec.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,28 @@ public static void main(String[] args) {
2525
// }
2626
// System.out.println(doubleStream.findFirst().getAsDouble());
2727
}
28+
29+
public static String randomString(int length) {
30+
String alphabet = "abcdefghijklmnopqrstuvwxyz";
31+
StringBuilder sb = new StringBuilder();
32+
for (int i = 0; i < length; i++) {
33+
int index = new Random().nextInt(0, alphabet.length());
34+
sb.append(alphabet.charAt(index));
35+
}
36+
return sb.toString();
37+
}
38+
39+
public static String randomStringWithExclamations(int length) {
40+
String alphabet = "abcdefghijklmnopqrstuvwxyz";
41+
StringBuilder sb = new StringBuilder();
42+
for (int i = 0; i < length; i++) {
43+
int index = new Random().nextInt(0, alphabet.length());
44+
if (index < 6) {
45+
sb.append("!");
46+
} else {
47+
sb.append(alphabet.charAt(index));
48+
}
49+
}
50+
return sb.toString();
51+
}
2852
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.anma.java.core.util;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.Random;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class RandomExecTest {
10+
11+
@Test
12+
void randomString() {
13+
14+
System.out.println(RandomExec.randomStringWithExclamations(12));
15+
16+
}
17+
}

0 commit comments

Comments
 (0)