Class OpenList

java.lang.Object
cloud.opencode.base.collections.OpenList

public final class OpenList extends Object
OpenList - List Facade Utility Class OpenList - 列表门面工具类

Provides comprehensive list operations including creation, transformation, filtering, and searching.

提供全面的列表操作,包括创建、转换、过滤和搜索。

Features | 主要功能:

  • Factory methods for list creation - 列表创建工厂方法
  • List transformation - 列表转换
  • List filtering - 列表过滤
  • List searching - 列表搜索
  • List partitioning - 列表分区

Usage Examples | 使用示例:

// Create list - 创建列表
List<String> list = OpenList.of("a", "b", "c");

// Reverse - 反转
List<String> reversed = OpenList.reverse(list);

// Partition - 分区
List<List<String>> partitions = OpenList.partition(list, 2);

// Transform - 转换
List<Integer> lengths = OpenList.transform(list, String::length);

Performance | 性能特性:

  • Most operations: O(n) - 大多数操作: O(n)
  • Random access: O(1) - 随机访问: O(1)

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • newArrayList

      public static <E> ArrayList<E> newArrayList()
      Create an empty ArrayList. 创建空的 ArrayList。
      Type Parameters:
      E - element type | 元素类型
      Returns:
      new empty ArrayList | 新的空 ArrayList
    • of

      @SafeVarargs public static <E> ArrayList<E> of(E... elements)
      Create an ArrayList with the given elements. 创建包含给定元素的 ArrayList。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      elements - the elements | 元素
      Returns:
      new ArrayList | 新的 ArrayList
    • from

      public static <E> ArrayList<E> from(Iterable<? extends E> elements)
      Create an ArrayList from an Iterable. 从 Iterable 创建 ArrayList。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      elements - the elements | 元素
      Returns:
      new ArrayList | 新的 ArrayList
    • withCapacity

      public static <E> ArrayList<E> withCapacity(int capacity)
      Create an ArrayList with initial capacity. 创建具有初始容量的 ArrayList。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      capacity - initial capacity | 初始容量
      Returns:
      new ArrayList | 新的 ArrayList
    • newLinkedList

      public static <E> LinkedList<E> newLinkedList()
      Create a LinkedList. 创建 LinkedList。
      Type Parameters:
      E - element type | 元素类型
      Returns:
      new LinkedList | 新的 LinkedList
    • linkedListFrom

      public static <E> LinkedList<E> linkedListFrom(Iterable<? extends E> elements)
      Create a LinkedList from an Iterable. 从 Iterable 创建 LinkedList。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      elements - the elements | 元素
      Returns:
      new LinkedList | 新的 LinkedList
    • reverse

      public static <E> List<E> reverse(List<E> list)
      Return a reversed view of the list. 返回列表的反转视图。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      Returns:
      reversed view | 反转视图
    • partition

      public static <E> List<List<E>> partition(List<E> list, int size)
      Return a partition view of the list. 返回列表的分区视图。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      size - partition size | 分区大小
      Returns:
      list of partitions | 分区列表
    • transform

      public static <F,T> List<T> transform(List<F> list, Function<? super F, ? extends T> function)
      Return a transformed view of the list. 返回列表的转换视图。
      Type Parameters:
      F - input element type | 输入元素类型
      T - output element type | 输出元素类型
      Parameters:
      list - the list | 列表
      function - the transform function | 转换函数
      Returns:
      transformed list | 转换后的列表
    • charactersOf

      public static List<Character> charactersOf(String string)
      Return a view of the string as a list of characters. 返回字符串作为字符列表的视图。
      Parameters:
      string - the string | 字符串
      Returns:
      list of characters | 字符列表
    • getFirst

      public static <E> E getFirst(List<E> list)
      Get the first element of the list. 获取列表的第一个元素。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      Returns:
      first element or null if empty | 第一个元素,空列表返回 null
    • getFirst

      public static <E> E getFirst(List<E> list, E defaultValue)
      Get the first element of the list with default value. 获取列表的第一个元素,带默认值。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      defaultValue - default value | 默认值
      Returns:
      first element or default | 第一个元素或默认值
    • getLast

      public static <E> E getLast(List<E> list)
      Get the last element of the list. 获取列表的最后一个元素。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      Returns:
      last element or null if empty | 最后一个元素,空列表返回 null
    • getLast

      public static <E> E getLast(List<E> list, E defaultValue)
      Get the last element of the list with default value. 获取列表的最后一个元素,带默认值。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      defaultValue - default value | 默认值
      Returns:
      last element or default | 最后一个元素或默认值
    • findFirst

      public static <E> Optional<E> findFirst(List<E> list, Predicate<? super E> predicate)
      Find the first element matching the predicate. 查找第一个匹配谓词的元素。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      predicate - the predicate | 谓词
      Returns:
      Optional containing the element or empty | 包含元素的 Optional 或空
    • filter

      public static <E> List<E> filter(List<E> list, Predicate<? super E> predicate)
      Find all elements matching the predicate. 查找所有匹配谓词的元素。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      list - the list | 列表
      predicate - the predicate | 谓词
      Returns:
      list of matching elements | 匹配元素的列表
    • cartesianProduct

      @SafeVarargs public static <E> List<List<E>> cartesianProduct(List<? extends E>... lists)
      Compute Cartesian product of lists. 计算列表的笛卡尔积。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      lists - the lists | 列表
      Returns:
      Cartesian product | 笛卡尔积
    • cartesianProduct

      public static <E> List<List<E>> cartesianProduct(List<? extends List<? extends E>> lists)
      Compute Cartesian product of lists. 计算列表的笛卡尔积。
      Type Parameters:
      E - element type | 元素类型
      Parameters:
      lists - the lists | 列表
      Returns:
      Cartesian product | 笛卡尔积