Class MultimapBuilder

java.lang.Object
cloud.opencode.base.collections.specialized.MultimapBuilder

public final class MultimapBuilder extends Object
MultimapBuilder - Fluent Multimap Builder MultimapBuilder - 流式多值映射构建器

A fluent builder for creating multimaps with configurable key and value collection types.

用于创建具有可配置键和值集合类型的多值映射的流式构建器。

Features | 主要功能:

  • Fluent API - 流式API
  • Key ordering options - 键排序选项
  • Value collection options - 值集合选项
  • Thread-safe options - 线程安全选项

Usage Examples | 使用示例:

// Hash keys with array list values - 哈希键与数组列表值
ListMultimap<String, Integer> listMultimap = MultimapBuilder
    .hashKeys()
    .arrayListValues()
    .build();

// Linked hash keys with linked hash set values - 链式哈希键与链式哈希集合值
SetMultimap<String, Integer> setMultimap = MultimapBuilder
    .linkedHashKeys()
    .linkedHashSetValues()
    .build();

// Tree keys with tree set values - 树形键与树形集合值
SetMultimap<String, Integer> sortedMultimap = MultimapBuilder
    .treeKeys()
    .treeSetValues()
    .build();

Performance | 性能特性:

  • Time complexity: build() O(1); put() O(1) amortized for hash keys, O(log k) for tree keys - 时间复杂度: build() O(1);hash键put() O(1) 均摊,tree键 O(log k)
  • Space complexity: O(k) where k is the number of distinct keys - 空间复杂度: O(k),k为不同键的数量
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • hashKeys

      public static MultimapBuilder.KeyBuilder hashKeys()
      Use hash map for keys. 使用哈希映射存储键。
      Returns:
      key builder | 键构建器
    • hashKeys

      public static MultimapBuilder.KeyBuilder hashKeys(int expectedKeys)
      Use hash map for keys with expected size. 使用指定预期大小的哈希映射存储键。
      Parameters:
      expectedKeys - expected number of keys | 预期键数量
      Returns:
      key builder | 键构建器
    • linkedHashKeys

      public static MultimapBuilder.KeyBuilder linkedHashKeys()
      Use linked hash map for keys. 使用链式哈希映射存储键。
      Returns:
      key builder | 键构建器
    • linkedHashKeys

      public static MultimapBuilder.KeyBuilder linkedHashKeys(int expectedKeys)
      Use linked hash map for keys with expected size. 使用指定预期大小的链式哈希映射存储键。
      Parameters:
      expectedKeys - expected number of keys | 预期键数量
      Returns:
      key builder | 键构建器
    • treeKeys

      public static MultimapBuilder.KeyBuilder treeKeys()
      Use tree map for keys (natural ordering). 使用树形映射存储键(自然排序)。
      Returns:
      key builder | 键构建器
    • treeKeys

      public static <K> MultimapBuilder.KeyBuilder treeKeys(Comparator<? super K> comparator)
      Use tree map for keys with custom comparator. 使用自定义比较器的树形映射存储键。
      Type Parameters:
      K - key type | 键类型
      Parameters:
      comparator - the comparator | 比较器
      Returns:
      key builder | 键构建器