Skip to content

Commit a85c562

Browse files
author
zihluwang
committed
docs: added docs
1 parent 566a960 commit a85c562

File tree

22 files changed

+357
-147
lines changed

22 files changed

+357
-147
lines changed

devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
package com.onixbyte.devkit.core.exceptions;
1919

2020
/**
21-
* The {@code NotImplementedException} class is a custom runtime exception that represents a situation where a
22-
* particular method or functionality is not implemented or is currently unavailable in the codebase.
21+
* The {@code NotImplementedException} class is a custom runtime exception that represents a
22+
* situation where a particular method or functionality is not implemented or is currently
23+
* unavailable in the codebase.
2324
* <p>
24-
* This exception is typically thrown when developers need to indicate that a specific part of the code is incomplete
25-
* or requires further implementation. It serves as a placeholder to highlight unfinished sections of the application
26-
* during development and testing phases.
25+
* This exception is typically thrown when developers need to indicate that a specific part of the
26+
* code is incomplete or requires further implementation. It serves as a placeholder to highlight
27+
* unfinished sections of the application during development and testing phases.
2728
* <p>
2829
* Usage Example:
2930
* <pre>
@@ -57,7 +58,8 @@ public NotImplementedException(String message) {
5758
}
5859

5960
/**
60-
* Creates a new {@code NotImplementedException} with the specified error message and a cause for this exception.
61+
* Creates a new {@code NotImplementedException} with the specified error message and a cause
62+
* for this exception.
6163
*
6264
* @param message the error message associated with this exception
6365
* @param cause the cause of this exception
@@ -76,8 +78,8 @@ public NotImplementedException(Throwable cause) {
7678
}
7779

7880
/**
79-
* Creates a new {@code NotImplementedException} with the specified error message, cause, suppression flag, and
80-
* stack trace writable flag.
81+
* Creates a new {@code NotImplementedException} with the specified error message, cause,
82+
* suppression flag, and stack trace writable flag.
8183
*
8284
* @param message the error message associated with this
8385
* exception

devkit-core/src/main/resources/logback.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
-->
1818

1919
<configuration>
20-
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
21-
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
20+
<property name="COLOURFUL_OUTPUT"
21+
value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
22+
<property name="STANDARD_OUTPUT"
23+
value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
2224

2325
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
2426
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

devkit-utils/src/main/java/com/onixbyte/devkit/utils/AesUtil.java

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

3636
/**
37-
* {@link AesUtil} can help you encrypt and decrypt data with specified secret by AES algorithm.
37+
* The {@link AesUtil} class provides utility methods for encrypting and decrypting data using the
38+
* AES algorithm. This class supports both byte array and string data, and uses a specified secret
39+
* key for encryption and decryption.
40+
* <p>
41+
* The utility methods in this class are useful for scenarios where data needs to be securely
42+
* encrypted and decrypted.
43+
* </p>
44+
*
45+
* <p><b>Example usage:</b></p>
46+
* <pre>
47+
* {@code
48+
* // Encrypting and decrypting byte array data
49+
* byte[] secretKey = "43f72073956d4c81".getBytes(StandardCharsets.UTF_8);
50+
* byte[] data = "Hello World".getBytes(StandardCharsets.UTF_8);
51+
* byte[] encryptedData = AesUtil.encrypt(data, secretKey);
52+
* byte[] decryptedData = AesUtil.decrypt(encryptedData, secretKey);
53+
* System.out.println(new String(decryptedData, StandardCharsets.UTF_8)); // Output: Hello World
54+
*
55+
* // Encrypting and decrypting string data
56+
* String secret = "43f72073956d4c81";
57+
* String encryptedString = AesUtil.encrypt("Hello World", secret);
58+
* String decryptedString = AesUtil.decrypt(encryptedString, secret);
59+
* System.out.println(decryptedString); // Output: Hello World
60+
*
61+
* // Generating a random secret key
62+
* String randomSecret = AesUtil.generateRandomSecret();
63+
* System.out.println(randomSecret); // Output: A ramdomly generated 16-character long secret
64+
* }
65+
* </pre>
3866
*
3967
* @author hubin@baomidou
4068
* @version 1.1.0
@@ -54,7 +82,7 @@ public static byte[] encrypt(byte[] data, byte[] secret) {
5482
try {
5583
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
5684
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
57-
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(secret));
85+
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(secret)); // set IV to secret
5886
return cipher.doFinal(data);
5987
} catch (NoSuchAlgorithmException | NoSuchPaddingException | UnsupportedOperationException |
6088
InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException |
@@ -78,7 +106,7 @@ public static byte[] decrypt(byte[] data, byte[] secret) {
78106
try {
79107
var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES);
80108
var cipher = Cipher.getInstance(AES_CBC_CIPHER);
81-
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(secret));
109+
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(secret)); // set IV to secret
82110
return cipher.doFinal(data);
83111
} catch (NoSuchAlgorithmException | NoSuchPaddingException |
84112
UnsupportedOperationException | InvalidKeyException |

devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,25 @@
2222
import java.util.function.BooleanSupplier;
2323

2424
/**
25-
* A util for boolean calculations.
25+
* The {@link BoolUtil} class provides utility methods for boolean calculations.
26+
* This class offers methods to perform logical operations such as AND, OR, and NOT on boolean values.
27+
* <p>
28+
* The utility methods in this class are useful for scenarios where multiple boolean values need to be
29+
* evaluated together, and for simplifying complex boolean expressions.
30+
* </p>
31+
*
32+
* <p><b>Example usage:</b></p>
33+
* <pre>
34+
* {@code
35+
* boolean result1 = BoolUtil.and(true, true, false); // false
36+
* boolean result2 = BoolUtil.or(true, false, false); // true
37+
* boolean result3 = BoolUtil.not(false); // true
38+
* }
39+
* </pre>
2640
*
27-
* @author shaoxinke
41+
* @author zihluwang
2842
* @version 1.6.2
43+
* @since 1.6.2
2944
*/
3045
public final class BoolUtil {
3146

devkit-utils/src/main/java/com/onixbyte/devkit/utils/BranchUtil.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
* <p>
3333
* <b>Example:</b>
3434
* <pre>
35-
* // If you want to simplify an if (exp1 || exp2), you can use the
36-
* // following code:
35+
* // If you want to simplify an if (exp1 || exp2), you can use the following code:
3736
* String r1 = BranchUtil.or(1 == 1, 2 == 1)
3837
* .handle(() -> "1 is equal to 1 or 2 is equal to 1.");
3938
*
@@ -49,8 +48,7 @@
4948
* }, () -> {
5049
* // do something
5150
* });
52-
* // If you only need an if branch, you can remove the second Supplier
53-
* // instance.
51+
* // If you only need an if branch, you can remove the second Supplier instance.
5452
*
5553
* // To check if all boolean expressions are true, use the 'and' method:
5654
* BranchUtil.and(1 == 1, 2 == 1)

devkit-utils/src/main/java/com/onixbyte/devkit/utils/HashUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
* The above examples demonstrate how to use the {@code HashUtil} class to calculate hash values
5656
* for a given string using different algorithms.
5757
* <p>
58-
* <b>Note:</b>
59-
* The hash functions provided by the HashUtil class are one-way hash functions, meaning the
58+
* The hash functions provided by the {@link HashUtil} are one-way hash functions, meaning the
6059
* original data cannot be retrieved from the hash value. These hash functions are commonly used
6160
* for data integrity checks and password storage, but they should not be used for
6261
* encryption purposes.

devkit-utils/src/main/java/com/onixbyte/devkit/utils/MapUtil.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,61 @@
2424
import java.util.Optional;
2525

2626
/**
27-
* {@code MapUtil} is a utility class that provides methods for converting objects to maps and maps
28-
* to objects.
27+
* The {@link MapUtil} class provides utility methods for converting between objects and maps.
28+
* This class leverages the {@link ObjectMapAdapter} interface to perform the conversions.
2929
* <p>
30-
* Note: Since version 1.4.2, this util class removed reflection API and transferred to a safer API.
31-
* Please see documentation for more information.
30+
* The utility methods in this class are useful for scenarios where objects need to be represented as maps for
31+
* serialization, deserialization, or other purposes.
32+
* </p>
33+
*
34+
* <p><b>Example usage:</b></p>
35+
* <pre>
36+
* {@code
37+
* public class User {
38+
* private String name;
39+
* private int age;
40+
*
41+
* // getters and setters
42+
* }
43+
*
44+
* public class UserMapAdapter implements ObjectMapAdapter<User> {
45+
* @Override
46+
* public Map<String, Object> toMap(User user) {
47+
* Map<String, Object> map = new HashMap<>();
48+
* map.put("name", user.getName());
49+
* map.put("age", user.getAge());
50+
* return map;
51+
* }
52+
*
53+
* @Override
54+
* public User fromMap(Map<String, Object> map) {
55+
* User user = new User();
56+
* user.setName((String) map.get("name"));
57+
* user.setAge((Integer) map.get("age"));
58+
* return user;
59+
* }
60+
* }
61+
*
62+
* public class Example {
63+
* public static void main(String[] args) {
64+
* User user = new User();
65+
* user.setName("John");
66+
* user.setAge(30);
67+
*
68+
* UserMapAdapter adapter = new UserMapAdapter();
69+
*
70+
* // Convert object to map
71+
* Map<String, Object> userMap = MapUtil.objectToMap(user, adapter);
72+
* System.out.println(userMap); // Output: {name=John, age=30}
73+
*
74+
* // Convert map to object
75+
* User newUser = MapUtil.mapToObject(userMap, adapter);
76+
* System.out.println(newUser.getName()); // Output: John
77+
* System.out.println(newUser.getAge()); // Output: 30
78+
* }
79+
* }
80+
* }
81+
* </pre>
3282
*
3383
* @author zihluwang
3484
* @version 1.7.0

devkit-utils/src/main/java/com/onixbyte/devkit/utils/ObjectMapAdapter.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,44 @@
2020
import java.util.Map;
2121

2222
/**
23-
* Adapts an Object to a Map, making conversion between Map and Object much more safe.
23+
* The {@link ObjectMapAdapter} interface provides methods to convert between objects and maps.
24+
* This interface is useful for scenarios where objects need to be represented as maps for
25+
* serialization, deserialization, or other purposes.
2426
*
25-
* @param <T> field type
27+
* <p>Implementations of this interface should provide the logic to convert an object of type {@code T}
28+
* to a {@link Map} and vice versa.</p>
29+
*
30+
* <p><b>Example usage:</b></p>
31+
* <pre>
32+
* {@code
33+
* public class User {
34+
* private String name;
35+
* private int age;
36+
*
37+
* // getters and setters
38+
* }
39+
*
40+
* public class UserMapAdapter implements ObjectMapAdapter<User> {
41+
* @Override
42+
* public Map<String, Object> toMap(User user) {
43+
* Map<String, Object> map = new HashMap<>();
44+
* map.put("name", user.getName());
45+
* map.put("age", user.getAge());
46+
* return map;
47+
* }
48+
*
49+
* @Override
50+
* public User fromMap(Map<String, Object> map) {
51+
* User user = new User();
52+
* user.setName((String) map.get("name"));
53+
* user.setAge((Integer) map.get("age"));
54+
* return user;
55+
* }
56+
* }
57+
* }
58+
* </pre>
59+
*
60+
* @param <T> the type of the object to be converted
2661
* @author zihluwang
2762
* @version 1.7.0
2863
* @since 1.4.2
@@ -40,7 +75,7 @@ public interface ObjectMapAdapter<T> {
4075
/**
4176
* Convert a Map to an object.
4277
*
43-
* @param map the map that will be converted to Object
78+
* @param map the map that will be converted to an object
4479
* @return the object that is converted from the Map
4580
*/
4681
T toObject(Map<String, Object> map);

devkit-utils/src/main/java/com/onixbyte/devkit/utils/package-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* dev-utils, which contains a collection of common utility classes commonly
2323
* used in all Java Application development.
2424
*
25-
* @author Zihlu Wang
2625
* @since 1.0.0
2726
*/
2827
package com.onixbyte.devkit.utils;

devkit-utils/src/main/resources/logback.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
-->
1818

1919
<configuration>
20-
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
21-
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
20+
<property name="COLOURFUL_OUTPUT"
21+
value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
22+
<property name="STANDARD_OUTPUT"
23+
value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
2224

2325
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
2426
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

0 commit comments

Comments
 (0)