diff --git a/tuple/build.gradle.kts b/tuple/build.gradle.kts new file mode 100644 index 0000000..a9eb008 --- /dev/null +++ b/tuple/build.gradle.kts @@ -0,0 +1,132 @@ +/* + * 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. + */ + +import java.net.URI + +plugins { + java + id("java-library") + id("maven-publish") + id("signing") +} + +val artefactVersion: String by project +val projectUrl: String by project +val projectGithubUrl: String by project +val licenseName: String by project +val licenseUrl: String by project + +group = "com.onixbyte" +version = artefactVersion + +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 = artefactVersion + + 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 { + 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/ImmutableTriTuple.java b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriTuple.java new file mode 100644 index 0000000..2a13c68 --- /dev/null +++ b/tuple/src/main/java/com/onixbyte/tuple/ImmutableTriTuple.java @@ -0,0 +1,57 @@ +/* + * 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 TriTuple} 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 TriTuple} containing the specified elements + */ + public static ImmutableTriTuple of(L left, M middle, R right) { + return new ImmutableTriTuple<>(left, middle, right); + } +}