RequestModule.java 文件源码

java
阅读 38 收藏 0 点赞 0 评论 0

项目:nomulus 作者:
/**
 * Provides an immutable representation of the servlet request parameters.
 *
 * <p>This performs a shallow copy of the {@code Map<String, String[]>} data structure from the
 * servlets API, each time this is provided. This is almost certainly less expensive than the
 * thread synchronization expense of {@link javax.inject.Singleton @Singleton}.
 *
 * <p><b>Note:</b> If a parameter is specified without a value, e.g. {@code /foo?lol} then an
 * empty string value is assumed, since Guava's multimap doesn't permit {@code null} mappings.
 *
 * @see HttpServletRequest#getParameterMap()
 */
@Provides
@ParameterMap
static ImmutableListMultimap<String, String> provideParameterMap(HttpServletRequest req) {
  ImmutableListMultimap.Builder<String, String> params = new ImmutableListMultimap.Builder<>();
  @SuppressWarnings("unchecked")  // Safe by specification.
  Map<String, String[]> original = req.getParameterMap();
  for (Map.Entry<String, String[]> param : original.entrySet()) {
    if (param.getValue().length == 0) {
      params.put(param.getKey(), "");
    } else {
      params.putAll(param.getKey(), param.getValue());
    }
  }
  return params.build();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号