From 48f12308260449079e8a70d031ababe58c320faf Mon Sep 17 00:00:00 2001 From: shaoxinke Date: Thu, 22 Aug 2024 14:16:48 +0800 Subject: [PATCH 1/4] feat: added boolean util --- .../com/onixbyte/devkit/utils/BoolUtil.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java 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 new file mode 100644 index 0000000..bec5c2f --- /dev/null +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java @@ -0,0 +1,33 @@ +package com.onixbyte.devkit.utils; + +import java.util.Arrays; +import java.util.Objects; +import java.util.function.BooleanSupplier; + +public final class BoolUtil { + + public static boolean and(Boolean... values) { + return Arrays.stream(values) + .filter(Objects::nonNull) + .allMatch(Boolean::booleanValue); + } + + public static boolean and(BooleanSupplier... valueSuppliers) { + return Arrays.stream(valueSuppliers) + .filter(Objects::nonNull) + .allMatch(BooleanSupplier::getAsBoolean); + } + + public static boolean or(Boolean... valueSuppliers) { + return Arrays.stream(valueSuppliers) + .filter(Objects::nonNull) + .anyMatch(Boolean::booleanValue); + } + + public static boolean or(BooleanSupplier... valueSuppliers) { + return Arrays.stream(valueSuppliers) + .filter(Objects::nonNull) + .anyMatch(BooleanSupplier::getAsBoolean); + } + +} From 9bac26bb897c8b6bf15a041b7ff710fed4299012 Mon Sep 17 00:00:00 2001 From: shaoxinke Date: Thu, 22 Aug 2024 14:19:30 +0800 Subject: [PATCH 2/4] fix: changed return types to primitive types --- .../java/com/onixbyte/devkit/utils/ChainedCalcUtil.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ChainedCalcUtil.java b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ChainedCalcUtil.java index 2ee3092..11bcc47 100644 --- a/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ChainedCalcUtil.java +++ b/devkit-utils/src/main/java/com/onixbyte/devkit/utils/ChainedCalcUtil.java @@ -240,7 +240,7 @@ public BigDecimal getValue(int scale) { * * @return the current value as a {@link Double} */ - public Double getDouble() { + public double getDouble() { return getValue().doubleValue(); } @@ -250,7 +250,7 @@ public Double getDouble() { * @param scale the scale for the result * @return the current value as a {@link Double} with the specified scale */ - public Double getDouble(int scale) { + public double getDouble(int scale) { return getValue(scale).doubleValue(); } @@ -259,7 +259,7 @@ public Double getDouble(int scale) { * * @return the current value as a {@link Long} */ - public Long getLong() { + public long getLong() { return getValue().longValue(); } @@ -268,7 +268,7 @@ public Long getLong() { * * @return the current value as an {@link Integer} */ - public Integer getInteger() { + public int getInteger() { return getValue().intValue(); } From 332dbe04e025771dd3465f9c8fe99d93c5767e6f Mon Sep 17 00:00:00 2001 From: shaoxinke Date: Thu, 22 Aug 2024 14:30:29 +0800 Subject: [PATCH 3/4] docs: added docs --- .../com/onixbyte/devkit/utils/BoolUtil.java | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) 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 bec5c2f..3a77079 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 @@ -1,29 +1,76 @@ +/* + * Copyright (C) 2024-2024 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.Arrays; import java.util.Objects; import java.util.function.BooleanSupplier; +/** + * A util for boolean calculations. + * + * @author shaoxinke + * @version 1.6.2 + */ public final class BoolUtil { + /** + * Logical and calculation. + * + * @param values the values to be calculated + * @return {@code true} if all value in values is {@code true}, otherwise {@code false} + */ public static boolean and(Boolean... values) { return Arrays.stream(values) .filter(Objects::nonNull) .allMatch(Boolean::booleanValue); } + /** + * Logical and calculation. + * + * @param valueSuppliers the suppliers of value to be calculated + * @return {@code true} if all value in values is {@code true}, otherwise {@code false} + */ public static boolean and(BooleanSupplier... valueSuppliers) { return Arrays.stream(valueSuppliers) .filter(Objects::nonNull) .allMatch(BooleanSupplier::getAsBoolean); } - public static boolean or(Boolean... valueSuppliers) { - return Arrays.stream(valueSuppliers) + /** + * Logical or calculation. + * + * @param values the values to be calculated + * @return {@code true} if any value in values is {@code true}, otherwise {@code false} + */ + public static boolean or(Boolean... values) { + return Arrays.stream(values) .filter(Objects::nonNull) .anyMatch(Boolean::booleanValue); } + /** + * Logical or calculation. + * + * @param valueSuppliers the suppliers of value to be calculated + * @return {@code true} if any value in values is {@code true}, otherwise {@code false} + */ public static boolean or(BooleanSupplier... valueSuppliers) { return Arrays.stream(valueSuppliers) .filter(Objects::nonNull) From 2c036a96c73f67192e12b091dbe5a20d2bebc1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E7=86=8A=E7=86=8A=E5=AD=90=E8=B7=AF?= Date: Thu, 22 Aug 2024 14:52:53 +0800 Subject: [PATCH 4/4] fix: added private constructor --- .../src/main/java/com/onixbyte/devkit/utils/BoolUtil.java | 5 +++++ gradle.properties | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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 3a77079..c97cb76 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 @@ -77,4 +77,9 @@ public static boolean or(BooleanSupplier... valueSuppliers) { .anyMatch(BooleanSupplier::getAsBoolean); } + /** + * Private constructor prevent from being initialised. + */ + private BoolUtil() {} + } diff --git a/gradle.properties b/gradle.properties index 0d329ae..f4fffc0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ springVersion=6.1.3 springBootVersion=3.2.3 buildGroupId=com.onixbyte -buildVersion=1.6.1 +buildVersion=1.6.2 projectUrl=https://onixbyte.com/JDevKit projectGithubUrl=https://github.com/OnixByte/JDevKit licenseName=The Apache License, Version 2.0