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
* 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 licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
@@ -20,7 +20,7 @@
* SOFTWARE.
*/
package com.onixbyte.common.util;
package com.onixbyte.common.adapter;
import java.util.Map;
@@ -22,6 +22,8 @@
package com.onixbyte.common.util;
import com.onixbyte.common.adapter.ObjectMapAdapter;
import java.util.Map;
/**
-4
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
@@ -60,7 +57,6 @@ tasks.withType<Jar> {
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
testImplementation(libs.jwt.core)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
}
+1 -1
View File
@@ -20,7 +20,7 @@
# SOFTWARE.
#
artefactVersion=3.2.0
artefactVersion=3.3.0
projectUrl=https://onixbyte.com/projects/onixbyte-toolbox
projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox
licenseName=MIT
+1 -13
View File
@@ -15,23 +15,11 @@
[versions]
slf4j = "2.0.17"
logback = "1.5.18"
jackson = "2.18.4"
jwt = "4.5.0"
spring = "6.2.6"
springBoot = "3.4.5"
logback = "1.5.26"
junit = "5.11.4"
[libraries]
slf4j = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
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-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 licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
@@ -29,9 +29,9 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* The {@code SnowflakeIdentityGenerator} generates unique identifiers using the Snowflake algorithm,
* which combines a timestamp, worker ID, and data centre ID to create 64-bit long integers. The bit
* distribution for the generated IDs is as follows:
* The {@code SnowflakeIdentityGenerator} generates unique identifiers using the
* Snowflake algorithm, which combines a timestamp, worker ID, and data centre ID to create 64-bit
* long integers. The bit distribution for the generated IDs is as follows:
* <ul>
* <li>1 bit for sign</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>
* </ul>
* <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
* 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
@@ -63,15 +63,15 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
*/
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.
*/
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.
@@ -118,13 +118,13 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
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) {
throw new IllegalArgumentException(String.format("Worker Id can't be greater than %d or less than 0",
maxWorkerId));
}
var maxDataCentreId = ~(-1L << dataCentreIdBits);
var maxDataCentreId = ~(-1L << DATA_CENTRE_ID_BITS);
if (dataCentreId > maxDataCentreId || dataCentreId < 0) {
throw new IllegalArgumentException(String.format("Data Centre Id can't be greater than %d or less than 0",
maxDataCentreId));
@@ -154,18 +154,17 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
}
// if generated at the same time, perform intra-millisecond sequences
long sequenceBits = 12L;
var sequenceBits = 12L;
if (lastTimestamp == timestamp) {
long sequenceMask = ~(-1L << sequenceBits);
var sequenceMask = ~(-1L << sequenceBits);
sequence = (sequence + 1) & sequenceMask;
// sequence overflow in milliseconds
if (sequence == 0) {
// block to the next millisecond, get a new timestamp
timestamp = awaitToNextMillis(lastTimestamp);
}
}
} else {
// timestamp change, sequence reset in milliseconds
else {
sequence = 0L;
}
@@ -173,8 +172,8 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator<Long>
lastTimestamp = timestamp;
// shifted and put together by or operations to form a 64-bit ID
var timestampLeftShift = sequenceBits + workerIdBits + dataCentreIdBits;
var dataCentreIdShift = sequenceBits + workerIdBits;
var timestampLeftShift = sequenceBits + WORKER_ID_BITS + DATA_CENTRE_ID_BITS;
var dataCentreIdShift = sequenceBits + WORKER_ID_BITS;
return ((timestamp - startEpoch) << timestampLeftShift)
| (dataCentreId << dataCentreIdShift)
| (workerId << sequenceBits)
-3
View File
@@ -35,9 +35,6 @@ val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
@@ -38,45 +38,45 @@ import java.util.function.Function;
* <b>Usage:</b>
* <pre>
* // Perform addition: 3 + 4
* BigDecimal result1 = ChainedCalcUtil.startWith(3)
* BigDecimal result1 = Calculator.startWith(3)
* .add(4)
* .getValue();
*
* // Perform subtraction: 4 - 2
* BigDecimal result2 = ChainedCalcUtil.startWith(4)
* BigDecimal result2 = Calculator.startWith(4)
* .subtract(2)
* .getValue();
*
* // Perform multiplication: 3 * 6
* BigDecimal result3 = ChainedCalcUtil.startWith(3)
* BigDecimal result3 = Calculator.startWith(3)
* .multiply(6)
* .getValue();
*
* // Perform division: 6 ÷ 2
* BigDecimal result4 = ChainedCalcUtil.startWith(6)
* BigDecimal result4 = Calculator.startWith(6)
* .divide(2)
* .getValue();
*
* // 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)
* .getValue();
*
* // Get int, long, or double results
* int intResult = ChainedCalcUtil.startWith(3)
* int intResult = Calculator.startWith(3)
* .add(4)
* .getInteger();
*
* long longResult = ChainedCalcUtil.startWith(4)
* long longResult = Calculator.startWith(4)
* .subtract(2)
* .getLong();
*
* double doubleResult = ChainedCalcUtil.startWith(6)
* double doubleResult = Calculator.startWith(6)
* .divide(2)
* .getDouble();
*
* // Get BigDecimal result with specified scale
* BigDecimal result6 = ChainedCalcUtil.startWith(13)
* BigDecimal result6 = Calculator.startWith(13)
* .divide(7)
* .getValue(2);
* </pre>
@@ -89,18 +89,18 @@ import java.util.function.Function;
* and may have performance implications for extremely large numbers or complex calculations.
*
* @author sunzsh
* @version 3.0.0
* @version 3.3.0
* @see BigDecimal
* @since 1.0.0
*/
public final class ChainedCalcUtil {
public final class Calculator {
/**
* Creates a {@code ChainedCalcUtil} instance with the specified initial value.
*
* @param value the initial value for the calculation
*/
private ChainedCalcUtil(Number value) {
private Calculator(Number value) {
this.value = convertBigDecimal(value, null);
}
@@ -110,8 +110,8 @@ public final class ChainedCalcUtil {
* @param value the initial value for the calculation
* @return a {@code ChainedCalcUtil} instance for performing chained calculations
*/
public static ChainedCalcUtil startWith(Number value) {
return new ChainedCalcUtil(value);
public static Calculator startWith(Number value) {
return new Calculator(value);
}
/**
@@ -120,7 +120,7 @@ public final class ChainedCalcUtil {
* @param other the value to be added
* @return a {@code ChainedCalcUtil} instance with the updated value
*/
public ChainedCalcUtil add(Number other) {
public Calculator add(Number other) {
return operator(BigDecimal::add, other);
}
@@ -131,7 +131,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation
* @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);
}
@@ -141,7 +141,7 @@ public final class ChainedCalcUtil {
* @param other the value to be subtracted
* @return a {@code ChainedCalcUtil} instance with the updated value
*/
public ChainedCalcUtil subtract(Number other) {
public Calculator subtract(Number other) {
return operator(BigDecimal::subtract, other);
}
@@ -153,7 +153,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation
* @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);
}
@@ -163,7 +163,7 @@ public final class ChainedCalcUtil {
* @param other the value to be multiplied by
* @return a {@code ChainedCalcUtil} instance with the updated value
*/
public ChainedCalcUtil multiply(Number other) {
public Calculator multiply(Number other) {
return operator(BigDecimal::multiply, other);
}
@@ -175,7 +175,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation
* @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);
}
@@ -185,7 +185,7 @@ public final class ChainedCalcUtil {
* @param other the value to divide by
* @return a {@code ChainedCalcUtil} instance with the updated value
*/
public ChainedCalcUtil divide(Number other) {
public Calculator divide(Number other) {
return operator(BigDecimal::divide, other);
}
@@ -196,7 +196,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation
* @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);
}
@@ -207,7 +207,7 @@ public final class ChainedCalcUtil {
* @param scale the scale for the result
* @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 ->
this.value.divide(otherValue, scale, RoundingMode.HALF_UP), other, null);
}
@@ -221,7 +221,7 @@ public final class ChainedCalcUtil {
* @param beforeOperateScale the scale to be applied before the operation
* @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) ->
this.value.divide(otherValue, scale, RoundingMode.HALF_UP),
other, beforeOperateScale);
@@ -290,7 +290,10 @@ public final class ChainedCalcUtil {
* @param otherValue the value to apply the operator with
* @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);
}
@@ -304,13 +307,16 @@ public final class ChainedCalcUtil {
* or null if not applicable
* @return a ChainedCalcUtil instance with the updated value
*/
private ChainedCalcUtil operator(BiFunction<BigDecimal, BigDecimal, BigDecimal> operator,
private Calculator operator(
BiFunction<BigDecimal, BigDecimal, BigDecimal> operator,
Object other,
Integer beforeOperateScale) {
return baseOperator((otherValue) ->
operator.apply(this.value, otherValue),
Integer beforeOperateScale
) {
return baseOperator(
(otherValue) -> operator.apply(this.value, otherValue),
other,
beforeOperateScale);
beforeOperateScale
);
}
/**
@@ -323,14 +329,16 @@ public final class ChainedCalcUtil {
* or null if not applicable
* @return a ChainedCalcUtil instance with the updated value
*/
private synchronized ChainedCalcUtil baseOperator(Function<BigDecimal, BigDecimal> operatorFunction,
private synchronized Calculator baseOperator(
Function<BigDecimal, BigDecimal> operatorFunction,
Object anotherValue,
Integer beforeOperateScale) {
Integer beforeOperateScale
) {
if (Objects.isNull(anotherValue)) {
return this;
}
if (anotherValue instanceof ChainedCalcUtil) {
this.value = operatorFunction.apply(((ChainedCalcUtil) anotherValue).getValue());
if (anotherValue instanceof Calculator) {
this.value = operatorFunction.apply(((Calculator) anotherValue).getValue());
return this;
}
this.value = operatorFunction.apply(convertBigDecimal(anotherValue, beforeOperateScale));
@@ -366,8 +374,7 @@ public final class ChainedCalcUtil {
}
/**
* -- GETTER --
* Returns the current value as a BigDecimal.
* Final result.
*/
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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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:
*
* 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
* 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.
* 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.
*/
rootProject.name = "onixbyte-toolbox"
include(
"version-catalogue",
"common-toolbox",
"identity-generator",
"crypto-toolbox",
"math-toolbox",
)
include("version-catalogue")
include("common-toolbox")
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 licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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:
*
* 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
* 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.
* 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;
@@ -32,31 +37,20 @@ import java.util.Objects;
* @author siujamo
* @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;
/**
* The middle element of the triple.
*/
private M middle;
/**
* The right element of the triple.
*/
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 middle the middle 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.middle = middle;
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.
* Two {@code TriTuple}s are considered equal if their left, middle and right elements are equal.
* Checks if this {@code Triple} is equal to the specified object. Two {@code Triple}s are
* considered equal if their left, middle and right elements are equal.
*
* @param object the object to compare with
* @return {@code true} if the objects are equal, {@code false} otherwise
*/
@Override
public boolean equals(Object object) {
if (!(object instanceof TriTuple<?, ?, ?> triTuple)) return false;
return Objects.equals(left, triTuple.left) &&
Objects.equals(middle, triTuple.middle) &&
Objects.equals(right, triTuple.right);
if (!(object instanceof Triple<?, ?, ?> triple)) return false;
return Objects.equals(left, triple.left) &&
Objects.equals(middle, triple.middle) &&
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
*/
@@ -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
*/
@Override
public String toString() {
return "TriTuple{" +
return "Triple{" +
"left=" + left +
", middle=" + middle +
", 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 middle the middle element
@@ -164,9 +160,9 @@ public final class TriTuple<L, M, R> {
* @param <L> the type of the left element
* @param <M> the type of the middle 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) {
return new TriTuple<>(left, middle, right);
public static <L, M, R> Triple<L, M, R> of(L left, M middle, R 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");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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:
*
* 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
* 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.
* 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;
@@ -33,25 +38,18 @@ import java.util.Objects;
* @author siujamo
* @author zihluwang
*/
public final class BiTuple<L, R> {
public final class Tuple<L, R> {
/**
* The left element of the tuple.
*/
private L left;
/**
* The right element of the tuple.
*/
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 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.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>
* 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.
*
* @param object the object to compare with this {@code BiTuple}
* @return {@code true} if the specified object is equal to 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 Tuple},
* {@code false} otherwise
*/
@Override
public boolean equals(Object object) {
if (!(object instanceof BiTuple<?, ?> biTuple)) return false;
return Objects.equals(left, biTuple.left) && Objects.equals(right, biTuple.right);
if (!(object instanceof Tuple<?, ?> tuple)) return false;
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>
* 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
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>
* 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
public String toString() {
return "BiTuple{" +
return "Tuple{" +
"left=" + left +
", 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 <R> the type of the right element
* @param left the left 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) {
return new BiTuple<>(left, right);
public static <L, R> Tuple<L, R> of(L left, R 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 licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
@@ -47,6 +44,7 @@ dependencies {
api("com.onixbyte:identity-generator:$artefactVersion")
api("com.onixbyte:crypto-toolbox:$artefactVersion")
api("com.onixbyte:math-toolbox:$artefactVersion")
api("com.onixbyte:tuple:$artefactVersion")
}
}