Record Class Quadruple<A,B,C,D>

java.lang.Object
java.lang.Record
cloud.opencode.base.core.tuple.Quadruple<A,B,C,D>
Type Parameters:
A - first element type - 第一个元素类型
B - second element type - 第二个元素类型
C - third element type - 第三个元素类型
D - fourth element type - 第四个元素类型
Record Components:
first - first element - 第一个元素
second - second element - 第二个元素
third - third element - 第三个元素
fourth - fourth element - 第四个元素
All Implemented Interfaces:
Serializable

public record Quadruple<A,B,C,D>(A first, B second, C third, D fourth) extends Record implements Serializable
Quadruple - Immutable four-element tuple (Record implementation) 四元组 - 不可变的四元素元组(Record 实现)

Immutable container for four related values.

不可变的四值容器,可用于返回四个相关值。

Features | 主要功能:

  • Immutable storage for four values - 不可变的四值存储
  • Element mapping and transformation - 元素映射和转换
  • Extract to Pair or Triple - 提取为 Pair 或 Triple
  • Null checks (hasNull, allNonNull) - 空值检查

Usage Examples | 使用示例:

Quadruple<String, Integer, Boolean, Double> quad =
    Quadruple.of("name", 25, true, 3.14);
String first = quad.first();
Triple<String, Integer, Boolean> triple = quad.toFirstTriple();

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
    Constructor
    Description
    Quadruple(A first, B second, C third, D fourth)
    Creates an instance of a Quadruple record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if all values are non-null 检查是否都非 null
    <R> R
    apply(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function)
    Applies a quad-function 应用四元函数
    static <A,B,C,D> Quadruple<A,B,C,D>
    Creates an empty Quadruple 创建空四元组
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the first record component.
    Returns the value of the fourth record component.
    final int
    Returns a hash code value for this object.
    boolean
    Checks if it contains a null value 检查是否包含 null 值
    <T> Quadruple<T,B,C,D>
    mapFirst(Function<? super A, ? extends T> mapper)
    Maps the first element 映射第一个元素
    <T> Quadruple<A,B,C,T>
    mapFourth(Function<? super D, ? extends T> mapper)
    Maps the fourth element 映射第四个元素
    <T> Quadruple<A,T,C,D>
    mapSecond(Function<? super B, ? extends T> mapper)
    Maps the second element 映射第二个元素
    <T> Quadruple<A,B,T,D>
    mapThird(Function<? super C, ? extends T> mapper)
    Maps the third element 映射第三个元素
    static <A,B,C,D> Quadruple<A,B,C,D>
    of(A first, B second, C third, D fourth)
    Creates a Quadruple 创建四元组
    Returns the value of the second record component.
    Returns the value of the third record component.
    Converts to an array 转换为数组
    Extracts the first two elements as a Pair 提取前两个元素为 Pair
    Extracts the first three elements as a Triple 提取前三个元素为 Triple
    Extracts the last two elements as a Pair 提取后两个元素为 Pair
    Extracts the last three elements as a Triple 提取后三个元素为 Triple
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Quadruple

      public Quadruple(A first, B second, C third, D fourth)
      Creates an instance of a Quadruple record class.
      Parameters:
      first - the value for the first record component
      second - the value for the second record component
      third - the value for the third record component
      fourth - the value for the fourth record component
  • Method Details

    • of

      public static <A,B,C,D> Quadruple<A,B,C,D> of(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 | 四元组
    • empty

      public static <A,B,C,D> Quadruple<A,B,C,D> empty()
      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 | 空四元组
    • mapFirst

      public <T> Quadruple<T,B,C,D> mapFirst(Function<? super A, ? extends T> mapper)
      Maps the first element 映射第一个元素
      Type Parameters:
      T - new type | 新类型
      Parameters:
      mapper - the mapper function | 映射函数
      Returns:
      a new Quadruple | 新四元组
    • mapSecond

      public <T> Quadruple<A,T,C,D> mapSecond(Function<? super B, ? extends T> mapper)
      Maps the second element 映射第二个元素
      Type Parameters:
      T - new type | 新类型
      Parameters:
      mapper - the mapper function | 映射函数
      Returns:
      a new Quadruple | 新四元组
    • mapThird

      public <T> Quadruple<A,B,T,D> mapThird(Function<? super C, ? extends T> mapper)
      Maps the third element 映射第三个元素
      Type Parameters:
      T - new type | 新类型
      Parameters:
      mapper - the mapper function | 映射函数
      Returns:
      a new Quadruple | 新四元组
    • mapFourth

      public <T> Quadruple<A,B,C,T> mapFourth(Function<? super D, ? extends T> mapper)
      Maps the fourth element 映射第四个元素
      Type Parameters:
      T - new type | 新类型
      Parameters:
      mapper - the mapper function | 映射函数
      Returns:
      a new Quadruple | 新四元组
    • apply

      public <R> R apply(QuadFunction<? super A, ? super B, ? super C, ? super D, ? extends R> function)
      Applies a quad-function 应用四元函数
      Type Parameters:
      R - result type | 结果类型
      Parameters:
      function - the quad-function | 四元函数
      Returns:
      the function result | 函数结果
    • toFirstPair

      public Pair<A,B> toFirstPair()
      Extracts the first two elements as a Pair 提取前两个元素为 Pair
      Returns:
      Pair
    • toLastPair

      public Pair<C,D> toLastPair()
      Extracts the last two elements as a Pair 提取后两个元素为 Pair
      Returns:
      Pair
    • toFirstTriple

      public Triple<A,B,C> toFirstTriple()
      Extracts the first three elements as a Triple 提取前三个元素为 Triple
      Returns:
      Triple
    • toLastTriple

      public Triple<B,C,D> toLastTriple()
      Extracts the last three elements as a Triple 提取后三个元素为 Triple
      Returns:
      Triple
    • 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

      public Object[] toArray()
      Converts to an array 转换为数组
      Returns:
      an array containing four elements | 包含四个元素的数组
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • first

      public A first()
      Returns the value of the first record component.
      Returns:
      the value of the first record component
    • second

      public B second()
      Returns the value of the second record component.
      Returns:
      the value of the second record component
    • third

      public C third()
      Returns the value of the third record component.
      Returns:
      the value of the third record component
    • fourth

      public D fourth()
      Returns the value of the fourth record component.
      Returns:
      the value of the fourth record component