Class ArgMap<K,V>

java.lang.Object
com.imyeyu.network.ArgMap<K,V>

public class ArgMap<K,V> extends Object
请求参数列表。

该实现允许同名 key 重复出现,适用于 query 参数和表单参数场景。

Since:
2025-06-26 15:41
Author:
夜雨
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    清空全部参数。
    返回只读参数视图。
    void
    forEach(BiConsumer<? super K,? super V> consumer)
    按插入顺序遍历全部参数。
    boolean
    判断参数列表是否为空。
    static <K, V> ArgMap<K,V>
    of(K key, V value)
    使用一组参数创建对象。
    static <K, V> ArgMap<K,V>
    of(K key1, V value1, K key2, V value2)
    使用两组参数创建对象。
    static <K, V> ArgMap<K,V>
    of(K key1, V value1, K key2, V value2, K key3, V value3)
    使用三组参数创建对象。
    put(K key, V value)
    追加一个参数。
    int
    返回参数数量。
    org.apache.hc.core5.http.HttpEntity
    转换为 multipart 实体。
    List<org.apache.hc.core5.http.NameValuePair>
    转换为表单参数列表。
    转换为 query string。
    将参数拼接到指定 URL。

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArgMap

      public ArgMap()
  • Method Details

    • put

      public ArgMap<K,V> put(K key, V value)
      追加一个参数。
      Parameters:
      key - 参数名
      value - 参数值
      Returns:
      当前对象
    • forEach

      public void forEach(BiConsumer<? super K,? super V> consumer)
      按插入顺序遍历全部参数。
      Parameters:
      consumer - 处理逻辑
    • size

      public int size()
      返回参数数量。
      Returns:
      参数数量
    • isEmpty

      public boolean isEmpty()
      判断参数列表是否为空。
      Returns:
      是否为空
    • clear

      public void clear()
      清空全部参数。
    • entries

      public List<Map.Entry<K,V>> entries()
      返回只读参数视图。
      Returns:
      参数条目列表
    • toEntity

      public org.apache.hc.core5.http.HttpEntity toEntity()
      转换为 multipart 实体。
      Returns:
      multipart 请求体
    • toNameValuePair

      public List<org.apache.hc.core5.http.NameValuePair> toNameValuePair()
      转换为表单参数列表。
      Returns:
      表单参数列表
    • toURL

      public String toURL()
      转换为 query string。
      Returns:
      query string
    • toURL

      public String toURL(String url)
      将参数拼接到指定 URL。
      Parameters:
      url - 原始 URL
      Returns:
      拼接后的 URL
    • of

      public static <K, V> ArgMap<K,V> of(K key, V value)
      使用一组参数创建对象。
      Type Parameters:
      K - key 类型
      V - value 类型
      Parameters:
      key - 参数名
      value - 参数值
      Returns:
      参数对象
    • of

      public static <K, V> ArgMap<K,V> of(K key1, V value1, K key2, V value2)
      使用两组参数创建对象。
      Type Parameters:
      K - key 类型
      V - value 类型
      Parameters:
      key1 - 参数名 1
      value1 - 参数值 1
      key2 - 参数名 2
      value2 - 参数值 2
      Returns:
      参数对象
    • of

      public static <K, V> ArgMap<K,V> of(K key1, V value1, K key2, V value2, K key3, V value3)
      使用三组参数创建对象。
      Type Parameters:
      K - key 类型
      V - value 类型
      Parameters:
      key1 - 参数名 1
      value1 - 参数值 1
      key2 - 参数名 2
      value2 - 参数值 2
      key3 - 参数名 3
      value3 - 参数值 3
      Returns:
      参数对象