diff --git a/build.gradle.kts b/build.gradle.kts index 533233b..cc56930 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 +} diff --git a/common-toolbox/build.gradle.kts b/common-toolbox/build.gradle.kts index 12d83a9..973cef2 100644 --- a/common-toolbox/build.gradle.kts +++ b/common-toolbox/build.gradle.kts @@ -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() } diff --git a/common-toolbox/src/main/java/com/onixbyte/common/util/ObjectMapAdapter.java b/common-toolbox/src/main/java/com/onixbyte/common/adapter/ObjectMapAdapter.java similarity index 98% rename from common-toolbox/src/main/java/com/onixbyte/common/util/ObjectMapAdapter.java rename to common-toolbox/src/main/java/com/onixbyte/common/adapter/ObjectMapAdapter.java index aa66469..4852fa2 100644 --- a/common-toolbox/src/main/java/com/onixbyte/common/util/ObjectMapAdapter.java +++ b/common-toolbox/src/main/java/com/onixbyte/common/adapter/ObjectMapAdapter.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package com.onixbyte.common.util; +package com.onixbyte.common.adapter; import java.util.Map; diff --git a/common-toolbox/src/main/java/com/onixbyte/common/util/MapUtil.java b/common-toolbox/src/main/java/com/onixbyte/common/util/MapUtil.java index a558cb7..050a003 100644 --- a/common-toolbox/src/main/java/com/onixbyte/common/util/MapUtil.java +++ b/common-toolbox/src/main/java/com/onixbyte/common/util/MapUtil.java @@ -22,6 +22,8 @@ package com.onixbyte.common.util; +import com.onixbyte.common.adapter.ObjectMapAdapter; + import java.util.Map; /** diff --git a/crypto-toolbox/build.gradle.kts b/crypto-toolbox/build.gradle.kts index 81139e1..c0692c4 100644 --- a/crypto-toolbox/build.gradle.kts +++ b/crypto-toolbox/build.gradle.kts @@ -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 { dependencies { compileOnly(libs.slf4j) implementation(libs.logback) - testImplementation(libs.jwt.core) testImplementation(platform(libs.junit.bom)) testImplementation(libs.junit.jupiter) } diff --git a/gradle.properties b/gradle.properties index 3c0b678..6dcdc54 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 64b7a22..44bd9ab 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/identity-generator/build.gradle.kts b/identity-generator/build.gradle.kts index d3c7471..92cf544 100644 --- a/identity-generator/build.gradle.kts +++ b/identity-generator/build.gradle.kts @@ -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() } diff --git a/identity-generator/src/main/java/com/onixbyte/identitygenerator/impl/SnowflakeIdentityGenerator.java b/identity-generator/src/main/java/com/onixbyte/identitygenerator/impl/SnowflakeIdentityGenerator.java index f3def6d..4f4c152 100644 --- a/identity-generator/src/main/java/com/onixbyte/identitygenerator/impl/SnowflakeIdentityGenerator.java +++ b/identity-generator/src/main/java/com/onixbyte/identitygenerator/impl/SnowflakeIdentityGenerator.java @@ -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: * *

- * 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 */ 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 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 } // 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); } - } - // timestamp change, sequence reset in milliseconds - else { + } else { + // timestamp change, sequence reset in milliseconds sequence = 0L; } @@ -173,8 +172,8 @@ public final class SnowflakeIdentityGenerator implements IdentityGenerator 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) diff --git a/math-toolbox/build.gradle.kts b/math-toolbox/build.gradle.kts index 9226aa3..daba828 100644 --- a/math-toolbox/build.gradle.kts +++ b/math-toolbox/build.gradle.kts @@ -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() } diff --git a/math-toolbox/src/main/java/com/onixbyte/math/ChainedCalcUtil.java b/math-toolbox/src/main/java/com/onixbyte/math/Calculator.java similarity index 82% rename from math-toolbox/src/main/java/com/onixbyte/math/ChainedCalcUtil.java rename to math-toolbox/src/main/java/com/onixbyte/math/Calculator.java index 51d31fd..ef692a4 100644 --- a/math-toolbox/src/main/java/com/onixbyte/math/ChainedCalcUtil.java +++ b/math-toolbox/src/main/java/com/onixbyte/math/Calculator.java @@ -38,45 +38,45 @@ import java.util.function.Function; * Usage: *

  *  // 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);
  *  
@@ -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,9 +207,9 @@ 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); + 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 * @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); + 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 operator, Object otherValue) { + private Calculator operator( + BiFunction 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 operator, - Object other, - Integer beforeOperateScale) { - return baseOperator((otherValue) -> - operator.apply(this.value, otherValue), - other, - beforeOperateScale); + private Calculator operator( + BiFunction operator, + Object other, + Integer beforeOperateScale + ) { + return baseOperator( + (otherValue) -> operator.apply(this.value, otherValue), + other, + 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 operatorFunction, - Object anotherValue, - Integer beforeOperateScale) { + private synchronized Calculator baseOperator( + Function operatorFunction, + Object anotherValue, + 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; diff --git a/settings.gradle.kts b/settings.gradle.kts index 415ef24..92c83e6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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("tuple") \ No newline at end of file +include("version-catalogue") +include("common-toolbox") +include("tuple") +include("identity-generator") +include("crypto-toolbox") +include("math-toolbox") diff --git a/tuple/build.gradle.kts b/tuple/build.gradle.kts index a9eb008..ca2a955 100644 --- a/tuple/build.gradle.kts +++ b/tuple/build.gradle.kts @@ -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() } diff --git a/tuple/src/main/java/com/onixbyte/tuple/ImmutableBiTuple.java b/tuple/src/main/java/com/onixbyte/tuple/ImmutableBiTuple.java deleted file mode 100644 index 48b38b3..0000000 --- a/tuple/src/main/java/com/onixbyte/tuple/ImmutableBiTuple.java +++ /dev/null @@ -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. - *

- * 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 the type of the left element - * @param 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 left, - R right -) { - - /** - * Creates a new {@code ImmutableBiTuple} with the specified left and right elements. - * - * @param the type of the left element - * @param 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 ImmutableBiTuple of(L left, R right) { - return new ImmutableBiTuple<>(left, right); - } -} diff --git a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriTuple.java b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriTuple.java deleted file mode 100644 index 1db986b..0000000 --- a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriTuple.java +++ /dev/null @@ -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. - *

- * 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 the type of the left element - * @param the type of the middle element - * @param 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 left, - M middle, - R right -) { - - /** - * Creates a new {@code ImmutableTriTuple} with the specified left, middle, and right elements. - * - * @param the type of the left element - * @param the type of the middle element - * @param 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 ImmutableTriTuple of(L left, M middle, R right) { - return new ImmutableTriTuple<>(left, middle, right); - } -} diff --git a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriple.java b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriple.java new file mode 100644 index 0000000..56d90d3 --- /dev/null +++ b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriple.java @@ -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. + *

+ * 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 the type of the left element + * @param the type of the middle element + * @param 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 left, + M middle, + R right +) { + + /** + * Creates a new {@code ImmutableTriple} with the specified left, middle, and right elements. + * + * @param the type of the left element + * @param the type of the middle element + * @param 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 ImmutableTriple of(L left, M middle, R right) { + return new ImmutableTriple<>(left, middle, right); + } +} diff --git a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTuple.java b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTuple.java new file mode 100644 index 0000000..f74451d --- /dev/null +++ b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTuple.java @@ -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. + *

+ * 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 the type of the left element + * @param 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 left, + R right +) { + + /** + * Creates a new {@code ImmutableTuple} with the specified left and right elements. + * + * @param the type of the left element + * @param 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 ImmutableTuple of(L left, R right) { + return new ImmutableTuple<>(left, right); + } +} diff --git a/tuple/src/main/java/com/onixbyte/tuple/TriTuple.java b/tuple/src/main/java/com/onixbyte/tuple/Triple.java similarity index 56% rename from tuple/src/main/java/com/onixbyte/tuple/TriTuple.java rename to tuple/src/main/java/com/onixbyte/tuple/Triple.java index 3f0ffe1..95e8774 100644 --- a/tuple/src/main/java/com/onixbyte/tuple/TriTuple.java +++ b/tuple/src/main/java/com/onixbyte/tuple/Triple.java @@ -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 { +public final class Triple { - /** - * 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 { } /** - * 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 { } /** - * 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 { } /** - * 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 { * @param the type of the left element * @param the type of the middle element * @param the type of the right element - * @return a new {@code TriTuple} instance + * @return a new {@code Triple} instance */ - public static TriTuple of(L left, M middle, R right) { - return new TriTuple<>(left, middle, right); + public static Triple of(L left, M middle, R right) { + return new Triple<>(left, middle, right); } } diff --git a/tuple/src/main/java/com/onixbyte/tuple/BiTuple.java b/tuple/src/main/java/com/onixbyte/tuple/Tuple.java similarity index 54% rename from tuple/src/main/java/com/onixbyte/tuple/BiTuple.java rename to tuple/src/main/java/com/onixbyte/tuple/Tuple.java index 6c7e8ff..cba5ff6 100644 --- a/tuple/src/main/java/com/onixbyte/tuple/BiTuple.java +++ b/tuple/src/main/java/com/onixbyte/tuple/Tuple.java @@ -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 { +public final class Tuple { - /** - * 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 { } /** - * Compares this {@code BiTuple} with the specified object for equality. + * Compares this {@code Tuple} with the specified object for equality. *

- * 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}. *

* 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 { } /** - * Returns a string representation of the {@code BiTuple}. + * Returns a string representation of the {@code Tuple}. *

* 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 the type of the left element * @param 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 BiTuple of(L left, R right) { - return new BiTuple<>(left, right); + public static Tuple of(L left, R right) { + return new Tuple<>(left, right); } } diff --git a/version-catalogue/build.gradle.kts b/version-catalogue/build.gradle.kts index 5c440d3..ad0c74b 100644 --- a/version-catalogue/build.gradle.kts +++ b/version-catalogue/build.gradle.kts @@ -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") } }