Class Fluent

java.lang.Object
com.sure.tool.fluent.Fluent

public final class Fluent extends Object
Fluent API 统一工厂入口(Fluent API 全面化门面)。

按目标类型分发:字符串走 FluentString,集合走 FluentList, Map 走 FluentMap。命名采用无歧义策略:列表构建用 listOf(Object...) (避免与 of(String) / of(Collection) 的泛型重载冲突), 单键值 Map 用 mapOf(Object, Object)。

示例:

String s = Fluent.of(" abc ").trim().upperCase().get();            // "ABC"
List<Integer> l = Fluent.listOf(3, 1, 2).sorted().toList();        // [1, 2, 3]
Map<String, Integer> m = Fluent.mapOf("a", 1).put("b", 2).toMap(); // {a=1, b=2}
Since:
1.19.0
  • Method Details

    • string

      public static FluentString string(String value)
      创建字符串管道。
      Parameters:
      value - 初始字符串,不能为 null
      Returns:
      FluentString 实例
      Throws:
      NullPointerException - value 为 null
    • of

      public static FluentString of(String value)
      创建字符串管道(string(String) 别名)。

      示例:

      FluentString f = Fluent.of("hello");
      
      Parameters:
      value - 初始字符串,不能为 null
      Returns:
      FluentString 实例
      Throws:
      NullPointerException - value 为 null
    • list

      public static <E> FluentList<E> list()
      创建空列表管道。

      示例:

      FluentList<String> f = Fluent.list();
      
      Type Parameters:
      E - 元素类型
      Returns:
      空 FluentList 实例
    • listOf

      @SafeVarargs public static <E> FluentList<E> listOf(E... items)
      以若干元素创建列表管道。

      示例:

      FluentList<Integer> f = Fluent.listOf(3, 1, 2);
      
      Type Parameters:
      E - 元素类型
      Parameters:
      items - 初始元素,不能含 null
      Returns:
      FluentList 实例(内部不可变)
      Throws:
      IllegalArgumentException - 任一元素为 null
    • of

      public static <E> FluentList<E> of(Collection<? extends E> collection)
      从既有集合创建列表管道(防御拷贝)。

      示例:

      FluentList<String> f = Fluent.of(existingList);
      
      Type Parameters:
      E - 元素类型
      Parameters:
      collection - 源集合,不能为 null,不能含 null 元素
      Returns:
      FluentList 实例(内部不可变副本)
      Throws:
      NullPointerException - collection 为 null
      IllegalArgumentException - collection 含 null 元素
    • map

      public static <K,V> FluentMap<K,V> map()
      创建空 Map 管道。

      示例:

      FluentMap<String, Integer> m = Fluent.map();
      
      Type Parameters:
      K - 键类型
      V - 值类型
      Returns:
      空 FluentMap 实例
    • mapOf

      public static <K,V> FluentMap<K,V> mapOf(K key, V value)
      创建含单个键值对的 Map 管道。

      示例:

      FluentMap<String, Integer> m = Fluent.mapOf("a", 1);
      
      Type Parameters:
      K - 键类型
      V - 值类型
      Parameters:
      key - 键,不能为 null
      value - 值,不能为 null
      Returns:
      FluentMap 实例
      Throws:
      IllegalArgumentException - key 或 value 为 null