diff --git a/settings.gradle.kts b/settings.gradle.kts index 92c83e6..c64a8fd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,7 +24,6 @@ rootProject.name = "onixbyte-toolbox" include("version-catalogue") include("common-toolbox") -include("tuple") include("identity-generator") include("crypto-toolbox") include("math-toolbox") diff --git a/tuple/README.md b/tuple/README.md deleted file mode 100644 index b0eb7d1..0000000 --- a/tuple/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# Tuple - -## Introduction - -The `tuple` module provides simple and efficient implementations of mutable and immutable bi-tuples and tri-tuples. These tuples allow you to group two or three values together without creating custom classes, supporting convenient usage in various programming scenarios. - -## Features - -- Immutable and mutable versions of bi-tuples (pairs) and tri-tuples (triplets); -- Factory method of() for easy instantiation of all tuple types; -- Simple, lightweight implementation compatible with standard Java usage; -- Clear distinction between mutable and immutable tuples for flexibility. - -## Installation - -### Maven - -Add the following dependency to your `pom.xml`: - -```xml - - com.onixbyte - tuple - $artefactVersion - -``` - -### Gradle - -#### Version Catalogue - -Add the following codes to you `gradle/libs.versions.toml`: - -```toml -[version] -onixbyteToolbox = "$artefactVersion" - -[libraries] -onixbyteToolbox-tuple = { group = "com.onixbyte", name = "tuple", version.ref = "onixbyteToolbox" } -``` - -Then add the following codes to your `build.gradle.kts` or `build.gradle` dependencies block: - -```kotlin -implementation(libs.onixbyteToolbox.tuple) -``` - -```groovy -implementation libs.onixbyteToolbox.tuple -``` - -#### Kotlin DSL - -Add the following line to your `build.gradle.kts` dependencies block: - -```kotlin -implementation("com.onixbyte:tuple:$artefactVersion") -``` - -#### Groovy DSL - -Add the following line to your `build.gradle` dependencies block: - -```groovy -implementation 'com.onixbyte:tuple:${artefactVersion}' -``` - -## Dependencies - -This module has no external dependencies other than the standard Java SDK. - -## Acknowledgement - -Thanks to all contributors who helped develop this module, improving its design, performance, and documentation over time. diff --git a/tuple/build.gradle.kts b/tuple/build.gradle.kts deleted file mode 100644 index ba5fdda..0000000 --- a/tuple/build.gradle.kts +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2024-2026 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. - */ - -import java.net.URI - -plugins { - java - id("java-library") - id("maven-publish") - id("signing") -} - -val tupleVersion: String by project - -version = tupleVersion -val projectUrl: String by project -val projectGithubUrl: String by project -val licenseName: String by project -val licenseUrl: String by project - -repositories { - mavenCentral() -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - withSourcesJar() - withJavadocJar() -} - -tasks.withType { - options.encoding = "UTF-8" -} - -tasks.withType { - exclude("logback.xml") -} - -dependencies { - compileOnly(libs.slf4j) - implementation(libs.logback) - testImplementation(platform(libs.junit.bom)) - testImplementation(libs.junit.jupiter) -} - -tasks.test { - useJUnitPlatform() -} - -publishing { - publications { - create("tuple") { - groupId = group.toString() - artifactId = "tuple" - version = tupleVersion - - pom { - name = "OnixByte Tuple" - description = - "The tuple module is designed to offer a convenient and efficient way to handle grouped data." - url = projectUrl - - licenses { - license { - name = licenseName - url = licenseUrl - } - } - - scm { - connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git" - developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git" - url = projectGithubUrl - } - - developers { - developer { - id = "zihluwang" - name = "Zihlu Wang" - email = "really@zihlu.wang" - timezone = "Asia/Hong_Kong" - } - - developer { - id = "siujamo" - name = "Siu Jam'o" - email = "jamo.siu@outlook.com" - timezone = "Asia/Shanghai" - } - } - } - - from(components["java"]) - - signing { - setRequired(project.hasProperty("signing.keyId")) - sign(publishing.publications["tuple"]) - } - } - - repositories { - maven { - name = "sonatypeNexus" - url = URI(providers.gradleProperty("repo.maven-central.host").get()) - credentials { - username = providers.gradleProperty("repo.maven-central.username").get() - password = providers.gradleProperty("repo.maven-central.password").get() - } - } - } - } -} diff --git a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriple.java b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriple.java deleted file mode 100644 index 26d43ac..0000000 --- a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriple.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2024-2026 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 deleted file mode 100644 index 6e31e46..0000000 --- a/tuple/src/main/java/com/onixbyte/tuple/ImmutableTuple.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2024-2026 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/Triple.java b/tuple/src/main/java/com/onixbyte/tuple/Triple.java deleted file mode 100644 index 531e196..0000000 --- a/tuple/src/main/java/com/onixbyte/tuple/Triple.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2024-2026 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; - -import java.util.Objects; - -/** - * Represents a mutable triple of three elements, referred to as 'left', 'middle' and 'right'. - * This class provides a way to group three values of different types. - *

- * The generic types {@code L}, {@code M} and {@code R} denote the types of the left, middle and - * right elements respectively. - * - * @param the type of the left element - * @param the type of the middle element - * @param the type of the right element - * @author siujamo - * @author zihluwang - */ -public final class Triple { - - private L left; - private M middle; - private R right; - - /** - * 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 Triple(L left, M middle, R right) { - this.left = left; - this.middle = middle; - this.right = right; - } - - /** - * Retrieves the left element of the triple. - * - * @return the left element - */ - public L getLeft() { - return left; - } - - /** - * Sets the left element of the triple. - * - * @param left the new left element - */ - public void setLeft(L left) { - this.left = left; - } - - /** - * Retrieves the middle element of the triple. - * - * @return the middle element - */ - public M getMiddle() { - return middle; - } - - /** - * Sets the middle element of the triple. - * - * @param middle the new middle element - */ - public void setMiddle(M middle) { - this.middle = middle; - } - - /** - * Retrieves the right element of the triple. - * - * @return the right element - */ - public R getRight() { - return right; - } - - /** - * Sets the right element of the triple. - * - * @param right the new right element - */ - public void setRight(R right) { - this.right = right; - } - - /** - * 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 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 Triple} based on its left, middle and - * right elements. - * - * @return the hash code value for this object - */ - @Override - public int hashCode() { - return Objects.hash(left, middle, right); - } - - /** - * 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 "Triple{" + - "left=" + left + - ", middle=" + middle + - ", right=" + right + - '}'; - } - - /** - * 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 - * @param right the right element - * @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 Triple} instance - */ - 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/Tuple.java b/tuple/src/main/java/com/onixbyte/tuple/Tuple.java deleted file mode 100644 index 9763941..0000000 --- a/tuple/src/main/java/com/onixbyte/tuple/Tuple.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2024-2026 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; - -import java.util.Objects; - -/** - * Represents an ordered pair of elements, where the first element is of type {@code L} and the - * second is of type {@code R}. This class provides a simple way to group two related - * values together. - *

- * The class is mutable, allowing the values of the left and right elements to be changed - * after creation. It also overrides the {@code equals}, {@code hashCode}, and {@code toString} - * methods to provide meaningful comparisons and string representations. - * - * @param the type of the left element - * @param the type of the right element - * @author siujamo - * @author zihluwang - */ -public final class Tuple { - - private L left; - private R right; - - /** - * 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 Tuple(L left, R right) { - this.left = left; - this.right = right; - } - - /** - * Retrieves the left element of the tuple. - * - * @return the left element of the tuple - */ - public L getLeft() { - return left; - } - - /** - * Sets the left element of the tuple to the specified value. - * - * @param left the new value for the left element of the tuple - */ - public void setLeft(L left) { - this.left = left; - } - - /** - * Retrieves the right element of the tuple. - * - * @return the right element of the tuple - */ - public R getRight() { - return right; - } - - /** - * Sets the right element of the tuple to the specified value. - * - * @param right the new value for the right element of the tuple - */ - public void setRight(R right) { - this.right = right; - } - - /** - * Compares this {@code Tuple} with the specified object for equality. - *

- * 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 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 Tuple tuple)) return false; - return Objects.equals(left, tuple.left) && Objects.equals(right, tuple.right); - } - - /** - * 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 Tuple} - */ - @Override - public int hashCode() { - return Objects.hash(left, right); - } - - /** - * 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 "Tuple{left=value1, right=value2}"}. - * - * @return a string representation of the {@code Tuple} - */ - @Override - public String toString() { - return "Tuple{" + - "left=" + left + - ", right=" + right + - '}'; - } - - /** - * 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 Tuple} containing the specified elements - */ - public static Tuple of(L left, R right) { - return new Tuple<>(left, right); - } -}