Skip to content

Commit eaa74a4

Browse files
author
Zihlu Wang
authored
Merge pull request #38 from shaoxinke/release/1.6.2
2 parents 53d24ea + 332dbe0 commit eaa74a4

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2024-2024 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.devkit.utils;
19+
20+
import java.util.Arrays;
21+
import java.util.Objects;
22+
import java.util.function.BooleanSupplier;
23+
24+
/**
25+
* A util for boolean calculations.
26+
*
27+
* @author shaoxinke
28+
* @version 1.6.2
29+
*/
30+
public final class BoolUtil {
31+
32+
/**
33+
* Logical and calculation.
34+
*
35+
* @param values the values to be calculated
36+
* @return {@code true} if all value in values is {@code true}, otherwise {@code false}
37+
*/
38+
public static boolean and(Boolean... values) {
39+
return Arrays.stream(values)
40+
.filter(Objects::nonNull)
41+
.allMatch(Boolean::booleanValue);
42+
}
43+
44+
/**
45+
* Logical and calculation.
46+
*
47+
* @param valueSuppliers the suppliers of value to be calculated
48+
* @return {@code true} if all value in values is {@code true}, otherwise {@code false}
49+
*/
50+
public static boolean and(BooleanSupplier... valueSuppliers) {
51+
return Arrays.stream(valueSuppliers)
52+
.filter(Objects::nonNull)
53+
.allMatch(BooleanSupplier::getAsBoolean);
54+
}
55+
56+
/**
57+
* Logical or calculation.
58+
*
59+
* @param values the values to be calculated
60+
* @return {@code true} if any value in values is {@code true}, otherwise {@code false}
61+
*/
62+
public static boolean or(Boolean... values) {
63+
return Arrays.stream(values)
64+
.filter(Objects::nonNull)
65+
.anyMatch(Boolean::booleanValue);
66+
}
67+
68+
/**
69+
* Logical or calculation.
70+
*
71+
* @param valueSuppliers the suppliers of value to be calculated
72+
* @return {@code true} if any value in values is {@code true}, otherwise {@code false}
73+
*/
74+
public static boolean or(BooleanSupplier... valueSuppliers) {
75+
return Arrays.stream(valueSuppliers)
76+
.filter(Objects::nonNull)
77+
.anyMatch(BooleanSupplier::getAsBoolean);
78+
}
79+
80+
}

devkit-utils/src/main/java/com/onixbyte/devkit/utils/ChainedCalcUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public BigDecimal getValue(int scale) {
240240
*
241241
* @return the current value as a {@link Double}
242242
*/
243-
public Double getDouble() {
243+
public double getDouble() {
244244
return getValue().doubleValue();
245245
}
246246

@@ -250,7 +250,7 @@ public Double getDouble() {
250250
* @param scale the scale for the result
251251
* @return the current value as a {@link Double} with the specified scale
252252
*/
253-
public Double getDouble(int scale) {
253+
public double getDouble(int scale) {
254254
return getValue(scale).doubleValue();
255255
}
256256

@@ -259,7 +259,7 @@ public Double getDouble(int scale) {
259259
*
260260
* @return the current value as a {@link Long}
261261
*/
262-
public Long getLong() {
262+
public long getLong() {
263263
return getValue().longValue();
264264
}
265265

@@ -268,7 +268,7 @@ public Long getLong() {
268268
*
269269
* @return the current value as an {@link Integer}
270270
*/
271-
public Integer getInteger() {
271+
public int getInteger() {
272272
return getValue().intValue();
273273
}
274274

0 commit comments

Comments
 (0)