Merge pull request #85 from onixbyte/release/3.3.0

Release: 3.3.0
This commit is contained in:
Jam'o Siu
2026-01-28 14:08:26 +08:00
committed by GitHub
20 changed files with 290 additions and 299 deletions
+7
View File
@@ -19,3 +19,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
val artefactVersion: String by project
subprojects {
group = "com.onixbyte"
version = artefactVersion
}
-3
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project val licenseName: String by project
val licenseUrl: String by project val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.onixbyte.common.util; package com.onixbyte.common.adapter;
import java.util.Map; import java.util.Map;
@@ -22,6 +22,8 @@
package com.onixbyte.common.util; package com.onixbyte.common.util;
import com.onixbyte.common.adapter.ObjectMapAdapter;
import java.util.Map; import java.util.Map;
/** /**
-4
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project val licenseName: String by project
val licenseUrl: String by project val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@@ -60,7 +57,6 @@ tasks.withType<Jar> {
dependencies { dependencies {
compileOnly(libs.slf4j) compileOnly(libs.slf4j)
implementation(libs.logback) implementation(libs.logback)
testImplementation(libs.jwt.core)
testImplementation(platform(libs.junit.bom)) testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter) testImplementation(libs.junit.jupiter)
} }
+1 -1
View File
@@ -20,7 +20,7 @@
# SOFTWARE. # SOFTWARE.
# #
artefactVersion=3.2.0 artefactVersion=3.3.0
projectUrl=https://onixbyte.com/projects/onixbyte-toolbox projectUrl=https://onixbyte.com/projects/onixbyte-toolbox
projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox
licenseName=MIT licenseName=MIT
+1 -13
View File
@@ -15,23 +15,11 @@
[versions] [versions]
slf4j = "2.0.17" slf4j = "2.0.17"
logback = "1.5.18" logback = "1.5.26"
jackson = "2.18.4"
jwt = "4.5.0"
spring = "6.2.6"
springBoot = "3.4.5"
junit = "5.11.4" junit = "5.11.4"
[libraries] [libraries]
slf4j = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" } slf4j = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
logback = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logback" } logback = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logback" }
jackson-core = { group = "com.fasterxml.jackson.core", name = "jackson-core", version.ref = "jackson" }
jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jackson" }
jwt-core = { group = "com.auth0", name = "java-jwt", version.ref = "jwt" }
springBoot-autoconfigure = { group = "org.springframework.boot", name = "spring-boot-autoconfigure", version.ref = "springBoot" }
springBoot-starter-logging = { group = "org.springframework.boot", name = "spring-boot-starter-logging", version.ref = "springBoot" }
springBoot-configurationProcessor = { group = "org.springframework.boot", name = "spring-boot-configuration-processor", version.ref = "springBoot" }
springBoot-starter-redis = { group = "org.springframework.boot", name = "spring-boot-starter-data-redis", version.ref = "springBoot" }
springBoot-starter-test = { group = "org.springframework.boot", name = "spring-boot-starter-test", version.ref = "springBoot" }
junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit" } junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit" }
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit" } junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit" }
-3
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project val licenseName: String by project
val licenseUrl: String by project val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@@ -29,9 +29,9 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
/** /**
* The {@code SnowflakeIdentityGenerator} generates unique identifiers using the Snowflake algorithm, * The {@code SnowflakeIdentityGenerator} generates unique identifiers using the
* which combines a timestamp, worker ID, and data centre ID to create 64-bit long integers. The bit * Snowflake algorithm, which combines a timestamp, worker ID, and data centre ID to create 64-bit
* distribution for the generated IDs is as follows: * long integers. The bit distribution for the generated IDs is as follows:
* <ul> * <ul>
* <li>1 bit for sign</li> * <li>1 bit for sign</li>
* <li>41 bits for timestamp (in milliseconds)</li> * <li>41 bits for timestamp (in milliseconds)</li>
@@ -40,7 +40,7 @@ import java.time.ZoneId;
* <li>12 bits for sequence number (per millisecond)</li> * <li>12 bits for sequence number (per millisecond)</li>
* </ul> * </ul>
* <p> * <p>
* When initializing a {@link SnowflakeIdentityGenerator}, you must provide the worker ID and data * When initialising a {@link SnowflakeIdentityGenerator}, you must provide the worker ID and data
* centre ID, ensuring they are within the valid range defined by the bit size. The generator * centre ID, ensuring they are within the valid range defined by the bit size. The generator
* maintains an internal sequence number that increments for IDs generated within the * maintains an internal sequence number that increments for IDs generated within the
* same millisecond. If the system clock moves backward, an exception is thrown to prevent * same millisecond. If the system clock moves backward, an exception is thrown to prevent
@@ -63,15 +63,15 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
*/ */
private final long startEpoch; private final long startEpoch;
/**
* The number of bits reserved for the worker ID.
*/
private final long workerIdBits = 5L;
/** /**
* The number of bits reserved for the data centre ID. * The number of bits reserved for the data centre ID.
*/ */
private final long dataCentreIdBits = 5L; private static final long DATA_CENTRE_ID_BITS = 5L;
/**
* The number of bits reserved for the worker ID.
*/
private static final long WORKER_ID_BITS = 5L;
/** /**
* The worker ID assigned to this generator. * The worker ID assigned to this generator.
@@ -118,13 +118,13 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
throw new IllegalArgumentException("Start Epoch can not be greater than current timestamp!"); throw new IllegalArgumentException("Start Epoch can not be greater than current timestamp!");
} }
var maxWorkerId = ~(-1L << workerIdBits); var maxWorkerId = ~(-1L << WORKER_ID_BITS);
if (workerId > maxWorkerId || workerId < 0) { if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("Worker Id can't be greater than %d or less than 0", throw new IllegalArgumentException(String.format("Worker Id can't be greater than %d or less than 0",
maxWorkerId)); maxWorkerId));
} }
var maxDataCentreId = ~(-1L << dataCentreIdBits); var maxDataCentreId = ~(-1L << DATA_CENTRE_ID_BITS);
if (dataCentreId > maxDataCentreId || dataCentreId < 0) { if (dataCentreId > maxDataCentreId || dataCentreId < 0) {
throw new IllegalArgumentException(String.format("Data Centre Id can't be greater than %d or less than 0", throw new IllegalArgumentException(String.format("Data Centre Id can't be greater than %d or less than 0",
maxDataCentreId)); maxDataCentreId));
@@ -154,18 +154,17 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
} }
// if generated at the same time, perform intra-millisecond sequences // if generated at the same time, perform intra-millisecond sequences
long sequenceBits = 12L; var sequenceBits = 12L;
if (lastTimestamp == timestamp) { if (lastTimestamp == timestamp) {
long sequenceMask = ~(-1L << sequenceBits); var sequenceMask = ~(-1L << sequenceBits);
sequence = (sequence + 1) & sequenceMask; sequence = (sequence + 1) & sequenceMask;
// sequence overflow in milliseconds // sequence overflow in milliseconds
if (sequence == 0) { if (sequence == 0) {
// block to the next millisecond, get a new timestamp // block to the next millisecond, get a new timestamp
timestamp = awaitToNextMillis(lastTimestamp); timestamp = awaitToNextMillis(lastTimestamp);
} }
} } else {
// timestamp change, sequence reset in milliseconds // timestamp change, sequence reset in milliseconds
else {
sequence = 0L; sequence = 0L;
} }
@@ -173,8 +172,8 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
lastTimestamp = timestamp; lastTimestamp = timestamp;
// shifted and put together by or operations to form a 64-bit ID // shifted and put together by or operations to form a 64-bit ID
var timestampLeftShift = sequenceBits + workerIdBits + dataCentreIdBits; var timestampLeftShift = sequenceBits + WORKER_ID_BITS + DATA_CENTRE_ID_BITS;
var dataCentreIdShift = sequenceBits + workerIdBits; var dataCentreIdShift = sequenceBits + WORKER_ID_BITS;
return ((timestamp - startEpoch) << timestampLeftShift) return ((timestamp - startEpoch) << timestampLeftShift)
| (dataCentreId << dataCentreIdShift) | (dataCentreId << dataCentreIdShift)
| (workerId << sequenceBits) | (workerId << sequenceBits)
-3
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project val licenseName: String by project
val licenseUrl: String by project val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@@ -38,45 +38,45 @@ import java.util.function.Function;
* <b>Usage:</b> * <b>Usage:</b>
* <pre> * <pre>
* // Perform addition: 3 + 4 * // Perform addition: 3 + 4
* BigDecimal result1 = ChainedCalcUtil.startWith(3) * BigDecimal result1 = Calculator.startWith(3)
* .add(4) * .add(4)
* .getValue(); * .getValue();
* *
* // Perform subtraction: 4 - 2 * // Perform subtraction: 4 - 2
* BigDecimal result2 = ChainedCalcUtil.startWith(4) * BigDecimal result2 = Calculator.startWith(4)
* .subtract(2) * .subtract(2)
* .getValue(); * .getValue();
* *
* // Perform multiplication: 3 * 6 * // Perform multiplication: 3 * 6
* BigDecimal result3 = ChainedCalcUtil.startWith(3) * BigDecimal result3 = Calculator.startWith(3)
* .multiply(6) * .multiply(6)
* .getValue(); * .getValue();
* *
* // Perform division: 6 ÷ 2 * // Perform division: 6 ÷ 2
* BigDecimal result4 = ChainedCalcUtil.startWith(6) * BigDecimal result4 = Calculator.startWith(6)
* .divide(2) * .divide(2)
* .getValue(); * .getValue();
* *
* // Perform division with specified scale: 13 ÷ 7 with a scale of 2 * // Perform division with specified scale: 13 ÷ 7 with a scale of 2
* BigDecimal result5 = ChainedCalcUtil.startWith(13) * BigDecimal result5 = Calculator.startWith(13)
* .divideWithScale(7, 2) * .divideWithScale(7, 2)
* .getValue(); * .getValue();
* *
* // Get int, long, or double results * // Get int, long, or double results
* int intResult = ChainedCalcUtil.startWith(3) * int intResult = Calculator.startWith(3)
* .add(4) * .add(4)
* .getInteger(); * .getInteger();
* *
* long longResult = ChainedCalcUtil.startWith(4) * long longResult = Calculator.startWith(4)
* .subtract(2) * .subtract(2)
* .getLong(); * .getLong();
* *
* double doubleResult = ChainedCalcUtil.startWith(6) * double doubleResult = Calculator.startWith(6)
* .divide(2) * .divide(2)
* .getDouble(); * .getDouble();
* *
* // Get BigDecimal result with specified scale * // Get BigDecimal result with specified scale
* BigDecimal result6 = ChainedCalcUtil.startWith(13) * BigDecimal result6 = Calculator.startWith(13)
* .divide(7) * .divide(7)
* .getValue(2); * .getValue(2);
* </pre> * </pre>
@@ -89,18 +89,18 @@ import java.util.function.Function;
* and may have performance implications for extremely large numbers or complex calculations. * and may have performance implications for extremely large numbers or complex calculations.
* *
* @author sunzsh * @author sunzsh
* @version 3.0.0 * @version 3.3.0
* @see BigDecimal * @see BigDecimal
* @since 1.0.0 * @since 1.0.0
*/ */
public final class ChainedCalcUtil { public final class Calculator {
/** /**
* Creates a {@code ChainedCalcUtil} instance with the specified initial value. * Creates a {@code ChainedCalcUtil} instance with the specified initial value.
* *
* @param value the initial value for the calculation * @param value the initial value for the calculation
*/ */
private ChainedCalcUtil(Number value) { private Calculator(Number value) {
this.value = convertBigDecimal(value, null); this.value = convertBigDecimal(value, null);
} }
@@ -110,8 +110,8 @@ public final class ChainedCalcUtil {
* @param value the initial value for the calculation * @param value the initial value for the calculation
* @return a {@code ChainedCalcUtil} instance for performing chained calculations * @return a {@code ChainedCalcUtil} instance for performing chained calculations
*/ */
public static ChainedCalcUtil startWith(Number value) { public static Calculator startWith(Number value) {
return new ChainedCalcUtil(value); return new Calculator(value);
} }
/** /**
@@ -120,7 +120,7 @@ public final class ChainedCalcUtil {
* @param other the value to be added * @param other the value to be added
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil add(Number other) { public Calculator add(Number other) {
return operator(BigDecimal::add, other); return operator(BigDecimal::add, other);
} }
@@ -131,7 +131,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation * @param beforeOperateScale the scale to be applied before the operation
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil add(Number other, Integer beforeOperateScale) { public Calculator add(Number other, Integer beforeOperateScale) {
return operator(BigDecimal::add, other, beforeOperateScale); return operator(BigDecimal::add, other, beforeOperateScale);
} }
@@ -141,7 +141,7 @@ public final class ChainedCalcUtil {
* @param other the value to be subtracted * @param other the value to be subtracted
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil subtract(Number other) { public Calculator subtract(Number other) {
return operator(BigDecimal::subtract, other); return operator(BigDecimal::subtract, other);
} }
@@ -153,7 +153,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation * @param beforeOperateScale the scale to be applied before the operation
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil subtract(Number other, Integer beforeOperateScale) { public Calculator subtract(Number other, Integer beforeOperateScale) {
return operator(BigDecimal::subtract, other, beforeOperateScale); return operator(BigDecimal::subtract, other, beforeOperateScale);
} }
@@ -163,7 +163,7 @@ public final class ChainedCalcUtil {
* @param other the value to be multiplied by * @param other the value to be multiplied by
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil multiply(Number other) { public Calculator multiply(Number other) {
return operator(BigDecimal::multiply, other); return operator(BigDecimal::multiply, other);
} }
@@ -175,7 +175,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation * @param beforeOperateScale the scale to be applied before the operation
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil multiply(Number other, Integer beforeOperateScale) { public Calculator multiply(Number other, Integer beforeOperateScale) {
return operator(BigDecimal::multiply, other, beforeOperateScale); return operator(BigDecimal::multiply, other, beforeOperateScale);
} }
@@ -185,7 +185,7 @@ public final class ChainedCalcUtil {
* @param other the value to divide by * @param other the value to divide by
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil divide(Number other) { public Calculator divide(Number other) {
return operator(BigDecimal::divide, other); return operator(BigDecimal::divide, other);
} }
@@ -196,7 +196,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation * @param beforeOperateScale the scale to be applied before the operation
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil divide(Number other, Integer beforeOperateScale) { public Calculator divide(Number other, Integer beforeOperateScale) {
return operator(BigDecimal::divide, other, beforeOperateScale); return operator(BigDecimal::divide, other, beforeOperateScale);
} }
@@ -207,9 +207,9 @@ public final class ChainedCalcUtil {
* @param scale the scale for the result * @param scale the scale for the result
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil divideWithScale(Number other, Integer scale) { public Calculator divideWithScale(Number other, Integer scale) {
return baseOperator(otherValue -> return baseOperator(otherValue ->
this.value.divide(otherValue, scale, RoundingMode.HALF_UP), other, null); this.value.divide(otherValue, scale, RoundingMode.HALF_UP), other, null);
} }
/** /**
@@ -221,10 +221,10 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation * @param beforeOperateScale the scale to be applied before the operation
* @return a {@code ChainedCalcUtil} instance with the updated value * @return a {@code ChainedCalcUtil} instance with the updated value
*/ */
public ChainedCalcUtil divideWithScale(Number other, Integer scale, Integer beforeOperateScale) { public Calculator divideWithScale(Number other, Integer scale, Integer beforeOperateScale) {
return baseOperator((otherValue) -> return baseOperator((otherValue) ->
this.value.divide(otherValue, scale, RoundingMode.HALF_UP), this.value.divide(otherValue, scale, RoundingMode.HALF_UP),
other, beforeOperateScale); other, beforeOperateScale);
} }
/** /**
@@ -290,7 +290,10 @@ public final class ChainedCalcUtil {
* @param otherValue the value to apply the operator with * @param otherValue the value to apply the operator with
* @return a ChainedCalcUtil instance with the updated value * @return a ChainedCalcUtil instance with the updated value
*/ */
private ChainedCalcUtil operator(BiFunction<BigDecimal, BigDecimal, BigDecimal> operator, Object otherValue) { private Calculator operator(
BiFunction<BigDecimal, BigDecimal, BigDecimal> operator,
Object otherValue
) {
return operator(operator, otherValue, 9); return operator(operator, otherValue, 9);
} }
@@ -304,13 +307,16 @@ public final class ChainedCalcUtil {
* or null if not applicable * or null if not applicable
* @return a ChainedCalcUtil instance with the updated value * @return a ChainedCalcUtil instance with the updated value
*/ */
private ChainedCalcUtil operator(BiFunction<BigDecimal, BigDecimal, BigDecimal> operator, private Calculator operator(
Object other, BiFunction<BigDecimal, BigDecimal, BigDecimal> operator,
Integer beforeOperateScale) { Object other,
return baseOperator((otherValue) -> Integer beforeOperateScale
operator.apply(this.value, otherValue), ) {
other, return baseOperator(
beforeOperateScale); (otherValue) -> operator.apply(this.value, otherValue),
other,
beforeOperateScale
);
} }
/** /**
@@ -323,14 +329,16 @@ public final class ChainedCalcUtil {
* or null if not applicable * or null if not applicable
* @return a ChainedCalcUtil instance with the updated value * @return a ChainedCalcUtil instance with the updated value
*/ */
private synchronized ChainedCalcUtil baseOperator(Function<BigDecimal, BigDecimal> operatorFunction, private synchronized Calculator baseOperator(
Object anotherValue, Function<BigDecimal, BigDecimal> operatorFunction,
Integer beforeOperateScale) { Object anotherValue,
Integer beforeOperateScale
) {
if (Objects.isNull(anotherValue)) { if (Objects.isNull(anotherValue)) {
return this; return this;
} }
if (anotherValue instanceof ChainedCalcUtil) { if (anotherValue instanceof Calculator) {
this.value = operatorFunction.apply(((ChainedCalcUtil) anotherValue).getValue()); this.value = operatorFunction.apply(((Calculator) anotherValue).getValue());
return this; return this;
} }
this.value = operatorFunction.apply(convertBigDecimal(anotherValue, beforeOperateScale)); this.value = operatorFunction.apply(convertBigDecimal(anotherValue, beforeOperateScale));
@@ -366,8 +374,7 @@ public final class ChainedCalcUtil {
} }
/** /**
* -- GETTER -- * Final result.
* Returns the current value as a BigDecimal.
*/ */
private BigDecimal value; private BigDecimal value;
+21 -19
View File
@@ -1,28 +1,30 @@
/* /*
* Copyright (C) 2024-2025 OnixByte. * Copyright (c) 2024-2025 OnixByte
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Permission is hereby granted, free of charge, to any person obtaining a copy
* you may not use this file except in compliance with the License. * of this software and associated documentation files (the "Software"), to deal
* You may obtain a copy of the License at * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* *
* Unless required by applicable law or agreed to in writing, software * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* distributed under the License is distributed on an "AS IS" BASIS, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* See the License for the specific language governing permissions and * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* limitations under the License. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
rootProject.name = "onixbyte-toolbox" rootProject.name = "onixbyte-toolbox"
include( include("version-catalogue")
"version-catalogue", include("common-toolbox")
"common-toolbox",
"identity-generator",
"crypto-toolbox",
"math-toolbox",
)
include("tuple") include("tuple")
include("identity-generator")
include("crypto-toolbox")
include("math-toolbox")
-3
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project val licenseName: String by project
val licenseUrl: String by project val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@@ -1,52 +0,0 @@
/*
* Copyright (C) 2024-2025 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.tuple;
/**
* Represents an immutable pair of two elements, referred to as 'left' and 'right'. This class
* provides a simple way to group two values without the need to create a custom class for each
* specific pair.
* <p>
* The generic types {@code L} and {@code R} denote the types of the left and right elements,
* respectively. Instances of this class are immutable once created.
*
* @param <L> the type of the left element
* @param <R> the type of the right element
* @param left the left element of this tuple
* @param right the right element of this tuple
* @author siujamo
* @author zihluwang
*/
public record ImmutableBiTuple<L, R>(
L left,
R right
) {
/**
* Creates a new {@code ImmutableBiTuple} with the specified left and right elements.
*
* @param <L> the type of the left element
* @param <R> the type of the right element
* @param left the left element
* @param right the right element
* @return a new {@code ImmutableBiTuple} containing the specified elements
*/
public static <L, R> ImmutableBiTuple<L, R> of(L left, R right) {
return new ImmutableBiTuple<>(left, right);
}
}
@@ -1,57 +0,0 @@
/*
* Copyright (C) 2024-2025 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.tuple;
/**
* Represents an immutable triple of three elements, referred to as 'left', 'middle', and 'right'.
* This class provides a generic way to group three values without the need to create a custom class
* for each specific combination.
* <p>
* The generic types {@code L}, {@code M}, and {@code R} denote the types of the left, middle, and
* right elements, respectively. Instances of this class are immutable once created.
*
* @param <L> the type of the left element
* @param <M> the type of the middle element
* @param <R> the type of the right element
* @param left the left element of this triple
* @param middle the middle element of this triple
* @param right the right element of this triple
* @author siujamo
* @author zihluwang
*/
public record ImmutableTriTuple<L, M, R>(
L left,
M middle,
R right
) {
/**
* Creates a new {@code ImmutableTriTuple} with the specified left, middle, and right elements.
*
* @param <L> the type of the left element
* @param <M> the type of the middle element
* @param <R> the type of the right element
* @param left the left element
* @param middle the middle element
* @param right the right element
* @return a new {@code ImmutableTriTuple} containing the specified elements
*/
public static <L, M, R> ImmutableTriTuple<L, M, R> of(L left, M middle, R right) {
return new ImmutableTriTuple<>(left, middle, right);
}
}
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024-2025 OnixByte
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.tuple;
/**
* Represents an immutable triple of three elements, referred to as 'left', 'middle', and 'right'.
* This class provides a generic way to group three values without the need to create a custom class
* for each specific combination.
* <p>
* The generic types {@code L}, {@code M}, and {@code R} denote the types of the left, middle, and
* right elements, respectively. Instances of this class are immutable once created.
*
* @param <L> the type of the left element
* @param <M> the type of the middle element
* @param <R> the type of the right element
* @param left the left element of this triple
* @param middle the middle element of this triple
* @param right the right element of this triple
* @author siujamo
* @author zihluwang
*/
public record ImmutableTriple<L, M, R>(
L left,
M middle,
R right
) {
/**
* Creates a new {@code ImmutableTriple} with the specified left, middle, and right elements.
*
* @param <L> the type of the left element
* @param <M> the type of the middle element
* @param <R> the type of the right element
* @param left the left element
* @param middle the middle element
* @param right the right element
* @return a new {@code ImmutableTriple} containing the specified elements
*/
public static <L, M, R> ImmutableTriple<L, M, R> of(L left, M middle, R right) {
return new ImmutableTriple<>(left, middle, right);
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2024-2025 OnixByte
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.onixbyte.tuple;
/**
* Represents an immutable pair of two elements, referred to as 'left' and 'right'. This class
* provides a simple way to group two values without the need to create a custom class for each
* specific pair.
* <p>
* The generic types {@code L} and {@code R} denote the types of the left and right elements,
* respectively. Instances of this class are immutable once created.
*
* @param <L> the type of the left element
* @param <R> the type of the right element
* @param left the left element of this tuple
* @param right the right element of this tuple
* @author siujamo
* @author zihluwang
*/
public record ImmutableTuple<L, R>(
L left,
R right
) {
/**
* Creates a new {@code ImmutableTuple} with the specified left and right elements.
*
* @param <L> the type of the left element
* @param <R> the type of the right element
* @param left the left element
* @param right the right element
* @return a new {@code ImmutableTuple} containing the specified elements
*/
public static <L, R> ImmutableTuple<L, R> of(L left, R right) {
return new ImmutableTuple<>(left, right);
}
}
@@ -1,18 +1,23 @@
/* /*
* Copyright (C) 2024-2025 OnixByte. * Copyright (c) 2024-2025 OnixByte
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Permission is hereby granted, free of charge, to any person obtaining a copy
* you may not use this file except in compliance with the License. * of this software and associated documentation files (the "Software"), to deal
* You may obtain a copy of the License at * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* *
* Unless required by applicable law or agreed to in writing, software * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* distributed under the License is distributed on an "AS IS" BASIS, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* See the License for the specific language governing permissions and * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* limitations under the License. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
package com.onixbyte.tuple; package com.onixbyte.tuple;
@@ -32,31 +37,20 @@ import java.util.Objects;
* @author siujamo * @author siujamo
* @author zihluwang * @author zihluwang
*/ */
public final class TriTuple<L, M, R> { public final class Triple<L, M, R> {
/**
* The left element of the triple.
*/
private L left; private L left;
/**
* The middle element of the triple.
*/
private M middle; private M middle;
/**
* The right element of the triple.
*/
private R right; private R right;
/** /**
* Constructs a new {@code TriTuple} with the given left, middle and right elements. * Constructs a new {@code Triple} with the given left, middle and right elements.
* *
* @param left the left element * @param left the left element
* @param middle the middle element * @param middle the middle element
* @param right the right element * @param right the right element
*/ */
public TriTuple(L left, M middle, R right) { public Triple(L left, M middle, R right) {
this.left = left; this.left = left;
this.middle = middle; this.middle = middle;
this.right = right; this.right = right;
@@ -117,22 +111,23 @@ public final class TriTuple<L, M, R> {
} }
/** /**
* Checks if this {@code TriTuple} is equal to the specified object. * Checks if this {@code Triple} is equal to the specified object. Two {@code Triple}s are
* Two {@code TriTuple}s are considered equal if their left, middle and right elements are equal. * considered equal if their left, middle and right elements are equal.
* *
* @param object the object to compare with * @param object the object to compare with
* @return {@code true} if the objects are equal, {@code false} otherwise * @return {@code true} if the objects are equal, {@code false} otherwise
*/ */
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (!(object instanceof TriTuple<?, ?, ?> triTuple)) return false; if (!(object instanceof Triple<?, ?, ?> triple)) return false;
return Objects.equals(left, triTuple.left) && return Objects.equals(left, triple.left) &&
Objects.equals(middle, triTuple.middle) && Objects.equals(middle, triple.middle) &&
Objects.equals(right, triTuple.right); Objects.equals(right, triple.right);
} }
/** /**
* Calculates the hash code for this {@code TriTuple} based on its left, middle and right elements. * Calculates the hash code for this {@code Triple} based on its left, middle and
* right elements.
* *
* @return the hash code value for this object * @return the hash code value for this object
*/ */
@@ -142,13 +137,14 @@ public final class TriTuple<L, M, R> {
} }
/** /**
* Returns a string representation of this {@code TriTuple}, including its left, middle and right elements. * Returns a string representation of this {@code Triple}, including its left, middle and
* right elements.
* *
* @return a string representation of the object * @return a string representation of the object
*/ */
@Override @Override
public String toString() { public String toString() {
return "TriTuple{" + return "Triple{" +
"left=" + left + "left=" + left +
", middle=" + middle + ", middle=" + middle +
", right=" + right + ", right=" + right +
@@ -156,7 +152,7 @@ public final class TriTuple<L, M, R> {
} }
/** /**
* Factory method to create a new {@code TriTuple} instance with the given left, middle and right elements. * Factory method to create a new {@code Triple} instance with the given left, middle and right elements.
* *
* @param left the left element * @param left the left element
* @param middle the middle element * @param middle the middle element
@@ -164,9 +160,9 @@ public final class TriTuple<L, M, R> {
* @param <L> the type of the left element * @param <L> the type of the left element
* @param <M> the type of the middle element * @param <M> the type of the middle element
* @param <R> the type of the right element * @param <R> the type of the right element
* @return a new {@code TriTuple} instance * @return a new {@code Triple} instance
*/ */
public static <L, M, R> TriTuple<L, M, R> of(L left, M middle, R right) { public static <L, M, R> Triple<L, M, R> of(L left, M middle, R right) {
return new TriTuple<>(left, middle, right); return new Triple<>(left, middle, right);
} }
} }
@@ -1,18 +1,23 @@
/* /*
* Copyright (C) 2024-2025 OnixByte. * Copyright (c) 2024-2025 OnixByte
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Permission is hereby granted, free of charge, to any person obtaining a copy
* you may not use this file except in compliance with the License. * of this software and associated documentation files (the "Software"), to deal
* You may obtain a copy of the License at * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* *
* Unless required by applicable law or agreed to in writing, software * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* distributed under the License is distributed on an "AS IS" BASIS, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* See the License for the specific language governing permissions and * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* limitations under the License. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
package com.onixbyte.tuple; package com.onixbyte.tuple;
@@ -33,25 +38,18 @@ import java.util.Objects;
* @author siujamo * @author siujamo
* @author zihluwang * @author zihluwang
*/ */
public final class BiTuple<L, R> { public final class Tuple<L, R> {
/**
* The left element of the tuple.
*/
private L left; private L left;
/**
* The right element of the tuple.
*/
private R right; private R right;
/** /**
* Constructs a new {@code BiTuple} with the specified left and right elements. * Constructs a new {@code Tuple} with the specified left and right elements.
* *
* @param left the left element to be stored in the tuple * @param left the left element to be stored in the tuple
* @param right the right element to be stored in the tuple * @param right the right element to be stored in the tuple
*/ */
public BiTuple(L left, R right) { public Tuple(L left, R right) {
this.left = left; this.left = left;
this.right = right; this.right = right;
} }
@@ -93,27 +91,27 @@ public final class BiTuple<L, R> {
} }
/** /**
* Compares this {@code BiTuple} with the specified object for equality. * Compares this {@code Tuple} with the specified object for equality.
* <p> * <p>
* Two {@code BiTuple}s are considered equal if they are of the same type and their left and * Two {@code Tuple}s are considered equal if they are of the same type and their left and
* right elements are equal according to their respective {@code equals} methods. * right elements are equal according to their respective {@code equals} methods.
* *
* @param object the object to compare with this {@code BiTuple} * @param object the object to compare with this {@code Tuple}
* @return {@code true} if the specified object is equal to this {@code BiTuple}, * @return {@code true} if the specified object is equal to this {@code Tuple},
* {@code false} otherwise * {@code false} otherwise
*/ */
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (!(object instanceof BiTuple<?, ?> biTuple)) return false; if (!(object instanceof Tuple<?, ?> tuple)) return false;
return Objects.equals(left, biTuple.left) && Objects.equals(right, biTuple.right); return Objects.equals(left, tuple.left) && Objects.equals(right, tuple.right);
} }
/** /**
* Returns a hash code value for the {@code BiTuple}. * Returns a hash code value for the {@code Tuple}.
* <p> * <p>
* The hash code is calculated based on the hash codes of the left and right elements. * The hash code is calculated based on the hash codes of the left and right elements.
* *
* @return a hash code value for this {@code BiTuple} * @return a hash code value for this {@code Tuple}
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
@@ -121,31 +119,31 @@ public final class BiTuple<L, R> {
} }
/** /**
* Returns a string representation of the {@code BiTuple}. * Returns a string representation of the {@code Tuple}.
* <p> * <p>
* The string representation consists of the class name, followed by the values of * The string representation consists of the class name, followed by the values of
* the left and right elements in the format {@code "BiTuple{left=value1, right=value2}"}. * the left and right elements in the format {@code "Tuple{left=value1, right=value2}"}.
* *
* @return a string representation of the {@code BiTuple} * @return a string representation of the {@code Tuple}
*/ */
@Override @Override
public String toString() { public String toString() {
return "BiTuple{" + return "Tuple{" +
"left=" + left + "left=" + left +
", right=" + right + ", right=" + right +
'}'; '}';
} }
/** /**
* Creates a new {@code BiTuple} with the specified left and right elements. * Creates a new {@code Tuple} with the specified left and right elements.
* *
* @param <L> the type of the left element * @param <L> the type of the left element
* @param <R> the type of the right element * @param <R> the type of the right element
* @param left the left element * @param left the left element
* @param right the right element * @param right the right element
* @return a new {@code BiTuple} containing the specified elements * @return a new {@code Tuple} containing the specified elements
*/ */
public static <L, R> BiTuple<L, R> of(L left, R right) { public static <L, R> Tuple<L, R> of(L left, R right) {
return new BiTuple<>(left, right); return new Tuple<>(left, right);
} }
} }
+1 -3
View File
@@ -34,9 +34,6 @@ val projectGithubUrl: String by project
val licenseName: String by project val licenseName: String by project
val licenseUrl: String by project val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories { repositories {
mavenCentral() mavenCentral()
} }
@@ -47,6 +44,7 @@ dependencies {
api("com.onixbyte:identity-generator:$artefactVersion") api("com.onixbyte:identity-generator:$artefactVersion")
api("com.onixbyte:crypto-toolbox:$artefactVersion") api("com.onixbyte:crypto-toolbox:$artefactVersion")
api("com.onixbyte:math-toolbox:$artefactVersion") api("com.onixbyte:math-toolbox:$artefactVersion")
api("com.onixbyte:tuple:$artefactVersion")
} }
} }