Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.6.2 #39

Merged
merged 7 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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);
}

/**
* 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)
.anyMatch(BooleanSupplier::getAsBoolean);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -268,7 +268,7 @@ public Long getLong() {
*
* @return the current value as an {@link Integer}
*/
public Integer getInteger() {
public int getInteger() {
return getValue().intValue();
}

Expand Down