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

v1.6.5 #42

Merged
merged 9 commits into from
Oct 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.onixbyte.devkit.utils;

import java.util.Arrays;
import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
Expand Down Expand Up @@ -89,62 +88,50 @@ private BranchUtil(boolean result) {
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
* boolean expressions.
*
* @param booleans the boolean expressions to be evaluated
* @param <T> the type of the result to be handled by the methods
* @param values the boolean expressions to be evaluated
* @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the logical OR operation
*/
public static <T> BranchUtil<T> or(Boolean... booleans) {
var result = Arrays.stream(booleans)
.filter(Objects::nonNull)
.anyMatch(Boolean::booleanValue);
return new BranchUtil<>(result);
public static <T> BranchUtil<T> or(Boolean... values) {
return new BranchUtil<>(BoolUtil.or(values));
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
* boolean expressions.
*
* @param booleans the boolean expressions to be evaluated
* @param <T> the type of the result to be handled by the methods
* @param values the boolean expressions to be evaluated
* @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the logical AND operation
*/
public static <T> BranchUtil<T> and(Boolean... booleans) {
var result = Arrays.stream(booleans)
.filter(Objects::nonNull)
.allMatch(Boolean::booleanValue);
return new BranchUtil<>(result);
public static <T> BranchUtil<T> and(Boolean... values) {
return new BranchUtil<>(BoolUtil.and(values));
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
* boolean suppliers.
*
* @param booleanSuppliers the boolean suppliers to be evaluated
* @param <T> the type of the result to be handled by the methods
* @param valueSuppliers the boolean suppliers to be evaluated
* @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the
* logical OR operation
*/
public static <T> BranchUtil<T> or(BooleanSupplier... booleanSuppliers) {
var result = Arrays.stream(booleanSuppliers)
.filter(Objects::nonNull)
.anyMatch(BooleanSupplier::getAsBoolean);
return new BranchUtil<>(result);
public static <T> BranchUtil<T> or(BooleanSupplier... valueSuppliers) {
return new BranchUtil<>(BoolUtil.or(valueSuppliers));
}

/**
* Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
* boolean suppliers.
*
* @param booleanSuppliers the boolean suppliers to be evaluated
* @param <T> the type of the result to be handled by the methods
* @param valueSuppliers the boolean suppliers to be evaluated
* @param <T> the type of the result to be handled by the methods
* @return a {@code BranchUtil} instance representing the result of the
* logical AND operation
*/
public static <T> BranchUtil<T> and(BooleanSupplier... booleanSuppliers) {
var result = Arrays.stream(booleanSuppliers)
.filter(Objects::nonNull)
.allMatch(BooleanSupplier::getAsBoolean);
return new BranchUtil<>(result);
public static <T> BranchUtil<T> and(BooleanSupplier... valueSuppliers) {
return new BranchUtil<>(BoolUtil.and(valueSuppliers));
}

/**
Expand Down
17 changes: 8 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
# limitations under the License.
#

jacksonVersion=2.17.2
jacksonVersion=2.18.0
javaJwtVersion=4.4.0
jjwtVersion=0.12.6
junitVersion=5.10.2
logbackVersion=1.5.4
lombokVersion=1.18.30
slf4jVersion=2.0.9
springVersion=6.1.3
springBootVersion=3.2.3
junitVersion=5.11.2
logbackVersion=1.5.10
lombokVersion=1.18.34
slf4jVersion=2.0.16
springVersion=6.1.13
springBootVersion=3.3.4

buildGroupId=com.onixbyte
buildVersion=1.6.4
buildVersion=1.6.5
projectUrl=https://onixbyte.com/JDevKit
projectGithubUrl=https://github.com/OnixByte/JDevKit
licenseName=The Apache License, Version 2.0
Expand Down
19 changes: 19 additions & 0 deletions num4j/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("java")
}

group = "com.onixbyte"
version = "unspecified"

repositories {
mavenCentral()
}

dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.onixbyte.devkit.utils;
package com.onixbyte.nums;

import lombok.Getter;

Expand Down Expand Up @@ -87,7 +87,7 @@
*
* @author sunzsh
* @version 1.1.0
* @see java.math.BigDecimal
* @see BigDecimal
* @since 1.0.0
*/
@Getter
Expand Down
62 changes: 62 additions & 0 deletions num4j/src/main/java/com/onixbyte/nums/PercentileCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 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.nums;

import com.onixbyte.nums.model.QuartileBounds;

import java.util.List;

/**
* Percentile calculator.
*
* @author zihluwang
* @version 1.7.0
* @since 1.7.0
*/
public final class PercentileCalculator {

public static Double calculatePercentile(List<Double> values, Double percentile) {
var sorted = values.stream().sorted().toList();
if (sorted.isEmpty()) {
throw new IllegalArgumentException("Unable to sort an empty list.");
}

var rank = percentile / 100. * (sorted.size() - 1);
var lowerIndex = ((int) Math.floor(rank));
var upperIndex = ((int) Math.ceil(rank));
var weight = rank - lowerIndex;

return sorted.get(lowerIndex) * (1 - weight) + sorted.get(upperIndex) * weight;
}

public static QuartileBounds calculatePercentileBounds(List<Double> data) {
var sorted = data.stream().sorted().toList();
var Q1 = calculatePercentile(sorted, 25.);
var Q3 = calculatePercentile(sorted, 75.);

var IQR = Q3 - Q1;

var lowerBound = Q1 - 1.5 * IQR;
var upperBound = Q3 + 1.5 * IQR;

return QuartileBounds.builder()
.upperBound(upperBound)
.lowerBound(lowerBound)
.build();
}

}
63 changes: 63 additions & 0 deletions num4j/src/main/java/com/onixbyte/nums/model/QuartileBounds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.nums.model;

/**
* QuartileBound.
*
* @param upperBound
* @param lowerBound
* @author zihluwang
*/
public record QuartileBounds(
Double upperBound,
Double lowerBound
) {

/**
* Get a builder for {@link QuartileBounds}.
*
* @return a builder
*/
public static Builder builder() {
return new Builder();
}

public static class Builder {
private Double upperBound;
private Double lowerBound;

private Builder() {
}

public Builder upperBound(Double upperBound) {
this.upperBound = upperBound;
return this;
}

public Builder lowerBound(Double lowerBound) {
this.lowerBound = lowerBound;
return this;
}

public QuartileBounds build() {
return new QuartileBounds(upperBound, lowerBound);
}
}

}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ include(
"simple-jwt-spring-boot-starter",
"property-guard-spring-boot-starter"
)
include("num4j")