Skip to content

Commit b061efc

Browse files
committed
feat: add immutable tri tuple
1 parent f6eb4bd commit b061efc

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed

tuple/build.gradle.kts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2024-2025 OnixByte
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
import java.net.URI
24+
25+
plugins {
26+
java
27+
id("java-library")
28+
id("maven-publish")
29+
id("signing")
30+
}
31+
32+
val artefactVersion: String by project
33+
val projectUrl: String by project
34+
val projectGithubUrl: String by project
35+
val licenseName: String by project
36+
val licenseUrl: String by project
37+
38+
group = "com.onixbyte"
39+
version = artefactVersion
40+
41+
repositories {
42+
mavenCentral()
43+
}
44+
45+
java {
46+
sourceCompatibility = JavaVersion.VERSION_17
47+
targetCompatibility = JavaVersion.VERSION_17
48+
withSourcesJar()
49+
withJavadocJar()
50+
}
51+
52+
tasks.withType<JavaCompile> {
53+
options.encoding = "UTF-8"
54+
}
55+
56+
tasks.withType<Jar> {
57+
exclude("logback.xml")
58+
}
59+
60+
dependencies {
61+
compileOnly(libs.slf4j)
62+
implementation(libs.logback)
63+
testImplementation(platform(libs.junit.bom))
64+
testImplementation(libs.junit.jupiter)
65+
}
66+
67+
tasks.test {
68+
useJUnitPlatform()
69+
}
70+
71+
publishing {
72+
publications {
73+
create<MavenPublication>("tuple") {
74+
groupId = group.toString()
75+
artifactId = "tuple"
76+
version = artefactVersion
77+
78+
pom {
79+
name = "OnixByte Tuple"
80+
description =
81+
"The tuple module is designed to offer a convenient and efficient way to handle grouped data."
82+
url = projectUrl
83+
84+
licenses {
85+
license {
86+
name = licenseName
87+
url = licenseUrl
88+
}
89+
}
90+
91+
scm {
92+
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
93+
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
94+
url = projectGithubUrl
95+
}
96+
97+
developers {
98+
developer {
99+
id = "zihluwang"
100+
name = "Zihlu Wang"
101+
email = "really@zihlu.wang"
102+
timezone = "Asia/Hong_Kong"
103+
}
104+
105+
developer {
106+
id = "siujamo"
107+
name = "Siu Jam'o"
108+
email = "jamo.siu@outlook.com"
109+
timezone = "Asia/Shanghai"
110+
}
111+
}
112+
}
113+
114+
from(components["java"])
115+
116+
signing {
117+
sign(publishing.publications["tuple"])
118+
}
119+
}
120+
121+
repositories {
122+
maven {
123+
name = "sonatypeNexus"
124+
url = URI(providers.gradleProperty("repo.maven-central.host").get())
125+
credentials {
126+
username = providers.gradleProperty("repo.maven-central.username").get()
127+
password = providers.gradleProperty("repo.maven-central.password").get()
128+
}
129+
}
130+
}
131+
}
132+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2024-2025 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.tuple;
19+
20+
/**
21+
* Represents an immutable triple of three elements, referred to as 'left', 'middle', and 'right'.
22+
* This class provides a generic way to group three values without the need to create a custom class
23+
* for each specific combination.
24+
* <p>
25+
* The generic types {@code L}, {@code M}, and {@code R} denote the types of the left, middle, and
26+
* right elements, respectively. Instances of this class are immutable once created.
27+
*
28+
* @param <L> the type of the left element
29+
* @param <M> the type of the middle element
30+
* @param <R> the type of the right element
31+
* @param left the left element of this triple
32+
* @param middle the middle element of this triple
33+
* @param right the right element of this triple
34+
* @author siujamo
35+
* @author zihluwang
36+
*/
37+
public record ImmutableTriTuple<L, M, R>(
38+
L left,
39+
M middle,
40+
R right
41+
) {
42+
43+
/**
44+
* Creates a new {@code TriTuple} with the specified left, middle, and right elements.
45+
*
46+
* @param <L> the type of the left element
47+
* @param <M> the type of the middle element
48+
* @param <R> the type of the right element
49+
* @param left the left element
50+
* @param middle the middle element
51+
* @param right the right element
52+
* @return a new {@code TriTuple} containing the specified elements
53+
*/
54+
public static <L, M, R> ImmutableTriTuple<L, M, R> of(L left, M middle, R right) {
55+
return new ImmutableTriTuple<>(left, middle, right);
56+
}
57+
}

0 commit comments

Comments
 (0)