Class TupleUtil

java.lang.Object
cloud.opencode.base.core.tuple.TupleUtil

public final class TupleUtil extends Object
Tuple Factory Utility - Convenience methods for creating tuples 元组工厂工具类 - 提供创建元组的便捷方法

Provides factory methods for creating Pair, Triple, and Quadruple tuples.

提供创建 Pair、Triple 和 Quadruple 元组的工厂方法。

Features | 主要功能:

  • Create Pair with pair() method - 使用 pair() 创建二元组
  • Create Triple with triple() method - 使用 triple() 创建三元组
  • Create Quadruple with quadruple() method - 使用 quadruple() 创建四元组
  • Create empty tuples - 创建空元组

Usage Examples | 使用示例:

Pair<String, Integer> pair = TupleUtil.pair("name", 25);
Triple<String, Integer, Boolean> triple = TupleUtil.triple("name", 25, true);
Quadruple<String, Integer, Boolean, Double> quad =
    TupleUtil.quadruple("name", 25, true, 3.14);

Security | 安全性:

  • Thread-safe: Yes (stateless factory) - 线程安全: 是 (无状态工厂)
  • Null-safe: Allows null values - 空值安全: 允许 null 值

Performance | 性能特性:

  • Time complexity: O(1) per tuple creation - 每次元组创建 O(1)
  • Space complexity: O(1) per tuple - 每个元组 O(1)
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • pair

      public static <L,R> Pair<L,R> pair(L left, R right)
      Creates a Pair 创建二元组
      Type Parameters:
      L - left value type | 左值类型
      R - right value type | 右值类型
      Parameters:
      left - left value | 左值
      right - right value | 右值
      Returns:
      the Pair | 二元组
    • pair

      public static <K,V> Pair<K,V> pair(Map.Entry<K,V> entry)
      Creates a Pair from Map.Entry 从 Map.Entry 创建二元组
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      entry - Map.Entry
      Returns:
      the Pair | 二元组
    • emptyPair

      public static <L,R> Pair<L,R> emptyPair()
      Creates an empty Pair 创建空二元组
      Type Parameters:
      L - left value type | 左值类型
      R - right value type | 右值类型
      Returns:
      an empty Pair | 空二元组
    • triple

      public static <A,B,C> Triple<A,B,C> triple(A first, B second, C third)
      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 | 三元组
    • emptyTriple

      public static <A,B,C> Triple<A,B,C> emptyTriple()
      Creates an empty Triple 创建空三元组
      Type Parameters:
      A - first element type | 第一个元素类型
      B - second element type | 第二个元素类型
      C - third element type | 第三个元素类型
      Returns:
      an empty Triple | 空三元组
    • quadruple

      public static <A,B,C,D> Quadruple<A,B,C,D> quadruple(A first, B second, C third, D fourth)
      Creates a Quadruple 创建四元组
      Type Parameters:
      A - first element type | 第一个元素类型
      B - second element type | 第二个元素类型
      C - third element type | 第三个元素类型
      D - fourth element type | 第四个元素类型
      Parameters:
      first - the first element | 第一个元素
      second - the second element | 第二个元素
      third - the third element | 第三个元素
      fourth - the fourth element | 第四个元素
      Returns:
      the Quadruple | 四元组
    • emptyQuadruple

      public static <A,B,C,D> Quadruple<A,B,C,D> emptyQuadruple()
      Creates an empty Quadruple 创建空四元组
      Type Parameters:
      A - first element type | 第一个元素类型
      B - second element type | 第二个元素类型
      C - third element type | 第三个元素类型
      D - fourth element type | 第四个元素类型
      Returns:
      an empty Quadruple | 空四元组