refactor: rename BiTuple to Tuple
This commit is contained in:
@@ -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.
|
|
||||||
* <p>
|
|
||||||
* 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 <L> the type of the left element
|
|
||||||
* @param <R> 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, R>(
|
|
||||||
L left,
|
|
||||||
R right
|
|
||||||
) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@code ImmutableBiTuple} with the specified left and right elements.
|
|
||||||
*
|
|
||||||
* @param <L> the type of the left element
|
|
||||||
* @param <R> 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 <L, R> ImmutableBiTuple<L, R> of(L left, R right) {
|
|
||||||
return new ImmutableBiTuple<>(left, right);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.
|
||||||
|
* <p>
|
||||||
|
* 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 <L> the type of the left element
|
||||||
|
* @param <R> 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, R>(
|
||||||
|
L left,
|
||||||
|
R right
|
||||||
|
) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@code ImmutableTuple} with the specified left and right elements.
|
||||||
|
*
|
||||||
|
* @param <L> the type of the left element
|
||||||
|
* @param <R> 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 <L, R> ImmutableTuple<L, R> of(L left, R right) {
|
||||||
|
return new ImmutableTuple<>(left, right);
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-19
@@ -33,7 +33,7 @@ import java.util.Objects;
|
|||||||
* @author siujamo
|
* @author siujamo
|
||||||
* @author zihluwang
|
* @author zihluwang
|
||||||
*/
|
*/
|
||||||
public final class BiTuple<L, R> {
|
public final class Tuple<L, R> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The left element of the tuple.
|
* The left element of the tuple.
|
||||||
@@ -46,12 +46,12 @@ public final class BiTuple<L, R> {
|
|||||||
private R right;
|
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 left the left element to be stored in the tuple
|
||||||
* @param right the right 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.left = left;
|
||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
@@ -93,27 +93,27 @@ public final class BiTuple<L, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares this {@code BiTuple} with the specified object for equality.
|
* Compares this {@code Tuple} with the specified object for equality.
|
||||||
* <p>
|
* <p>
|
||||||
* 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.
|
* right elements are equal according to their respective {@code equals} methods.
|
||||||
*
|
*
|
||||||
* @param object the object to compare with 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 BiTuple},
|
* @return {@code true} if the specified object is equal to this {@code Tuple},
|
||||||
* {@code false} otherwise
|
* {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (!(object instanceof BiTuple<?, ?> biTuple)) return false;
|
if (!(object instanceof Tuple<?, ?> tuple)) return false;
|
||||||
return Objects.equals(left, biTuple.left) && Objects.equals(right, biTuple.right);
|
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}.
|
||||||
* <p>
|
* <p>
|
||||||
* The hash code is calculated based on the hash codes of the left and right elements.
|
* 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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
@@ -121,31 +121,31 @@ public final class BiTuple<L, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string representation of the {@code BiTuple}.
|
* Returns a string representation of the {@code Tuple}.
|
||||||
* <p>
|
* <p>
|
||||||
* The string representation consists of the class name, followed by the values of
|
* 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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "BiTuple{" +
|
return "Tuple{" +
|
||||||
"left=" + left +
|
"left=" + left +
|
||||||
", right=" + right +
|
", 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 <L> the type of the left element
|
* @param <L> the type of the left element
|
||||||
* @param <R> the type of the right element
|
* @param <R> the type of the right element
|
||||||
* @param left the left element
|
* @param left the left element
|
||||||
* @param right the right 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 <L, R> BiTuple<L, R> of(L left, R right) {
|
public static <L, R> Tuple<L, R> of(L left, R right) {
|
||||||
return new BiTuple<>(left, right);
|
return new Tuple<>(left, right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user