refactor: change to MIT license and reformat codes

This commit is contained in:
zihluwang
2025-06-17 23:07:52 +08:00
parent 7ea6646e89
commit a878422889
73 changed files with 1521 additions and 2522 deletions
+20 -14
View File
@@ -1,19 +1,25 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.net.URI
plugins {
@@ -82,8 +88,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -122,4 +128,4 @@ publishing {
}
}
}
}
}
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -54,12 +59,27 @@ import java.util.UUID;
* System.out.println(randomSecret); // Output: A randomly generated 16-character long secret
* }</pre>
*
* @author hubin@baomidou
* @version 1.1.0
* @since 1.1.0
* @author hubin
* @version 3.0.0
*/
public final class AesUtil {
/**
* The algorithm AES.
*/
private static final String AES = "AES";
/**
* The algorithm AES/CBC/PKCS5Padding.
*/
private static final String AES_CBC_CIPHER = "AES/CBC/PKCS5Padding";
/**
* Private constructor to prevent instantiation of this utility class.
*/
private AesUtil() {
}
/**
* Encrypts the specified data using the AES algorithm with the provided secret key.
*
@@ -125,21 +145,4 @@ public final class AesUtil {
public static String generateRandomSecret() {
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16);
}
/**
* Private constructor to prevent instantiation of this utility class.
*/
private AesUtil() {
}
/**
* The algorithm AES.
*/
private static final String AES = "AES";
/**
* The algorithm AES/CBC/PKCS5Padding.
*/
private static final String AES_CBC_CIPHER = "AES/CBC/PKCS5Padding";
}
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -50,11 +55,21 @@ import java.util.Objects;
* encoding and decoding.
*
* @author zihluwang
* @version 1.1.0
* @since 1.0.0
* @version 3.0.0
*/
public final class Base64Util {
/**
* Private constructor to prevent instantiation of this utility class.
*/
private Base64Util() {
}
private static Base64.Encoder encoder;
private static Base64.Decoder decoder;
private static Base64.Encoder urlEncoder;
private static Base64.Decoder urlDecoder;
/**
* Ensure that there is only one Base64 Encoder.
*
@@ -103,12 +118,6 @@ public final class Base64Util {
return urlDecoder;
}
/**
* Private constructor to prevent instantiation of this utility class.
*/
private Base64Util() {
}
/**
* Encodes the given string using the specified charset.
*
@@ -200,13 +209,4 @@ public final class Base64Util {
public static String decodeUrlComponents(String value) {
return decodeUrlComponents(value, StandardCharsets.UTF_8);
}
private static Base64.Encoder encoder;
private static Base64.Decoder decoder;
private static Base64.Encoder urlEncoder;
private static Base64.Decoder urlDecoder;
}
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -30,20 +35,23 @@ import java.util.function.BooleanSupplier;
* </p>
*
* <p><b>Example usage:</b></p>
* <pre>
* {@code
* <pre>{@code
* boolean result1 = BoolUtil.and(true, true, false); // false
* boolean result2 = BoolUtil.or(true, false, false); // true
* boolean result3 = BoolUtil.not(false); // true
* }
* </pre>
* }</pre>
*
* @author zihluwang
* @version 1.6.2
* @since 1.6.2
* @version 3.0.0
*/
public final class BoolUtil {
/**
* Private constructor to prevent instantiation of this utility class.
*/
private BoolUtil() {
}
/**
* Logical and calculation.
*
@@ -91,10 +99,4 @@ public final class BoolUtil {
.filter(Objects::nonNull)
.anyMatch(BooleanSupplier::getAsBoolean);
}
/**
* Private constructor to prevent instantiation of this utility class.
*/
private BoolUtil() {}
}
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -64,11 +69,10 @@ import java.util.function.Supplier;
* expressions.
*
* @author zihluwang
* @version 2.1.3
* @version 3.0.0
* @see java.util.function.Supplier
* @see java.util.function.BooleanSupplier
* @see java.lang.Runnable
* @since 1.0.0
*/
public final class BranchUtil {
@@ -167,7 +171,8 @@ public final class BranchUtil {
*
* @param <T> the type of the result to be handled by the methods
* @param trueSupplier the supplier to be executed if the result is {@code true}
* @return the result of the executed handler, or {@code null} if result of evaluation is {@code false}
* @return the result of the executed handler, or {@code null} if result of evaluation
* is {@code false}
*/
public <T> T thenSupply(Supplier<T> trueSupplier) {
return thenSupply(trueSupplier, null);
@@ -205,5 +210,4 @@ public final class BranchUtil {
public void then(Runnable trueHandler) {
then(trueHandler, null);
}
}
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -27,6 +32,7 @@ import java.util.function.Supplier;
* A utility class providing static methods for manipulating collections.
*
* @author zihluwang
* @version 3.0.0
*/
public final class CollectionUtil {
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -60,12 +65,17 @@ import java.util.Optional;
* encryption purposes.
*
* @author zihluwang
* @version 1.1.0
* @version 3.0.0
* @see java.security.MessageDigest
* @since 1.0.0
*/
public final class HashUtil {
/**
* Private constructor to prevent instantiation of this utility class.
*/
private HashUtil() {
}
/**
* Calculates the MD2 hash value of the specified string using the given charset.
*
@@ -222,12 +232,6 @@ public final class HashUtil {
return hash("SHA-512", value, StandardCharsets.UTF_8);
}
/**
* Private constructor to prevent instantiation of this utility class.
*/
private HashUtil() {
}
/**
* Calculates the hash value of the specified string using the specified
* algorithm and charset.
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -28,15 +33,16 @@ import java.util.Map;
* </p>
*
* <p><b>Example usage:</b></p>
* <pre>
* {@code
* <pre>{@code
* // User.java
* public class User {
* private String name;
* private int age;
*
* // getters and setters
* }
*
*
* // UserMapAdapter.java
* public class UserMapAdapter implements ObjectMapAdapter<User> {
* @Override
* public Map<String, Object> toMap(User user) {
@@ -73,15 +79,19 @@ import java.util.Map;
* System.out.println(newUser.getAge()); // Output: 30
* }
* }
* }
* </pre>
* }</pre>
*
* @author zihluwang
* @version 1.7.0
* @since 1.0.0
* @version 3.0.0
*/
public final class MapUtil {
/**
* Private constructor to prevent instantiation of this utility class.
*/
private MapUtil() {
}
/**
* Converts an object to a map by mapping the field names to their corresponding values.
*
@@ -106,10 +116,4 @@ public final class MapUtil {
public static <T> T mapToObject(Map<String, Object> objectMap, ObjectMapAdapter<T> adapter) {
return adapter.toObject(objectMap);
}
/**
* Private constructor to prevent instantiation of this utility class.
*/
private MapUtil() {
}
}
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -28,8 +33,7 @@ import java.util.Map;
* {@code T} to a {@link Map} and vice versa.</p>
*
* <p><b>Example usage:</b></p>
* <pre>
* {@code
* <pre>{@code
* public class User {
* private String name;
* private int age;
@@ -54,13 +58,11 @@ import java.util.Map;
* return user;
* }
* }
* }
* </pre>
* }</pre>
*
* @param <T> the type of the object to be converted
* @author zihluwang
* @version 1.7.0
* @since 1.4.2
* @version 3.0.0
*/
public interface ObjectMapAdapter<T> {
@@ -1,18 +1,23 @@
/*
* Copyright (C) 2024-2025 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.
* You may obtain a copy of the License at
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* http://www.apache.org/licenses/LICENSE-2.0
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.common.util;
@@ -27,6 +32,7 @@ import java.util.stream.IntStream;
* leverage the {@link IntStream} to provide efficient and versatile integer sequences.
*
* @author zihluwang
* @version 3.0.0
* @see IntStream
*/
public final class RangeUtil {
@@ -64,7 +70,7 @@ public final class RangeUtil {
public static IntStream range(int end) {
if (end <= 0) {
throw new IllegalArgumentException("Parameter [end] should not be less than or equal to 0, provided: " +
end);
end);
}
return IntStream.range(0, end);
}
@@ -77,8 +83,9 @@ public final class RangeUtil {
* further processing.
* <p>
* If {@code start} is less than {@code end}, an ascending range (exclusive of {@code end})
* is generated. If {@code start} is greater than {@code end}, a descending range (exclusive of {@code end})
* is generated. If {@code start} equals {@code end}, an empty stream is returned.
* is generated. If {@code start} is greater than {@code end}, a descending range (exclusive
* of {@code end}) is generated. If {@code start} equals {@code end}, an empty stream
* is returned.
* <p>
* <b>Example Usage:</b>
* <pre>{@code
@@ -103,7 +110,8 @@ public final class RangeUtil {
*
* @param start the starting value of the range (inclusive)
* @param end upper-bound of the range (exclusive)
* @return an {@code IntStream} of integers in ascending or descending order, exclusive of {@code end}
* @return an {@code IntStream} of integers in ascending or descending order, exclusive
* of {@code end}
* @see IntStream
*/
public static IntStream range(int start, int end) {
@@ -150,8 +158,8 @@ public final class RangeUtil {
}
/**
* Generates a stream of integers starting from the specified {@code start} value, incremented by
* the specified {@code step}, up to the specified {@code end} value.
* Generates a stream of integers starting from the specified {@code start} value, incremented
* by the specified {@code step}, up to the specified {@code end} value.
* <p>
* It creates a sequential, ordered {@code IntStream} that can be used for iteration or
* further processing.
@@ -180,9 +188,10 @@ public final class RangeUtil {
* @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 (non-zero)
* @return an {@code IntStream} of integers from {@code start} to {@code end} exclusive stepping by {@code step}
* @throws IllegalArgumentException if {@code step} is zero or if {@code start} and {@code end} are inconsistent
* with the direction imposed by {@code step}
* @return an {@code IntStream} of integers from {@code start} to {@code end} exclusive stepping
* by {@code step}
* @throws IllegalArgumentException if {@code step} is zero or if {@code start} and {@code end}
* are inconsistent with the direction imposed by {@code step}
* @see IntStream
*/
public static IntStream range(int start, int end, int step) {
+18 -13
View File
@@ -1,19 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2024-2025 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.
~ You may obtain a copy of the License at
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ http://www.apache.org/licenses/LICENSE-2.0
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ 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.
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->
<configuration>
@@ -22,7 +27,7 @@
<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"/>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${COLOURFUL_OUTPUT}</pattern>
@@ -31,4 +36,4 @@
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
</configuration>