Skip to content

Commit f8bce22

Browse files
author
Zihlu Wang
authored
Merge pull request #81 from onixbyte/release/v3.1.0
2 parents 05e6982 + 8e10a31 commit f8bce22

File tree

9 files changed

+644
-3
lines changed

9 files changed

+644
-3
lines changed

common-toolbox/src/main/java/com/onixbyte/common/util/AesUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ public static String encrypt(String data, String secret) throws GeneralSecurityE
168168
/**
169169
* Decrypts the specified Base64-encoded string data using the AES algorithm with the provided secret key.
170170
*
171-
* @param data the Base64-encoded string data to be decrypted
172-
* @param secret the secret key used for decryption
171+
* @param data the Base64-encoded string data to be decrypted
172+
* @param secret the secret key used for decryption
173+
* @param ivParam the initialization vector parameter used for AES decryption
173174
* @return the decrypted string data
174175
* @throws GeneralSecurityException if any cryptographic error occurs during decryption
175176
*/

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# SOFTWARE.
2121
#
2222

23-
artefactVersion=3.0.0
23+
artefactVersion=3.1.0
2424
projectUrl=https://onixbyte.com/projects/onixbyte-toolbox
2525
projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox
2626
licenseName=MIT

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ include(
2424
"crypto-toolbox",
2525
"math-toolbox",
2626
)
27+
28+
include("tuple")

tuple/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Tuple
2+
3+
## Introduction
4+
5+
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.
6+
7+
## Features
8+
9+
- Immutable and mutable versions of bi-tuples (pairs) and tri-tuples (triplets);
10+
- Factory method of() for easy instantiation of all tuple types;
11+
- Simple, lightweight implementation compatible with standard Java usage;
12+
- Clear distinction between mutable and immutable tuples for flexibility.
13+
14+
## Installation
15+
16+
### Maven
17+
18+
Add the following dependency to your `pom.xml`:
19+
20+
```xml
21+
<dependency>
22+
<groupId>com.onixbyte</groupId>
23+
<artifactId>tuple</artifactId>
24+
<version>$artefactVersion</version>
25+
</dependency>
26+
```
27+
28+
### Gradle
29+
30+
#### Version Catalogue
31+
32+
Add the following codes to you `gradle/libs.versions.toml`:
33+
34+
```toml
35+
[version]
36+
onixbyteToolbox = "$artefactVersion"
37+
38+
[libraries]
39+
onixbyteToolbox-tuple = { group = "com.onixbyte", name = "tuple", version.ref = "onixbyteToolbox" }
40+
```
41+
42+
Then add the following codes to your `build.gradle.kts` or `build.gradle` dependencies block:
43+
44+
```kotlin
45+
implementation(libs.onixbyteToolbox.tuple)
46+
```
47+
48+
```groovy
49+
implementation libs.onixbyteToolbox.tuple
50+
```
51+
52+
#### Kotlin DSL
53+
54+
Add the following line to your `build.gradle.kts` dependencies block:
55+
56+
```kotlin
57+
implementation("com.onixbyte:tuple:$artefactVersion")
58+
```
59+
60+
#### Groovy DSL
61+
62+
Add the following line to your `build.gradle` dependencies block:
63+
64+
```groovy
65+
implementation 'com.onixbyte:tuple:${artefactVersion}'
66+
```
67+
68+
## Dependencies
69+
70+
This module has no external dependencies other than the standard Java SDK.
71+
72+
## Acknowledgement
73+
74+
Thanks to all contributors who helped develop this module, improving its design, performance, and documentation over time.

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+
102+
timezone = "Asia/Hong_Kong"
103+
}
104+
105+
developer {
106+
id = "siujamo"
107+
name = "Siu Jam'o"
108+
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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
import java.util.Objects;
21+
22+
/**
23+
* Represents an ordered pair of elements, where the first element is of type {@code L} and the
24+
* second is of type {@code R}. This class provides a simple way to group two related
25+
* values together.
26+
* <p>
27+
* The class is mutable, allowing the values of the left and right elements to be changed
28+
* after creation. It also overrides the {@code equals}, {@code hashCode}, and {@code toString}
29+
* methods to provide meaningful comparisons and string representations.
30+
*
31+
* @param <L> the type of the left element
32+
* @param <R> the type of the right element
33+
* @author siujamo
34+
* @author zihluwang
35+
*/
36+
public final class BiTuple<L, R> {
37+
38+
/**
39+
* The left element of the tuple.
40+
*/
41+
private L left;
42+
43+
/**
44+
* The right element of the tuple.
45+
*/
46+
private R right;
47+
48+
/**
49+
* Constructs a new {@code BiTuple} with the specified left and right elements.
50+
*
51+
* @param left the left element to be stored in the tuple
52+
* @param right the right element to be stored in the tuple
53+
*/
54+
public BiTuple(L left, R right) {
55+
this.left = left;
56+
this.right = right;
57+
}
58+
59+
/**
60+
* Retrieves the left element of the tuple.
61+
*
62+
* @return the left element of the tuple
63+
*/
64+
public L getLeft() {
65+
return left;
66+
}
67+
68+
/**
69+
* Sets the left element of the tuple to the specified value.
70+
*
71+
* @param left the new value for the left element of the tuple
72+
*/
73+
public void setLeft(L left) {
74+
this.left = left;
75+
}
76+
77+
/**
78+
* Retrieves the right element of the tuple.
79+
*
80+
* @return the right element of the tuple
81+
*/
82+
public R getRight() {
83+
return right;
84+
}
85+
86+
/**
87+
* Sets the right element of the tuple to the specified value.
88+
*
89+
* @param right the new value for the right element of the tuple
90+
*/
91+
public void setRight(R right) {
92+
this.right = right;
93+
}
94+
95+
/**
96+
* Compares this {@code BiTuple} with the specified object for equality.
97+
* <p>
98+
* Two {@code BiTuple}s are considered equal if they are of the same type and their left and
99+
* right elements are equal according to their respective {@code equals} methods.
100+
*
101+
* @param object the object to compare with this {@code BiTuple}
102+
* @return {@code true} if the specified object is equal to this {@code BiTuple},
103+
* {@code false} otherwise
104+
*/
105+
@Override
106+
public boolean equals(Object object) {
107+
if (!(object instanceof BiTuple<?, ?> biTuple)) return false;
108+
return Objects.equals(left, biTuple.left) && Objects.equals(right, biTuple.right);
109+
}
110+
111+
/**
112+
* Returns a hash code value for the {@code BiTuple}.
113+
* <p>
114+
* The hash code is calculated based on the hash codes of the left and right elements.
115+
*
116+
* @return a hash code value for this {@code BiTuple}
117+
*/
118+
@Override
119+
public int hashCode() {
120+
return Objects.hash(left, right);
121+
}
122+
123+
/**
124+
* Returns a string representation of the {@code BiTuple}.
125+
* <p>
126+
* The string representation consists of the class name, followed by the values of
127+
* the left and right elements in the format {@code "BiTuple{left=value1, right=value2}"}.
128+
*
129+
* @return a string representation of the {@code BiTuple}
130+
*/
131+
@Override
132+
public String toString() {
133+
return "BiTuple{" +
134+
"left=" + left +
135+
", right=" + right +
136+
'}';
137+
}
138+
139+
/**
140+
* Creates a new {@code BiTuple} with the specified left and right elements.
141+
*
142+
* @param <L> the type of the left element
143+
* @param <R> the type of the right element
144+
* @param left the left element
145+
* @param right the right element
146+
* @return a new {@code BiTuple} containing the specified elements
147+
*/
148+
public static <L, R> BiTuple<L, R> of(L left, R right) {
149+
return new BiTuple<>(left, right);
150+
}
151+
}

0 commit comments

Comments
 (0)