Record Class Partition<T>

java.lang.Object
java.lang.Record
com.sure.tool.collection.Partition<T>
Type Parameters:
T - 元素类型
Record Components:
matched - 匹配谓词的元素列表(可为空列表,不为 null)
unmatched - 不匹配谓词的元素列表(可为空列表,不为 null)

public record Partition<T>(List<T> matched, List<T> unmatched) extends Record
集合二分结果:按谓词将集合分为「匹配」与「不匹配」两部分,均保持输入顺序。 构造时对列表做防御性拷贝,访问器返回不可变视图,杜绝内部表示暴露。
Since:
1.15.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Partition(List<T> matched, List<T> unmatched)
    紧凑构造:参数为 null 时按空列表处理,非空时做防御性拷贝。
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    匹配元素列表的不可变视图。
    final String
    Returns a string representation of this record class.
    不匹配元素列表的不可变视图。

    Methods inherited from class Object

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

    • Partition

      public Partition(List<T> matched, List<T> unmatched)
      紧凑构造:参数为 null 时按空列表处理,非空时做防御性拷贝。
  • Method Details

    • matched

      public List<T> matched()
      匹配元素列表的不可变视图。
      Returns:
      不可变列表
    • unmatched

      public List<T> unmatched()
      不匹配元素列表的不可变视图。
      Returns:
      不可变列表
    • toString

      public final 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.