From 225356d92ad6f6ad8969a8c448b371054f8f4466 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Sun, 29 Dec 2024 12:54:13 +0800 Subject: [PATCH 1/7] style: removed contact information in javadoc --- .../core/exceptions/NotImplementedException.java | 10 ---------- .../devkit/core/exceptions/package-info.java | 1 - .../com/onixbyte/devkit/core/package-info.java | 14 -------------- .../java/com/onixbyte/devkit/package-info.java | 15 --------------- 4 files changed, 40 deletions(-) diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java index 3c88b7c..956340d 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java @@ -33,16 +33,6 @@ * This feature will be implemented in a future release."""); * } * - * Contact - * * * @author Zihlu Wang * @version 1.1.0 diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java index dd116ca..9d1b883 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java @@ -18,7 +18,6 @@ /** * This package contains commonly used exceptions will be used in JDevKit. * - * @author Zihlu Wang * @since 1.0.0 */ package com.onixbyte.devkit.core.exceptions; \ No newline at end of file diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java index 2300e53..6e74d24 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java @@ -23,20 +23,6 @@ *

* JDevKit is designed to be modular, and other specific feature modules within * the library may rely on these exceptions from the core package. - *

- * For more information and the latest version of JDevKit, please visit our - * website codecrafters.org.cn. - *

- * Contact - *

* * @since 1.0.0 */ diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java b/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java index 8cadf32..ea3e173 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java @@ -21,21 +21,6 @@ * enhance productivity. This package serves as the root package for several * modules, containing {@code devkit-core}, {@code guid} and {@code dev-utils} * module. - *

- * For more information and the latest version of JDevKit, please visit our - * website codecrafters.org.cn. - * - *

- * Contact - *

* * @since 1.0.0 */ From 566a960c14357f3d277ff39ceaa6686b8279ff63 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Sun, 29 Dec 2024 13:01:43 +0800 Subject: [PATCH 2/7] ci: added step to display all outputs --- .github/workflows/github-packages-publish.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/github-packages-publish.yml b/.github/workflows/github-packages-publish.yml index 74d97d4..1032b73 100644 --- a/.github/workflows/github-packages-publish.yml +++ b/.github/workflows/github-packages-publish.yml @@ -64,5 +64,8 @@ jobs: # Overwrite artefactVersion with tag name run: ./gradlew build -PartefactVersion=${{ github.event.release.tag_name }} + - name: List Output Items + run: ls -l ./**/build/libs + - name: Publish to Maven Central run: ./gradlew publish From a85c562b66c91dd10079b20c25d71066fcd39845 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Sat, 18 Jan 2025 14:06:13 +0800 Subject: [PATCH 3/7] docs: added docs --- .../exceptions/NotImplementedException.java | 18 +++--- devkit-core/src/main/resources/logback.xml | 6 +- .../com/onixbyte/devkit/utils/AesUtil.java | 34 ++++++++++- .../com/onixbyte/devkit/utils/BoolUtil.java | 19 +++++- .../com/onixbyte/devkit/utils/BranchUtil.java | 6 +- .../com/onixbyte/devkit/utils/HashUtil.java | 3 +- .../com/onixbyte/devkit/utils/MapUtil.java | 58 +++++++++++++++++-- .../devkit/utils/ObjectMapAdapter.java | 41 ++++++++++++- .../onixbyte/devkit/utils/package-info.java | 1 - devkit-utils/src/main/resources/logback.xml | 6 +- .../java/com/onixbyte/guid/GuidCreator.java | 30 ++++++++-- .../guid/exceptions/TimingException.java | 26 ++++----- .../guid/exceptions/package-info.java | 26 ++++----- .../guid/impl/SnowflakeGuidCreator.java | 49 +++++++--------- .../java/com/onixbyte/guid/package-info.java | 8 +-- .../java/com/onixbyte/security/KeyLoader.java | 24 +++++++- .../exception/KeyLoadingException.java | 20 ++++++- .../devkit/utils/unsafe/ReflectMapUtil.java | 45 +++++++++++--- .../src/main/resources/logback.xml | 6 +- .../onixbyte/nums/PercentileCalculator.java | 13 +++-- .../onixbyte/nums/model/QuartileBounds.java | 20 ++++--- .../autoconfiguration/PropertyGuard.java | 45 +++++++------- 22 files changed, 357 insertions(+), 147 deletions(-) diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java index 956340d..d3df10d 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java @@ -18,12 +18,13 @@ package com.onixbyte.devkit.core.exceptions; /** - * The {@code NotImplementedException} class is a custom runtime exception that represents a situation where a - * particular method or functionality is not implemented or is currently unavailable in the codebase. + * The {@code NotImplementedException} class is a custom runtime exception that represents a + * situation where a particular method or functionality is not implemented or is currently + * unavailable in the codebase. *

- * This exception is typically thrown when developers need to indicate that a specific part of the code is incomplete - * or requires further implementation. It serves as a placeholder to highlight unfinished sections of the application - * during development and testing phases. + * This exception is typically thrown when developers need to indicate that a specific part of the + * code is incomplete or requires further implementation. It serves as a placeholder to highlight + * unfinished sections of the application during development and testing phases. *

* Usage Example: *

@@ -57,7 +58,8 @@ public NotImplementedException(String message) {
     }
 
     /**
-     * Creates a new {@code NotImplementedException} with the specified error message and a cause for this exception.
+     * Creates a new {@code NotImplementedException} with the specified error message and a cause
+     * for this exception.
      *
      * @param message the error message associated with this exception
      * @param cause   the cause of this exception
@@ -76,8 +78,8 @@ public NotImplementedException(Throwable cause) {
     }
 
     /**
-     * Creates a new {@code NotImplementedException} with the specified error message, cause, suppression flag, and
-     * stack trace writable flag.
+     * Creates a new {@code NotImplementedException} with the specified error message, cause,
+     * suppression flag, and stack trace writable flag.
      *
      * @param message            the error message associated with this
      *                           exception
diff --git a/devkit-core/src/main/resources/logback.xml b/devkit-core/src/main/resources/logback.xml
index 6d26440..df2a9f0 100644
--- a/devkit-core/src/main/resources/logback.xml
+++ b/devkit-core/src/main/resources/logback.xml
@@ -17,8 +17,10 @@
   -->
 
 
-    
-    
+    
+    
 
     
     
diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/AesUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/AesUtil.java
index 1c47120..3f1ffa2 100644
--- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/AesUtil.java
+++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/AesUtil.java
@@ -34,7 +34,35 @@
 import java.util.UUID;
 
 /**
- * {@link AesUtil} can help you encrypt and decrypt data with specified secret by AES algorithm.
+ * The {@link AesUtil} class provides utility methods for encrypting and decrypting data using the
+ * AES algorithm. This class supports both byte array and string data, and uses a specified secret
+ * key for encryption and decryption.
+ * 

+ * The utility methods in this class are useful for scenarios where data needs to be securely + * encrypted and decrypted. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * // Encrypting and decrypting byte array data
+ * byte[] secretKey = "43f72073956d4c81".getBytes(StandardCharsets.UTF_8);
+ * byte[] data = "Hello World".getBytes(StandardCharsets.UTF_8);
+ * byte[] encryptedData = AesUtil.encrypt(data, secretKey);
+ * byte[] decryptedData = AesUtil.decrypt(encryptedData, secretKey);
+ * System.out.println(new String(decryptedData, StandardCharsets.UTF_8)); // Output: Hello World
+ * 
+ * // Encrypting and decrypting string data
+ * String secret = "43f72073956d4c81";
+ * String encryptedString = AesUtil.encrypt("Hello World", secret);
+ * String decryptedString = AesUtil.decrypt(encryptedString, secret);
+ * System.out.println(decryptedString); // Output: Hello World
+ * 
+ * // Generating a random secret key
+ * String randomSecret = AesUtil.generateRandomSecret();
+ * System.out.println(randomSecret); // Output: A ramdomly generated 16-character long secret 
+ * }
+ * 
* * @author hubin@baomidou * @version 1.1.0 @@ -54,7 +82,7 @@ public static byte[] encrypt(byte[] data, byte[] secret) { try { var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES); var cipher = Cipher.getInstance(AES_CBC_CIPHER); - cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(secret)); + cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(secret)); // set IV to secret return cipher.doFinal(data); } catch (NoSuchAlgorithmException | NoSuchPaddingException | UnsupportedOperationException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | @@ -78,7 +106,7 @@ public static byte[] decrypt(byte[] data, byte[] secret) { try { var secretKeySpec = new SecretKeySpec(new SecretKeySpec(secret, AES).getEncoded(), AES); var cipher = Cipher.getInstance(AES_CBC_CIPHER); - cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(secret)); + cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(secret)); // set IV to secret return cipher.doFinal(data); } catch (NoSuchAlgorithmException | NoSuchPaddingException | UnsupportedOperationException | InvalidKeyException | diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java index c97cb76..70e0c17 100644 --- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java @@ -22,10 +22,25 @@ import java.util.function.BooleanSupplier; /** - * A util for boolean calculations. + * The {@link BoolUtil} class provides utility methods for boolean calculations. + * This class offers methods to perform logical operations such as AND, OR, and NOT on boolean values. + *

+ * The utility methods in this class are useful for scenarios where multiple boolean values need to be + * evaluated together, and for simplifying complex boolean expressions. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * boolean result1 = BoolUtil.and(true, true, false); // false
+ * boolean result2 = BoolUtil.or(true, false, false); // true
+ * boolean result3 = BoolUtil.not(false); // true
+ * }
+ * 
* - * @author shaoxinke + * @author zihluwang * @version 1.6.2 + * @since 1.6.2 */ public final class BoolUtil { diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BranchUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BranchUtil.java index 0d339d6..755d92e 100644 --- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BranchUtil.java +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BranchUtil.java @@ -32,8 +32,7 @@ *

* Example: *

- * // If you want to simplify an if (exp1 || exp2), you can use the
- * // following code:
+ * // If you want to simplify an if (exp1 || exp2), you can use the following code:
  * String r1 = BranchUtil.or(1 == 1, 2 == 1)
  *     .handle(() -> "1 is equal to 1 or 2 is equal to 1.");
  *
@@ -49,8 +48,7 @@
  *     }, () -> {
  *         // do something
  *     });
- * // If you only need an if branch, you can remove the second Supplier
- * // instance.
+ * // If you only need an if branch, you can remove the second Supplier instance.
  *
  * // To check if all boolean expressions are true, use the 'and' method:
  * BranchUtil.and(1 == 1, 2 == 1)
diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/HashUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/HashUtil.java
index 2c24283..995ea42 100644
--- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/HashUtil.java
+++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/HashUtil.java
@@ -55,8 +55,7 @@
  * The above examples demonstrate how to use the {@code HashUtil} class to calculate hash values
  * for a given string using different algorithms.
  * 

- * Note: - * The hash functions provided by the HashUtil class are one-way hash functions, meaning the + * The hash functions provided by the {@link HashUtil} are one-way hash functions, meaning the * original data cannot be retrieved from the hash value. These hash functions are commonly used * for data integrity checks and password storage, but they should not be used for * encryption purposes. diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/MapUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/MapUtil.java index a81e8cf..2356b9b 100644 --- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/MapUtil.java +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/MapUtil.java @@ -24,11 +24,61 @@ import java.util.Optional; /** - * {@code MapUtil} is a utility class that provides methods for converting objects to maps and maps - * to objects. + * The {@link MapUtil} class provides utility methods for converting between objects and maps. + * This class leverages the {@link ObjectMapAdapter} interface to perform the conversions. *

- * Note: Since version 1.4.2, this util class removed reflection API and transferred to a safer API. - * Please see documentation for more information. + * The utility methods in this class are useful for scenarios where objects need to be represented as maps for + * serialization, deserialization, or other purposes. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * public class User {
+ *     private String name;
+ *     private int age;
+ *     
+ *     // getters and setters
+ * }
+ * 
+ * public class UserMapAdapter implements ObjectMapAdapter {
+ *     @Override
+ *     public Map toMap(User user) {
+ *         Map map = new HashMap<>();
+ *         map.put("name", user.getName());
+ *         map.put("age", user.getAge());
+ *         return map;
+ *     }
+ * 
+ *     @Override
+ *     public User fromMap(Map map) {
+ *         User user = new User();
+ *         user.setName((String) map.get("name"));
+ *         user.setAge((Integer) map.get("age"));
+ *         return user;
+ *     }
+ * }
+ * 
+ * public class Example {
+ *     public static void main(String[] args) {
+ *         User user = new User();
+ *         user.setName("John");
+ *         user.setAge(30);
+ *         
+ *         UserMapAdapter adapter = new UserMapAdapter();
+ *         
+ *         // Convert object to map
+ *         Map userMap = MapUtil.objectToMap(user, adapter);
+ *         System.out.println(userMap); // Output: {name=John, age=30}
+ *         
+ *         // Convert map to object
+ *         User newUser = MapUtil.mapToObject(userMap, adapter);
+ *         System.out.println(newUser.getName()); // Output: John
+ *         System.out.println(newUser.getAge());  // Output: 30
+ *     }
+ * }
+ * }
+ * 
* * @author zihluwang * @version 1.7.0 diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ObjectMapAdapter.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ObjectMapAdapter.java index 49d51b1..c13eb1d 100644 --- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ObjectMapAdapter.java +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ObjectMapAdapter.java @@ -20,9 +20,44 @@ import java.util.Map; /** - * Adapts an Object to a Map, making conversion between Map and Object much more safe. + * The {@link ObjectMapAdapter} interface provides methods to convert between objects and maps. + * This interface is useful for scenarios where objects need to be represented as maps for + * serialization, deserialization, or other purposes. * - * @param field type + *

Implementations of this interface should provide the logic to convert an object of type {@code T} + * to a {@link Map} and vice versa.

+ * + *

Example usage:

+ *
+ * {@code
+ * public class User {
+ *     private String name;
+ *     private int age;
+ *     
+ *     // getters and setters
+ * }
+ * 
+ * public class UserMapAdapter implements ObjectMapAdapter {
+ *     @Override
+ *     public Map toMap(User user) {
+ *         Map map = new HashMap<>();
+ *         map.put("name", user.getName());
+ *         map.put("age", user.getAge());
+ *         return map;
+ *     }
+ * 
+ *     @Override
+ *     public User fromMap(Map map) {
+ *         User user = new User();
+ *         user.setName((String) map.get("name"));
+ *         user.setAge((Integer) map.get("age"));
+ *         return user;
+ *     }
+ * }
+ * }
+ * 
+ * + * @param the type of the object to be converted * @author zihluwang * @version 1.7.0 * @since 1.4.2 @@ -40,7 +75,7 @@ public interface ObjectMapAdapter { /** * Convert a Map to an object. * - * @param map the map that will be converted to Object + * @param map the map that will be converted to an object * @return the object that is converted from the Map */ T toObject(Map map); diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/package-info.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/package-info.java index 526f806..dd546c4 100644 --- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/package-info.java +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/package-info.java @@ -22,7 +22,6 @@ * dev-utils, which contains a collection of common utility classes commonly * used in all Java Application development. * - * @author Zihlu Wang * @since 1.0.0 */ package com.onixbyte.devkit.utils; \ No newline at end of file diff --git a/devkit-utils/src/main/resources/logback.xml b/devkit-utils/src/main/resources/logback.xml index 6d26440..df2a9f0 100644 --- a/devkit-utils/src/main/resources/logback.xml +++ b/devkit-utils/src/main/resources/logback.xml @@ -17,8 +17,10 @@ --> - - + + diff --git a/guid/src/main/java/com/onixbyte/guid/GuidCreator.java b/guid/src/main/java/com/onixbyte/guid/GuidCreator.java index 078b031..c33eede 100644 --- a/guid/src/main/java/com/onixbyte/guid/GuidCreator.java +++ b/guid/src/main/java/com/onixbyte/guid/GuidCreator.java @@ -18,10 +18,33 @@ package com.onixbyte.guid; /** - * The {@code GuidCreator} is a generic interface for generating globally unique - * identifiers (GUIDs) of a specific type. + * The {@code GuidCreator} is a generic interface for generating globally unique identifiers (GUIDs) + * of a specific type. *

* The type of ID is determined by the class implementing this interface. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * public class StringGuidCreator implements GuidCreator {
+ *     private final AtomicLong counter = new AtomicLong();
+ *
+ *     @Override
+ *     public String nextId() {
+ *         return UUID.randomUUID().toString() + "-" + counter.incrementAndGet();
+ *     }
+ * }
+ *
+ * public class Example {
+ *     public static void main(String[] args) {
+ *         GuidCreator guidCreator = new StringGuidCreator();
+ *         String guid = guidCreator.nextId();
+ *         System.out.println("Generated GUID: " + guid);
+ *     }
+ * }
+ * }
+ * 
* * @param this represents the type of the Global Unique Identifier * @author Zihlu Wang @@ -32,9 +55,6 @@ public interface GuidCreator { /** * Generates and returns the next globally unique ID. - *

- * The exact implementation of how the globally unique ID is generated and - * returned will depend on the class implementing this method. * * @return the next globally unique ID */ diff --git a/guid/src/main/java/com/onixbyte/guid/exceptions/TimingException.java b/guid/src/main/java/com/onixbyte/guid/exceptions/TimingException.java index 7144723..461b76a 100644 --- a/guid/src/main/java/com/onixbyte/guid/exceptions/TimingException.java +++ b/guid/src/main/java/com/onixbyte/guid/exceptions/TimingException.java @@ -18,13 +18,12 @@ package com.onixbyte.guid.exceptions; /** - * The {@code TimingException} class represents an exception that is thrown - * when there is an error related to time sequence. + * The {@code TimingException} class represents an exception that is thrown when there is an error + * related to time sequence. *

- * Instances of TimingException can be created with or without a message and a - * cause. The message provides a description of the exception, while the cause - * represents the underlying cause of the exception and provides additional - * information about the error. + * Instances of TimingException can be created with or without a message and a cause. The message + * provides a description of the exception, while the cause represents the underlying cause of the + * exception and provides additional information about the error. * * @author Zihlu Wang * @since 1.0.0 @@ -32,15 +31,14 @@ public class TimingException extends RuntimeException { /** - * A custom exception that is thrown when there is an issue with timing or - * scheduling. + * A custom exception that is thrown when there is an issue with timing or scheduling. */ public TimingException() { } /** - * A custom exception that is thrown when there is an issue with timing or - * scheduling with customised error message. + * A custom exception that is thrown when there is an issue with timing or scheduling with + * customised error message. * * @param message customised message */ @@ -49,8 +47,8 @@ public TimingException(String message) { } /** - * A custom exception that is thrown when there is an issue with timing or - * scheduling with customised error message. + * A custom exception that is thrown when there is an issue with timing or scheduling with + * customised error message. * * @param message customised message * @param cause the cause of this exception @@ -60,8 +58,8 @@ public TimingException(String message, Throwable cause) { } /** - * A custom exception that is thrown when there is an issue with timing or - * scheduling with customised error message. + * A custom exception that is thrown when there is an issue with timing or scheduling with + * customised error message. * * @param cause the cause of this exception */ diff --git a/guid/src/main/java/com/onixbyte/guid/exceptions/package-info.java b/guid/src/main/java/com/onixbyte/guid/exceptions/package-info.java index 30736c6..30ceee8 100644 --- a/guid/src/main/java/com/onixbyte/guid/exceptions/package-info.java +++ b/guid/src/main/java/com/onixbyte/guid/exceptions/package-info.java @@ -16,25 +16,23 @@ */ /** - * This package contains the custom exception classes related to GUID - * generation. These exceptions are thrown when there are issues or errors - * during the generation or processing of global unique identifiers (GUIDs). + * This package contains the custom exception classes related to GUID generation. These exceptions + * are thrown when there are issues or errors during the generation or processing of global unique + * identifiers (GUIDs). *

- * The main exception class in this package is {@link - * com.onixbyte.guid.exceptions.TimingException}, which is a runtime - * exception and serves as the base exception for all other custom exceptions + * The main exception class in this package is {@link com.onixbyte.guid.exceptions.TimingException}, + * which is a runtime exception and serves as the base exception for all other custom exceptions * related to GUID generation. *

- * Custom exceptions in this package provide specific information about the - * type of error that occurred during GUID generation, making it easier for - * developers to handle and respond to different scenarios when dealing with - * GUIDs. They are designed to enhance the robustness and reliability of the - * GUID generation process by providing clear and meaningful error messages to + * Custom exceptions in this package provide specific information about the type of error that + * occurred during GUID generation, making it easier for developers to handle and respond to + * different scenarios when dealing with GUIDs. They are designed to enhance the robustness and + * reliability of the GUID generation process by providing clear and meaningful error messages to * the developers. *

- * Developers using the GUID generation module should be aware of the possible - * exceptions that can be thrown and handle them appropriately to ensure smooth - * operation and error handling in their applications. + * Developers using the GUID generation module should be aware of the possible exceptions that can + * be thrown and handle them appropriately to ensure smooth operation and error handling in + * their applications. * * @since 1.0.0 */ diff --git a/guid/src/main/java/com/onixbyte/guid/impl/SnowflakeGuidCreator.java b/guid/src/main/java/com/onixbyte/guid/impl/SnowflakeGuidCreator.java index 2c40a5e..f6ef85a 100644 --- a/guid/src/main/java/com/onixbyte/guid/impl/SnowflakeGuidCreator.java +++ b/guid/src/main/java/com/onixbyte/guid/impl/SnowflakeGuidCreator.java @@ -24,10 +24,9 @@ import java.time.ZoneId; /** - * The {@code SnowflakeGuidCreator} generates unique identifiers using the - * Snowflake algorithm, which combines a timestamp, worker ID, and data centre - * ID to create 64-bit long integers. The bit distribution for the generated - * IDs is as follows: + * The {@code SnowflakeGuidCreator} generates unique identifiers using the Snowflake algorithm, + * which combines a timestamp, worker ID, and data centre ID to create 64-bit long integers. The bit + * distribution for the generated IDs is as follows: *

    *
  • 1 bit for sign
  • *
  • 41 bits for timestamp (in milliseconds)
  • @@ -36,11 +35,10 @@ *
  • 12 bits for sequence number (per millisecond)
  • *
*

- * When initializing a {@link SnowflakeGuidCreator}, you must provide the - * worker ID and data centre ID, ensuring they are within the valid range - * defined by the bit size. The generator maintains an internal sequence number - * that increments for IDs generated within the same millisecond. If the system - * clock moves backward, an exception is thrown to prevent generating IDs with + * When initializing a {@link SnowflakeGuidCreator}, you must provide the worker ID and data centre + * ID, ensuring they are within the valid range defined by the bit size. The generator maintains an + * internal sequence number that increments for IDs generated within the same millisecond. If the + * system clock moves backward, an exception is thrown to prevent generating IDs with * repeated timestamps. * * @author Zihlu Wang @@ -50,8 +48,8 @@ public final class SnowflakeGuidCreator implements GuidCreator { /** - * Constructs a SnowflakeGuidGenerator with the default start epoch and - * custom worker ID, data centre ID. + * Constructs a SnowflakeGuidGenerator with the default start epoch and custom worker ID, data + * centre ID. * * @param dataCentreId the data centre ID (between 0 and 31) * @param workerId the worker ID (between 0 and 31) @@ -61,16 +59,13 @@ public SnowflakeGuidCreator(long dataCentreId, long workerId) { } /** - * Constructs a SnowflakeGuidGenerator with a custom epoch, worker ID, and - * data centre ID. + * Constructs a SnowflakeGuidGenerator with a custom epoch, worker ID, and data centre ID. * * @param dataCentreId the data centre ID (between 0 and 31) * @param workerId the worker ID (between 0 and 31) - * @param startEpoch the custom epoch timestamp (in milliseconds) to - * start generating IDs from - * @throws IllegalArgumentException if the start epoch is greater than the - * current timestamp, or if the worker ID - * or data centre ID is out of range + * @param startEpoch the custom epoch timestamp (in milliseconds) to start generating IDs from + * @throws IllegalArgumentException if the start epoch is greater than the current timestamp, + * or if the worker ID or data centre ID is out of range */ public SnowflakeGuidCreator(long dataCentreId, long workerId, long startEpoch) { if (startEpoch > currentTimestamp()) { @@ -98,37 +93,37 @@ public SnowflakeGuidCreator(long dataCentreId, long workerId, long startEpoch) { * Generates the next unique ID. * * @return the generated unique ID - * @throws TimingException if the system clock moves backwards, - * indicating an invalid sequence of timestamps. + * @throws TimingException if the system clock moves backwards, indicating an invalid sequence + * of timestamps. */ @Override public synchronized Long nextId() { var timestamp = currentTimestamp(); - // If the current time is less than the timestamp of the last ID generation, it means that the system clock - // has been set back and an exception should be thrown. + // if the current time is less than the timestamp of the last ID generation, it means that + // the system clock has been set back and an exception should be thrown if (timestamp < lastTimestamp) { throw new TimingException("Clock moved backwards. Refusing to generate id for %d milliseconds" .formatted(lastTimestamp - timestamp)); } - // If generated at the same time, perform intra-millisecond sequences + // if generated at the same time, perform intra-millisecond sequences long sequenceBits = 12L; if (lastTimestamp == timestamp) { long sequenceMask = ~(-1L << sequenceBits); sequence = (sequence + 1) & sequenceMask; - // Sequence overflow in milliseconds + // sequence overflow in milliseconds if (sequence == 0) { - // Block to the next millisecond, get a new timestamp + // block to the next millisecond, get a new timestamp timestamp = awaitToNextMillis(lastTimestamp); } } - // Timestamp change, sequence reset in milliseconds + // timestamp change, sequence reset in milliseconds else { sequence = 0L; } - // Timestamp of last ID generation + // timestamp of last ID generation lastTimestamp = timestamp; // shifted and put together by or operations to form a 64-bit ID diff --git a/guid/src/main/java/com/onixbyte/guid/package-info.java b/guid/src/main/java/com/onixbyte/guid/package-info.java index 9dc81bc..2828873 100644 --- a/guid/src/main/java/com/onixbyte/guid/package-info.java +++ b/guid/src/main/java/com/onixbyte/guid/package-info.java @@ -16,12 +16,10 @@ */ /** - * The package provides a set of tools for generating globally unique - * identifiers (GUIDs). + * The package provides a set of tools for generating globally unique identifiers (GUIDs). *

- * The goal of this library is to provide an efficient, reliable way to - * generate globally unique identifiers without requiring any specific - * environment or configuration. + * The goal of this library is to provide an efficient, reliable way to generate globally unique + * identifiers without requiring any specific environment or configuration. *

* Key features include: *

    diff --git a/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java b/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java index 4a4b3e1..9de2a05 100644 --- a/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java +++ b/key-pair-loader/src/main/java/com/onixbyte/security/KeyLoader.java @@ -30,7 +30,29 @@ import java.util.Base64; /** - * KeyLoader can load key pairs from PEM formated content. + * The {@code KeyLoader} class provides utility methods for loading ECDSA keys from PEM-formatted + * key text. This class supports loading both private and public keys. + *

    + * The utility methods in this class are useful for scenarios where ECDSA keys need to be loaded + * from PEM-formatted strings for cryptographic operations. + *

    + * + *

    Example usage:

    + *
    + * {@code
    + * String pemPrivateKey = """
    + *                        -----BEGIN PRIVATE KEY-----
    + *                        ...
    + *                        -----END PRIVATE KEY-----""";
    + * ECPrivateKey privateKey = KeyLoader.loadEcdsaPrivateKey(pemPrivateKey);
    + * 
    + * String pemPublicKey = """
    + *                       -----BEGIN PUBLIC KEY-----
    + *                       ...
    + *                       -----END PUBLIC KEY-----""";
    + * ECPublicKey publicKey = KeyLoader.loadEcdsaPublicKey(pemPublicKey);
    + * }
    + * 
    * * @author zihluwang * @version 1.6.0 diff --git a/key-pair-loader/src/main/java/com/onixbyte/security/exception/KeyLoadingException.java b/key-pair-loader/src/main/java/com/onixbyte/security/exception/KeyLoadingException.java index 2c36b10..49715d8 100644 --- a/key-pair-loader/src/main/java/com/onixbyte/security/exception/KeyLoadingException.java +++ b/key-pair-loader/src/main/java/com/onixbyte/security/exception/KeyLoadingException.java @@ -18,7 +18,25 @@ package com.onixbyte.security.exception; /** - * {@code KeyLoadingException} is an exception indicating an error occurred while loading a key. + * The {@code KeyLoadingException} class represents an exception that is thrown when there is an error + * loading cryptographic keys. This exception can be used to indicate various issues such as invalid key + * specifications, unsupported key algorithms, or other key loading errors. + *

    + * This class extends {@link RuntimeException}, allowing it to be thrown without being declared in a method's + * {@code throws} clause. + *

    + * + *

    Example usage:

    + *
    + * {@code
    + * try {
    + *     ECPrivateKey privateKey = KeyLoader.loadEcdsaPrivateKey(pemPrivateKey);
    + * } catch (KeyLoadingException e) {
    + *     // Handle the exception
    + *     e.printStackTrace();
    + * }
    + * }
    + * 
    * * @author zihluwang * @version 1.6.0 diff --git a/map-util-unsafe/src/main/java/com/onixbyte/devkit/utils/unsafe/ReflectMapUtil.java b/map-util-unsafe/src/main/java/com/onixbyte/devkit/utils/unsafe/ReflectMapUtil.java index daa84c5..48dc048 100644 --- a/map-util-unsafe/src/main/java/com/onixbyte/devkit/utils/unsafe/ReflectMapUtil.java +++ b/map-util-unsafe/src/main/java/com/onixbyte/devkit/utils/unsafe/ReflectMapUtil.java @@ -24,10 +24,43 @@ import java.util.Map; /** - * {@code MapUtil} is a utility class that provides methods for converting objects to maps and - * maps to objects. + * The {@link ReflectMapUtil} class provides utility methods for converting between objects and maps + * using reflection. This class allows for dynamic mapping of object fields to map entries and + * vice versa. *

    - * It also provides methods for getting and setting field values using reflection. + * The utility methods in this class are useful for scenarios where objects need to be represented + * as maps for serialization, deserialization, or other purposes, and where the structure of the + * objects is not known at compile time. + *

    + * + *

    Example usage:

    + *
    + * {@code
    + * public class User {
    + *     private String name;
    + *     private int age;
    + *     
    + *     // getters and setters
    + * }
    + * 
    + * public class Example {
    + *     public static void main(String[] args) throws IllegalAccessException {
    + *         User user = new User();
    + *         user.setName("John");
    + *         user.setAge(30);
    + *         
    + *         // Convert object to map
    + *         Map userMap = ReflectMapUtil.objectToMap(user);
    + *         System.out.println(userMap); // Output: {name=John, age=30}
    + *         
    + *         // Convert map to object
    + *         User newUser = ReflectMapUtil.mapToObject(userMap, User.class);
    + *         System.out.println(newUser.getName()); // Output: John
    + *         System.out.println(newUser.getAge());  // Output: 30
    + *     }
    + * }
    + * }
    + * 
    * * @author zihluwang * @version 1.4.2 @@ -131,10 +164,8 @@ public static T mapToObject(Map map, Class requiredType) * @param the type of the field value * @return the value of the field in the object, or null if the field does * not exist or cannot be accessed - * @throws IllegalAccessException if an error occurs while accessing the - * field - * @throws InvocationTargetException if an error occurs while invoking the - * field getter method + * @throws IllegalAccessException if an error occurs while accessing the field + * @throws InvocationTargetException if an error occurs while invoking the field getter method * @throws NoSuchMethodException if the specified getter is not present */ public static T getFieldValue(Object obj, String fieldName, Class fieldType) diff --git a/map-util-unsafe/src/main/resources/logback.xml b/map-util-unsafe/src/main/resources/logback.xml index 1cf5a50..41cf3b5 100644 --- a/map-util-unsafe/src/main/resources/logback.xml +++ b/map-util-unsafe/src/main/resources/logback.xml @@ -17,8 +17,10 @@ --> - - + + diff --git a/num4j/src/main/java/com/onixbyte/nums/PercentileCalculator.java b/num4j/src/main/java/com/onixbyte/nums/PercentileCalculator.java index 6ae9378..b28f397 100644 --- a/num4j/src/main/java/com/onixbyte/nums/PercentileCalculator.java +++ b/num4j/src/main/java/com/onixbyte/nums/PercentileCalculator.java @@ -21,8 +21,8 @@ import java.util.List; /** - * A utility class that provides methods for calculating percentiles and interquartile range (IQR) bounds - * for a dataset. + * A utility class that provides methods for calculating percentiles and interquartile range (IQR) + * bounds for a dataset. *

    * This class contains static methods to: *

      @@ -57,12 +57,13 @@ private PercentileCalculator() { /** * Calculates the specified percentile from a list of values. *

      - * This method takes a list of double values and calculates the given percentile using linear interpolation between - * the two closest ranks. The list is first sorted in ascending order, and the specified percentile is - * then calculated. + * This method takes a list of double values and calculates the given percentile using linear + * interpolation between the two closest ranks. The list is first sorted in ascending order, + * and the specified percentile is then calculated. * * @param values a list of {@code Double} values from which the percentile is calculated. - * @param percentile a {@code Double} representing the percentile to be calculated (e.g., 50.0 for the median) + * @param percentile a {@code Double} representing the percentile to be calculated (e.g., 50.0 + * for the median) * @return a {@code Double} value representing the calculated percentile */ public static Double calculatePercentile(List values, Double percentile) { diff --git a/num4j/src/main/java/com/onixbyte/nums/model/QuartileBounds.java b/num4j/src/main/java/com/onixbyte/nums/model/QuartileBounds.java index 3233e61..fa5c85f 100644 --- a/num4j/src/main/java/com/onixbyte/nums/model/QuartileBounds.java +++ b/num4j/src/main/java/com/onixbyte/nums/model/QuartileBounds.java @@ -20,9 +20,9 @@ /** * A record representing the quartile bounds of a dataset. *

      - * This class encapsulates the lower and upper bounds of a dataset, which are typically used for detecting outliers in - * the data. The bounds are calculated based on the interquartile range (IQR) of the dataset. Values below the lower - * bound or above the upper bound may be considered outliers. + * This class encapsulates the lower and upper bounds of a dataset, which are typically used for + * detecting outliers in the data. The bounds are calculated based on the interquartile range (IQR) + * of the dataset. Values below the lower bound or above the upper bound may be considered outliers. *

      * Quartile bounds consist of: *

        @@ -52,8 +52,8 @@ public record QuartileBounds( /** * Creates a new {@link Builder} instance for building a {@code QuartileBounds} object. *

        - * The {@link Builder} pattern is used to construct the {@code QuartileBounds} object with optional values for the - * upper and lower bounds. + * The {@link Builder} pattern is used to construct the {@code QuartileBounds} object with + * optional values for the upper and lower bounds. *

        * * @return a new instance of the {@link Builder} class @@ -65,9 +65,10 @@ public static Builder builder() { /** * A builder class for constructing instances of the {@code QuartileBounds} record. *

        - * The {@link Builder} pattern allows for the step-by-step construction of a {@code QuartileBounds} object, - * providing a flexible way to set values for the lower and upper bounds. Once the builder has the required values, - * the {@link #build()} method creates and returns a new {@code QuartileBounds} object. + * The {@link Builder} pattern allows for the step-by-step construction of a + * {@code QuartileBounds} object, providing a flexible way to set values for the lower and + * upper bounds. Once the builder has the required values, the {@link #build()} method creates + * and returns a new {@code QuartileBounds} object. *

        *

        * Example usage: @@ -114,7 +115,8 @@ public Builder lowerBound(Double lowerBound) { } /** - * Builds and returns a new {@code QuartileBounds} instance with the specified upper and lower bounds. + * Builds and returns a new {@code QuartileBounds} instance with the specified upper and + * lower bounds. * * @return a new {@code QuartileBounds} object containing the specified bounds */ diff --git a/property-guard-spring-boot-starter/src/main/java/com/onixbyte/propertyguard/autoconfiguration/PropertyGuard.java b/property-guard-spring-boot-starter/src/main/java/com/onixbyte/propertyguard/autoconfiguration/PropertyGuard.java index 25354a2..ee779a3 100644 --- a/property-guard-spring-boot-starter/src/main/java/com/onixbyte/propertyguard/autoconfiguration/PropertyGuard.java +++ b/property-guard-spring-boot-starter/src/main/java/com/onixbyte/propertyguard/autoconfiguration/PropertyGuard.java @@ -29,39 +29,34 @@ import java.util.Optional; /** - * {@code PropertyGuard} is a utility class designed for encrypting - * configuration properties in Spring Boot applications. + * {@code PropertyGuard} is a utility class designed for encrypting configuration properties in + * Spring Boot applications. *

        - * Spring Boot applications often need to store sensitive configuration details - * such as database passwords, API keys, etc. To ensure that these sensitive - * pieces of information are not exposed to the public, developers can utilize - * the {@code PropertyGuard} class to encrypt and store them within - * configuration files. + * Spring Boot applications often need to store sensitive configuration details such as database + * passwords, API keys, etc. To ensure that these sensitive pieces of information are not exposed + * to the public, developers can utilize the {@code PropertyGuard} class to encrypt and store them + * within configuration files. *

        * Usage - * You need a 16-char long secret for encrypting a configuration property. You - * can get this secret on your own, or use the helper utility class by the - * following code: + * You need a 16-char long secret for encrypting a configuration property. You can get this secret + * on your own, or use the helper utility class by the following code: *

        {@code
        - * var secret = AesUtil.generateRandomSecret(); // Let's presume the result is
        - *                                              // "3856faef0d2d4f33"
        + * var secret = AesUtil.generateRandomSecret(); // Let's presume the result is "3856faef0d2d4f33"
          * }
        *

        - * Then, in {@code application.yml} or {@code application.properties}, change - * the original value from plain text to encrypted value with the prefix - * "pg:". - *

        - *     # original
        - *     app.example-properties=Sample Value
        + * Then, in {@code application.yml} or {@code application.properties}, change the original value
        + * from plain text to encrypted value with the prefix "pg:".
        + * 
        {@code
        + * # original
        + * app.example-properties=Sample Value
          *
        - *     # encrypted with key 3856faef0d2d4f33
        - *     app.example-properties=pg:t4YBfv8M9ZmTzWgTi2gJqg==
        - * 
        - * After that, before running, you need to add the command line arguments - * "pg.key" as the following codes: {@code --pg.key=}. + * # encrypted with key 3856faef0d2d4f33 + * app.example-properties=pg:t4YBfv8M9ZmTzWgTi2gJqg== + * }
        + * After that, before running, you need to add the command line arguments "pg.key" as the following + * codes: {@code --pg.key=}. *

        - * This class is extracted from MyBatis-Plus. + * This class is extracted from MyBatis-Plus. * * @author hubin@baomidou * @version 1.1.0 From ef504bbe06971458669c22bcc84f6175066d6ef5 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Sun, 19 Jan 2025 00:06:18 +0800 Subject: [PATCH 4/7] feat: added RangeUtil RangeUtil is a utility class providing methods for generating streams of integers that emulate the behaviour of Python's range function. --- .../com/onixbyte/devkit/utils/RangeUtil.java | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 devkit-utils/src/main/java/com/onixbyte/devkit/utils/RangeUtil.java diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/RangeUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/RangeUtil.java new file mode 100644 index 0000000..7a7dd6a --- /dev/null +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/RangeUtil.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2024-2025 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.devkit.utils; + +import java.util.stream.IntStream; + +/** + * {@code RangeUtil} is a utility class providing methods for generating streams of integers that + * emulate the behaviour of Python's {@code range} function. + *

        + * This class offers static methods to create ranges with various configurations. These methods + * leverage the {@link IntStream} to provide efficient and versatile integer sequences. + * + * @author zihluwang + * @see IntStream + */ +public final class RangeUtil { + + /** + * Private constructor prevent class being instantiated. + */ + private RangeUtil() { + } + + /** + * Generates a stream of integers starting from {@code 0} up to the specified {@code end} value. + *

        + * It creates a sequential, ordered {@code IntStream} that can be used for iteration or + * further processing. + *

        + * Example Usage: + *

        {@code
        +     * RangeUtil.range(5).forEach(System.out::println);
        +     *
        +     * // Output:
        +     * // 0
        +     * // 1
        +     * // 2
        +     * // 3
        +     * // 4
        +     * }
        + * + * @param end upper-bound of the range (exclusive) + * @return an {@code IntStream} of integers from {@code 0} (inclusive) to + * {@code end} (exclusive) + * @throws IllegalArgumentException if the given {@code end} value is less equal to 0 + * @see IntStream + */ + public static IntStream range(int end) { + if (end <= 0) { + throw new IllegalArgumentException("Parameter [end] should not less than 0, provided is " + + end); + } + return IntStream.range(0, end); + } + + /** + * Generates a stream of integers starting from the specified {@code start} value up to the + * specified {@code end} value. + *

        + * It creates a sequential, ordered {@code IntStream} that can be used for iteration or + * further processing. + *

        + * Example Usage: + *

        {@code
        +     * RangeUtil.range(3, 8).forEach(System.out::println);
        +     *
        +     * // Output:
        +     * // 3
        +     * // 4
        +     * // 5
        +     * // 6
        +     * // 7
        +     * }
        + * + * @param start the starting value of the range (inclusive) + * @param end upper-bound of the range (exclusive) + * @return an {@code IntStream} of integers from {@code 0} (inclusive) to + * {@code end} (exclusive) + * @throws IllegalArgumentException if the given {@code end} value is less equal to 0 + * @see IntStream + */ + public static IntStream range(int start, int end) { + if (end >= start) { + throw new IllegalStateException("Parameter [start] should less than parameter [end]."); + } + return IntStream.range(start, end); + } + + /** + * Generates a stream of integers starting from the specified {@code start} value up to the + * specified {@code end} value. + *

        + * It creates a sequential, ordered {@code IntStream} that can be used for iteration or + * further processing. + *

        + * Example Usage: + *

        {@code
        +     * RangeUtil.rangeClosed(3, 8).forEach(System.out::println);
        +     *
        +     * // Output:
        +     * // 3
        +     * // 4
        +     * // 5
        +     * // 6
        +     * // 7
        +     * // 8
        +     * }
        + * + * @param start the starting value of the range (inclusive) + * @param end upper-bound of the range (inclusive) + * @return an {@code IntStream} of integers from {@code 0} (inclusive) to + * {@code end} (inclusive) + * @throws IllegalArgumentException if the given {@code end} value is less equal to 0 + * @see IntStream + */ + public static IntStream rangeClosed(int start, int end) { + return IntStream.rangeClosed(start, end); + } + + /** + * Generates a stream of integers starting from the specified {@code start} value, increment by + * the specified {@code step}, up to the specified {@code end} value. + *

        + * It creates a sequential, ordered {@code IntStream} that can be used for iteration or + * further processing. + *

        + * Example Usage: + *

        {@code
        +     * RangeUtil.range(3, 8, 2).forEach(System.out::println);
        +     *
        +     * // Output:
        +     * // 3
        +     * // 5
        +     * // 7
        +     * }
        + * + * @param start the starting value of the range (inclusive) + * @param end upper-bound of the range (exclusive) + * @param step the increment (or decrement) between each value + * @return an {@code IntStream} of integers from {@code 0} (inclusive) to + * {@code end} (exclusive) + * @throws IllegalArgumentException if the given {@code end} value is less equal to 0 + * @see IntStream + */ + public static IntStream range(int start, int end, int step) { + if (step == 0) { + throw new IllegalArgumentException("Step value must not be zero."); + } + if ((step > 0 && start >= end) || (step < 0 && start <= end)) { + throw new IllegalArgumentException("Range parameters are inconsistent with the step value."); + } + return IntStream.iterate(start, (n) -> n < end, (n) -> n + step); + } + +} From a8aa5b16e37349c60dc9e5253f6402d77dd62696 Mon Sep 17 00:00:00 2001 From: zihluwang Date: Sun, 19 Jan 2025 00:07:41 +0800 Subject: [PATCH 5/7] build: upgrade to v1.8.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 92149db..b44cb7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ slf4jVersion=2.0.16 springVersion=6.1.13 springBootVersion=3.3.4 -artefactVersion=1.7.0 +artefactVersion=1.8.0 projectUrl=https://onixbyte.com/JDevKit projectGithubUrl=https://github.com/OnixByte/JDevKit licenseName=The Apache License, Version 2.0 From f771b1af199e2f3532277f7f4816ee2eea70851f Mon Sep 17 00:00:00 2001 From: zihluwang Date: Sat, 25 Jan 2025 19:25:21 +0800 Subject: [PATCH 6/7] refactor: upgrage copyright years --- LICENSE | 2 +- build.gradle.kts | 2 +- devkit-core/build.gradle.kts | 2 +- .../devkit/core/exceptions/NotImplementedException.java | 2 +- .../java/com/onixbyte/devkit/core/exceptions/package-info.java | 2 +- .../src/main/java/com/onixbyte/devkit/core/package-info.java | 2 +- .../src/main/java/com/onixbyte/devkit/package-info.java | 2 +- devkit-core/src/main/resources/logback.xml | 2 +- .../devkit/core/exceptions/NotImplementationExceptionTest.java | 2 +- devkit-utils/build.gradle.kts | 2 +- .../src/main/java/com/onixbyte/devkit/utils/AesUtil.java | 2 +- .../src/main/java/com/onixbyte/devkit/utils/Base64Util.java | 2 +- .../src/main/java/com/onixbyte/devkit/utils/BoolUtil.java | 2 +- .../src/main/java/com/onixbyte/devkit/utils/BranchUtil.java | 2 +- .../src/main/java/com/onixbyte/devkit/utils/HashUtil.java | 2 +- .../src/main/java/com/onixbyte/devkit/utils/MapUtil.java | 2 +- .../main/java/com/onixbyte/devkit/utils/ObjectMapAdapter.java | 2 +- .../src/main/java/com/onixbyte/devkit/utils/package-info.java | 2 +- devkit-utils/src/main/resources/logback.xml | 2 +- .../src/test/java/com/onixbyte/devkit/utils/TestAesUtil.java | 2 +- .../test/java/com/onixbyte/devkit/utils/TestBase64Util.java | 2 +- gradle.properties | 3 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- guid/build.gradle.kts | 2 +- guid/src/main/java/com/onixbyte/guid/GuidCreator.java | 2 +- .../java/com/onixbyte/guid/exceptions/TimingException.java | 2 +- .../main/java/com/onixbyte/guid/exceptions/package-info.java | 2 +- .../main/java/com/onixbyte/guid/impl/SnowflakeGuidCreator.java | 2 +- guid/src/main/java/com/onixbyte/guid/package-info.java | 2 +- guid/src/main/resources/logback.xml | 2 +- settings.gradle.kts | 2 +- simple-jwt-spring-boot-starter/build.gradle.kts | 2 +- .../AuthzeroTokenResolverAutoConfiguration.java | 2 +- .../simplejwt/autoconfiguration/GuidAutoConfiguration.java | 2 +- .../autoconfiguration/conditions/GuidCreatorCondition.java | 2 +- .../com/onixbyte/simplejwt/autoconfiguration/package-info.java | 2 +- .../autoconfiguration/properties/SimpleJwtProperties.java | 2 +- .../simplejwt/autoconfiguration/properties/package-info.java | 2 +- simple-jwt-spring-boot-starter/src/main/resources/logback.xml | 2 +- 39 files changed, 39 insertions(+), 40 deletions(-) diff --git a/LICENSE b/LICENSE index 5d240f5..5548015 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2023-2024 OnixByte (HK) + Copyright 2024-2025 OnixByte Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/build.gradle.kts b/build.gradle.kts index f723ee5..f43baac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024-2024 OnixByte. + * Copyright (C) 2024-2025 OnixByte. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/devkit-core/build.gradle.kts b/devkit-core/build.gradle.kts index ddb0713..70c87a2 100644 --- a/devkit-core/build.gradle.kts +++ b/devkit-core/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024-2024 OnixByte. + * Copyright (C) 2024-2025 OnixByte. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java index d3df10d..21ba66c 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/NotImplementedException.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024-2024 OnixByte. + * Copyright (C) 2024-2025 OnixByte. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java index 9d1b883..78bd635 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/exceptions/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024-2024 OnixByte. + * Copyright (C) 2024-2025 OnixByte. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java b/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java index 6e74d24..919ce2b 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/core/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024-2024 OnixByte. + * Copyright (C) 2024-2025 OnixByte. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java b/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java index ea3e173..aa57a33 100644 --- a/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java +++ b/devkit-core/src/main/java/com/onixbyte/devkit/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024-2024 OnixByte. + * Copyright (C) 2024-2025 OnixByte. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/devkit-core/src/main/resources/logback.xml b/devkit-core/src/main/resources/logback.xml index df2a9f0..56cd5b7 100644 --- a/devkit-core/src/main/resources/logback.xml +++ b/devkit-core/src/main/resources/logback.xml @@ -1,6 +1,6 @@