Merge pull request #38 from shaoxinke/release/1.6.2
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -240,7 +240,7 @@ public final class ChainedCalcUtil {
|
||||
*
|
||||
* @return the current value as a {@link Double}
|
||||
*/
|
||||
public Double getDouble() {
|
||||
public double getDouble() {
|
||||
return getValue().doubleValue();
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public final class ChainedCalcUtil {
|
||||
* @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 final class ChainedCalcUtil {
|
||||
*
|
||||
* @return the current value as a {@link Long}
|
||||
*/
|
||||
public Long getLong() {
|
||||
public long getLong() {
|
||||
return getValue().longValue();
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ public final class ChainedCalcUtil {
|
||||
*
|
||||
* @return the current value as an {@link Integer}
|
||||
*/
|
||||
public Integer getInteger() {
|
||||
public int getInteger() {
|
||||
return getValue().intValue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user