Record Class Triple<A,B,C>
java.lang.Object
java.lang.Record
cloud.opencode.base.collections.Triple<A,B,C>
- Type Parameters:
A- the type of the first element - 第一个元素的类型B- the type of the second element - 第二个元素的类型C- the type of the third element - 第三个元素的类型- Record Components:
first- the first element - 第一个元素second- the second element - 第二个元素third- the third element - 第三个元素
- All Implemented Interfaces:
Serializable
Triple - Immutable generic triple of three values
Triple - 不可变的泛型三元组
A simple container holding three related values. Provides functional
transformation methods and conversion to Pair.
一个持有三个相关值的简单容器。提供函数式变换方法以及到 Pair 的转换。
Features | 主要功能:
- Immutable record-based implementation - 基于 record 的不可变实现
- Functional transformations (mapFirst, mapSecond, mapThird) - 函数式变换
- Projection to Pair (dropFirst, dropSecond, dropThird) - 投影到 Pair
- Null-safe: allows null values - 空值安全:允许 null 值
Usage Examples | 使用示例:
// Create a triple - 创建三元组
Triple<String, Integer, Boolean> triple = Triple.of("name", 25, true);
// Map individual elements - 映射单个元素
Triple<String, String, Boolean> mapped = triple.mapSecond(String::valueOf);
// Drop to pair - 投影到二元组
Pair<String, Integer> pair = triple.dropThird(); // ("name", 25)
- Since:
- JDK 25, opencode-base-collections V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a Pair containing the second and third elements, dropping the first.Returns a Pair containing the first and third elements, dropping the second.Returns a Pair containing the first and second elements, dropping the third.final booleanIndicates whether some other object is "equal to" this one.first()Returns the value of thefirstrecord component.final inthashCode()Returns a hash code value for this object.Transforms the first element using the given function.Transforms the second element using the given function.Transforms the third element using the given function.static <A,B, C> Triple <A, B, C> of(A first, B second, C third) Creates a new Triple with the given values.second()Returns the value of thesecondrecord component.third()Returns the value of thethirdrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Triple
-
-
Method Details
-
of
Creates a new Triple with the given values. 使用给定的值创建新的三元组。- Type Parameters:
A- the type of the first element - 第一个元素的类型B- the type of the second element - 第二个元素的类型C- the type of the third element - 第三个元素的类型- Parameters:
first- the first element (nullable) - 第一个元素(可为 null)second- the second element (nullable) - 第二个元素(可为 null)third- the third element (nullable) - 第三个元素(可为 null)- Returns:
- a new Triple - 新的三元组
-
mapFirst
Transforms the first element using the given function. 使用给定函数变换第一个元素。- Type Parameters:
D- the type of the new first element - 新的第一个元素的类型- Parameters:
fn- the mapping function - 映射函数- Returns:
- a new Triple with the transformed first element - 变换了第一个元素的新三元组
- Throws:
NullPointerException- if fn is null - 如果 fn 为 null
-
mapSecond
Transforms the second element using the given function. 使用给定函数变换第二个元素。- Type Parameters:
D- the type of the new second element - 新的第二个元素的类型- Parameters:
fn- the mapping function - 映射函数- Returns:
- a new Triple with the transformed second element - 变换了第二个元素的新三元组
- Throws:
NullPointerException- if fn is null - 如果 fn 为 null
-
mapThird
Transforms the third element using the given function. 使用给定函数变换第三个元素。- Type Parameters:
D- the type of the new third element - 新的第三个元素的类型- Parameters:
fn- the mapping function - 映射函数- Returns:
- a new Triple with the transformed third element - 变换了第三个元素的新三元组
- Throws:
NullPointerException- if fn is null - 如果 fn 为 null
-
dropThird
-
dropFirst
-
dropSecond
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
first
-
second
-
third
-