Record Class Triple<A,B,C>
java.lang.Object
java.lang.Record
cloud.opencode.base.core.tuple.Triple<A,B,C>
- Type Parameters:
A- first element type - 第一个元素类型B- second element type - 第二个元素类型C- third element type - 第三个元素类型- Record Components:
first- first element - 第一个元素second- second element - 第二个元素third- third element - 第三个元素
- All Implemented Interfaces:
Serializable
Triple - Immutable three-element tuple (Record implementation)
三元组 - 不可变的三元素元组(Record 实现)
Immutable container for three related values.
不可变的三值容器,可用于返回三个相关值。
Features | 主要功能:
- Immutable storage for three values - 不可变的三值存储
- Multiple aliases (first/second/third, left/middle/right) - 多种别名访问
- Element mapping and transformation - 元素映射和转换
- Extract to Pair (first two or last two) - 提取为 Pair
Usage Examples | 使用示例:
Triple<String, Integer, Boolean> triple = Triple.of("name", 25, true);
String first = triple.first();
Triple<String, String, Boolean> mapped = triple.mapSecond(String::valueOf);
Pair<String, Integer> pair = triple.toFirstPair();
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是 (不可变 Record)
- Null-safe: Allows null values - 空值安全: 允许 null 值
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if all values are non-null 检查是否都非 null<R> Rapply(TriFunction<? super A, ? super B, ? super C, ? extends R> function) Applies a tri-function 应用三元函数static <A,B, C> Triple <A, B, C> empty()Creates an empty Triple 创建空三元组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.booleanhasNull()Checks if it contains a null value 检查是否包含 null 值left()Gets the left value (alias for first) 获取左值(第一个元素的别名)<T,U, V> Triple <T, U, V> map(Function<? super A, ? extends T> firstMapper, Function<? super B, ? extends U> secondMapper, Function<? super C, ? extends V> thirdMapper) Maps all elements simultaneously 同时映射所有元素Maps the first element 映射第一个元素Maps the second element 映射第二个元素Maps the third element 映射第三个元素middle()Gets the middle value (alias for second) 获取中值(第二个元素的别名)static <A,B, C> Triple <A, B, C> of(A first, B second, C third) Creates a Triple 创建三元组right()Gets the right value (alias for third) 获取右值(第三个元素的别名)second()Returns the value of thesecondrecord component.third()Returns the value of thethirdrecord component.Object[]toArray()Converts to an array 转换为数组Extracts the first two elements as a Pair 提取前两个元素为 PairExtracts the last two elements as a Pair 提取后两个元素为 PairtoString()Returns a string representation of this record class.
-
Constructor Details
-
Triple
-
-
Method Details
-
of
Creates a Triple 创建三元组- Type Parameters:
A- first element type | 第一个元素类型B- second element type | 第二个元素类型C- third element type | 第三个元素类型- Parameters:
first- the first element | 第一个元素second- the second element | 第二个元素third- the third element | 第三个元素- Returns:
- the Triple | 三元组
-
empty
Creates an empty Triple 创建空三元组- Type Parameters:
A- first element type | 第一个元素类型B- second element type | 第二个元素类型C- third element type | 第三个元素类型- Returns:
- an empty Triple | 空三元组
-
left
Gets the left value (alias for first) 获取左值(第一个元素的别名)- Returns:
- the first element | 第一个元素
-
middle
Gets the middle value (alias for second) 获取中值(第二个元素的别名)- Returns:
- the second element | 第二个元素
-
right
Gets the right value (alias for third) 获取右值(第三个元素的别名)- Returns:
- the third element | 第三个元素
-
mapFirst
-
mapSecond
-
mapThird
-
map
public <T,U, Triple<T,V> U, mapV> (Function<? super A, ? extends T> firstMapper, Function<? super B, ? extends U> secondMapper, Function<? super C, ? extends V> thirdMapper) Maps all elements simultaneously 同时映射所有元素- Type Parameters:
T- new first element type | 新第一个元素类型U- new second element type | 新第二个元素类型V- new third element type | 新第三个元素类型- Parameters:
firstMapper- first element mapper function | 第一个元素映射函数secondMapper- second element mapper function | 第二个元素映射函数thirdMapper- third element mapper function | 第三个元素映射函数- Returns:
- a new Triple | 新三元组
-
apply
Applies a tri-function 应用三元函数- Type Parameters:
R- result type | 结果类型- Parameters:
function- the tri-function | 三元函数- Returns:
- the function result | 函数结果
-
toFirstPair
-
toLastPair
-
hasNull
public boolean hasNull()Checks if it contains a null value 检查是否包含 null 值- Returns:
- true if any value is null | 如果任一值为 null 返回 true
-
allNonNull
public boolean allNonNull()Checks if all values are non-null 检查是否都非 null- Returns:
- true if all values are non-null | 如果都非 null 返回 true
-
toArray
Converts to an array 转换为数组- Returns:
- an array containing three elements | 包含三个元素的数组
-
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
-