Skip to content

Commit f80c47e

Browse files
author
Zihlu Wang
committed
docs(global): Optimised javadoc, changed the spelling to British English.
1 parent fee85d5 commit f80c47e

File tree

41 files changed

+459
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+459
-438
lines changed

devkit-core/src/main/java/cn/org/codecrafters/devkit/core/exceptions/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
/**
19-
* Commonly used exceptions will be used in JDevKit.
19+
* This package contains commonly used exceptions will be used in JDevKit.
2020
*
2121
* @author Zihlu Wang
2222
* @since 1.0.0

devkit-core/src/main/java/cn/org/codecrafters/devkit/core/package-info.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616
*/
1717

1818
/**
19-
* This package is a part of JDevKit, an open-source Java Development Kit that
20-
* provides a set of convenient tools to streamline code development and
21-
* enhance productivity. This package serves as the core package containing
22-
* common exceptions that are used throughout the entireJDevKit project.
23-
*
19+
* This package is the core part of JDevKit, an open-source Java Development
20+
* Kit that provides a set of convenient tools to streamline code development
21+
* and enhance productivity. This package serves as the core package containing
22+
* common exceptions that are used throughout the entire JDevKit project.
2423
* <p>
2524
* JDevKit is designed to be modular, and other specific feature modules within
2625
* the library may rely on these exceptions from the core package.
27-
*
2826
* <p>
2927
* For more information and the latest version of JDevKit, please visit our
3028
* website <a href="https://codecrafters.org.cn">codecrafters.org.cn</a>.
31-
*
3229
* <p>
3330
* <b>Contact</b>
3431
* <ul>

devkit-core/src/main/java/cn/org/codecrafters/devkit/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* This package is the main part of JDevKit, an open-source Java class library
2020
* that provides a set of convenient tools to streamline code development and
2121
* enhance productivity. This package serves as the root package for several
22-
* modules, containing devkit-core, guid and dev-utils module.
23-
*
22+
* modules, containing {@code devkit-core}, {@code guid} and {@code dev-utils}
23+
* module.
2424
* <p>
2525
* For more information and the latest version of JDevKit, please visit our
2626
* website <a href="https://codecrafters.org.cn">codecrafters.org.cn</a>.

devkit-utils/src/main/java/cn/org/codecrafters/devkit/utils/AesUtil.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
import java.util.UUID;
3535

3636
/**
37-
* AES Util helps you encrypt and decrypt data with specified key and AES
38-
* algorithm.
37+
* {@link AesUtil} can help you encrypt and decrypt data with specified secret
38+
* by AES algorithm.
3939
*
4040
* @author hubin@baomidou
41-
* @since 1.1.0
4241
* @version 1.1.0
42+
* @since 1.1.0
4343
*/
4444
@Slf4j
4545
public final class AesUtil {
@@ -52,17 +52,17 @@ private AesUtil() {
5252
private static final String AES_CBC_CIPHER = "AES/CBC/PKCS5Padding";
5353

5454
/**
55-
* Encrypt the given data with given key with AES algorithm.
55+
* Encrypts the data using the AES algorithm with the given secret.
5656
*
57-
* @param data the data to be encrypted
58-
* @param key the key to encrypt the data
57+
* @param data the data to be encrypted
58+
* @param secret the secret to encrypt the data
5959
* @return the encryption result or {@code null} if encryption failed
6060
*/
61-
public static byte[] encrypt(byte[] data, byte[] key) {
61+
public static byte[] encrypt(byte[] data, byte[] secret) {
6262
try {
63-
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(key, AES).getEncoded(), AES);
63+
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
6464
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
65-
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(key));
65+
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(secret));
6666
return cipher.doFinal(data);
6767
} catch (NoSuchAlgorithmException | NoSuchPaddingException | UnsupportedOperationException |
6868
InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException |
@@ -76,17 +76,17 @@ public static byte[] encrypt(byte[] data, byte[] key) {
7676
}
7777

7878
/**
79-
* Decrypt the given data with given key with AES algorithm.
79+
* Decrypts the data using the AES algorithm with the given secret.
8080
*
8181
* @param data the data to be decrypted
82-
* @param key the key to encrypt the data
82+
* @param secret the secret to encrypt the data
8383
* @return the decryption result or {@code null} if decryption failed
8484
*/
85-
public static byte[] decrypt(byte[] data, byte[] key) {
85+
public static byte[] decrypt(byte[] data, byte[] secret) {
8686
try {
87-
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(key, AES).getEncoded(), AES);
87+
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
8888
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
89-
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(key));
89+
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(secret));
9090
return cipher.doFinal(data);
9191
} catch (NoSuchAlgorithmException | NoSuchPaddingException | UnsupportedOperationException |
9292
InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException |
@@ -100,36 +100,36 @@ public static byte[] decrypt(byte[] data, byte[] key) {
100100
}
101101

102102
/**
103-
* Encrypt the given data with given key with AES algorithm.
103+
* Encrypts the data using the AES algorithm with the given secret.
104104
*
105105
* @param data the data to be encrypted
106-
* @param key the key to encrypt the data
106+
* @param secret the secret to encrypt the data
107107
* @return the encryption result or {@code null} if encryption failed
108108
*/
109-
public static String encrypt(String data, String key) {
110-
return Base64.getEncoder().encodeToString(encrypt(data.getBytes(StandardCharsets.UTF_8), key.getBytes(StandardCharsets.UTF_8)));
109+
public static String encrypt(String data, String secret) {
110+
return Base64.getEncoder().encodeToString(encrypt(data.getBytes(StandardCharsets.UTF_8), secret.getBytes(StandardCharsets.UTF_8)));
111111
}
112112

113113
/**
114-
* Decrypt the given data with given key with AES algorithm.
114+
* Decrypts the data using the AES algorithm with the given secret.
115115
*
116116
* @param data the data to be decrypted
117-
* @param key the key to encrypt the data
117+
* @param secret the secret to encrypt the data
118118
* @return the decryption result or {@code null} if decryption failed
119119
*/
120-
public static String decrypt(String data, String key) {
120+
public static String decrypt(String data, String secret) {
121121
return new String(Objects.requireNonNull(
122122
decrypt(Base64.getDecoder().decode(data.getBytes()),
123-
key.getBytes(StandardCharsets.UTF_8)))
123+
secret.getBytes(StandardCharsets.UTF_8)))
124124
);
125125
}
126126

127127
/**
128-
* Generates 16 characters-long random key.
128+
* Generates 16 characters-long random secret.
129129
*
130130
* @return the generated secure secret
131131
*/
132-
public static String generateRandomKey() {
132+
public static String generateRandomSecret() {
133133
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16);
134134
}
135135

devkit-utils/src/main/java/cn/org/codecrafters/devkit/utils/Base64Util.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
import java.nio.charset.Charset;
2121
import java.nio.charset.StandardCharsets;
2222
import java.util.Base64;
23+
import java.util.Objects;
2324

2425
/**
25-
* The {@code Base64Util} class provides static methods to encode and decode
26-
* strings using Base64 encoding. It utilizes the {@link Base64} class from the
26+
* The {@link Base64Util} class provides static methods to encode and decode
27+
* strings with Base64 encoding. It utilizes the {@link Base64} class from the
2728
* Java standard library for performing the encoding and decoding operations.
2829
* This utility class offers convenient methods to encode and decode strings
2930
* with different character sets.
@@ -55,6 +56,34 @@
5556
*/
5657
public final class Base64Util {
5758

59+
private static Base64.Encoder encoder;
60+
61+
private static Base64.Decoder decoder;
62+
63+
/**
64+
* Ensure that there is only one Base64 Encoder.
65+
*
66+
* @return the {@link Base64.Encoder} instance
67+
*/
68+
private static Base64.Encoder getEncoder() {
69+
if (Objects.isNull(encoder)) {
70+
encoder = Base64.getEncoder();
71+
}
72+
return encoder;
73+
}
74+
75+
/**
76+
* Ensure that there is only one Base64 Encoder.
77+
*
78+
* @return the {@link Base64.Encoder} instance
79+
*/
80+
private static Base64.Decoder getDecoder() {
81+
if (Objects.isNull(decoder)) {
82+
decoder = Base64.getDecoder();
83+
}
84+
return decoder;
85+
}
86+
5887
/**
5988
* Private constructor to prevent instantiation of the class.
6089
*/
@@ -69,8 +98,7 @@ private Base64Util() {
6998
* @return the Base64 encoded string
7099
*/
71100
public static String encode(String value, Charset charset) {
72-
var encoder = Base64.getEncoder();
73-
var encoded = encoder.encode(value.getBytes(charset));
101+
var encoded = getEncoder().encode(value.getBytes(charset));
74102

75103
return new String(encoded);
76104
}
@@ -93,8 +121,7 @@ public static String encode(String value) {
93121
* @return the decoded string
94122
*/
95123
public static String decode(String value, Charset charset) {
96-
var decoder = Base64.getDecoder();
97-
var decoded = decoder.decode(value.getBytes(charset));
124+
var decoded = getDecoder().decode(value.getBytes(charset));
98125

99126
return new String(decoded);
100127
}

devkit-utils/src/main/java/cn/org/codecrafters/devkit/utils/BranchUtil.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@
2323
import java.util.function.Supplier;
2424

2525
/**
26-
* The BranchUtil class provides static methods to simplify conditional logic
27-
* in Java development by leveraging lambda expressions. It offers convenient
28-
* methods to replace verbose if...else statements with more concise and
29-
* expressive functional constructs.
26+
* The {@link BranchUtil} class provides static methods to simplify conditional
27+
* logic in Java development by leveraging lambda expressions. It offers
28+
* convenient methods to replace verbose {@code if...else} statements with more
29+
* concise and expressive functional constructs.
3030
* <p>
31-
* Developers can use the methods in this utility class to streamline their
32-
* code, enhance readability, and promote a more functional style of
33-
* programming when dealing with branching logic and conditional statements.
31+
* Developers can use methods in this utility class to streamline their code,
32+
* enhance readability, and promote a more functional style of programming when
33+
* dealing with branching logic and conditional statements.
3434
* <p>
3535
* <b>Example:</b>
3636
* <pre>
3737
* // If you want to simplify an if (exp1 || exp2), you can use the
3838
* // following code:
39-
* var r1 = BranchUtil.or(1 == 1, 2 == 1)
39+
* String r1 = BranchUtil.or(1 == 1, 2 == 1)
4040
* .handle(() -> "1 is equal to 1 or 2 is equal to 1.");
4141
*
4242
* // If you have an else branch, you can use the following code:
43-
* var r2 = BranchUtil.or(1 == 1, 2 == 1)
43+
* String r2 = BranchUtil.or(1 == 1, 2 == 1)
4444
* .handle(() -> "1 is equal to 1 or 2 is equal to 1.",
4545
* () -> "1 is not equal to 1 and 2 is not equal to 1.");
4646
*

0 commit comments

Comments
 (0)