public class MapBuilder {
/**
* Creates an instance of {@code HashMap}
*/
public static <K, V> HashMap<K, V> newHashMap() {
return new HashMap<>();
} /**
* Returns the empty map.
*/
public static <K, V> Map<K, V> of() {
return newHashMap();
} /**
* Returns map containing a single entry.
*/
public static <K, V> Map<K, V> of(K k1, V v1) {
Map<K, V> map = of();
map.put(k1, v1);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2) {
Map<K, V> map = of();
map.put(k1, v1);
map.put(k2, v2);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
Map<K, V> map = of();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
Map<K, V> map = of();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
map.put(k4, v4);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
Map<K, V> map = of();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
map.put(k4, v4);
map.put(k5, v5);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Map<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) {
Map<K, V> map = of();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
map.put(k4, v4);
map.put(k5, v5);
map.put(k6, v6);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Map<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) {
Map<K, V> map = of();
map.put(k1, v1);
map.put(k2, v2);
map.put(k3, v3);
map.put(k4, v4);
map.put(k5, v5);
map.put(k6, v6);
map.put(k7, v7);
return map;
} /**
* Returns map containing the given entries.
*/
public static <K, V> Builder<K, V> builder() {
return new Builder<>();
} public static final class Builder<K, V> { private Map<K, V> map;
private boolean underConstruction; private Builder() {
map = newHashMap();
underConstruction = true;
} public Builder<K, V> put(K k, V v) {
if (!underConstruction) {
throw new IllegalStateException("Underlying map has already been built");
}
map.put(k, v);
return this;
} public Map<K, V> build() {
if (!underConstruction) {
throw new IllegalStateException("Underlying map has already been built");
}
underConstruction = false;
return map;
}
} }

MapBuilder,操作集合工具类的更多相关文章

  1. Redis操作Set工具类封装,Java Redis Set命令封装

    Redis操作Set工具类封装,Java Redis Set命令封装 >>>>>>>>>>>>>>>>& ...

  2. Java—集合工具类

    集合中的元素工具类排序: Java提供了一个操作Set.List和Map等集合的工具类:Collections,该工具类提供了大量方法对集合进行排序.查询和修改等操作,还提供了将集合对象置为不可变.对 ...

  3. Java从零开始学二十四(集合工具类Collections)

    一.Collections简介 在集合的应用开发中,集合的若干接口和若干个子类是最最常使用的,但是在JDK中提供了一种集合操作的工具类 —— Collections,可以直接通过此类方便的操作集合 二 ...

  4. Collections 集合工具类

    集合工具类  包括很多静态方法来操作集合list 而Collections则是集合类的一个工具类/帮助类,其中提供了一系列静态方法,用于对集合中元素进行排序.搜索以及线程安全等各种操作. 1) 排序( ...

  5. Java操作Redis工具类

    依赖 jar 包 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis< ...

  6. 集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils探究(转)

    之前一直以为集合工具类只有CollectionUtils,主要用它的isEmpty(final Collection<?> coll)静态方法来判断一个给定的集合是否为null或者是否长度 ...

  7. java之集合工具类Collections

    Collections类简介 java.utils.Collections 是集合工具类,用来对集合进行操作.此类完全由在 collection 上进行操作或返回 collection 的静态方法组成 ...

  8. [Google Guava] 2.3-强大的集合工具类:java.util.Collections中未包含的集合工具

    原文链接 译文链接 译者:沈义扬,校对:丁一 尚未完成: Queues, Tables工具类 任何对JDK集合框架有经验的程序员都熟悉和喜欢java.util.Collections包含的工具方法.G ...

  9. Collections集合工具类常用的方法

    java.utils.Collections //是集合工具类,用来对集合进行操作.部分方法如下: public static <T> boolean addAll(Collection& ...

随机推荐

  1. POJ 1047 Round and Round We Go

    https://vjudge.net/problem/POJ-1047 题意: 给一个整数,它的长度为n,从1开始一直到n和该整数相乘,判断每次结果是否和原来的整数是循环的. 思路: 大整数的乘法. ...

  2. UVa 12549 机器人警卫(最小点覆盖)

    https://vjudge.net/problem/UVA-12549 题意: 在一个Y行X列的网格里有空地(.),重要位置(*)和障碍物(#),用最少的机器人看守所有重要位置,每个机器人要放在一个 ...

  3. 怎样绕开QQ通讯录和360的广播中断

    http://www.eoeandroid.com/thread-148381-1-1.html 最近在网上搜索怎样绕开QQ通讯录和360的广播中断,在它们之前拿到短信,结果很遗憾没有搜索到什么东西, ...

  4. BZOJ 2806 【CTSC2012】 Cheat

    题目链接:Cheat 话说这道题很久以前某人就给我们考过,直到现在,我终于把这个坑填上了…… 这道题要我们把一个串\(S\)划分成若干块,每块长度不小于\(L_0\),使得能够在文章库中完全匹配的块的 ...

  5. python 浮点数转分数

    from fractions import Fraction value = 4.2 print(Fraction(value).limit_denominator())

  6. erlang 一个高性能web框架 Cowboy 的使用笔记

    环境:ubuntu_server 1210 目的:构建web版hello world程序 参考链接:http://roberto-aloi.com/blog/2013/07/13/create-dep ...

  7. Curious Array CodeForces - 407C (高阶差分)

    高阶差分板子题 const int N = 1e5+111; int a[N], n, m, k; int C[N][111], d[N][111]; signed main() { scanf(&q ...

  8. poj3436网络流之最大流拆点

    这题看了半天看不懂题意...还是看的网上题意写的 加一个源点一个汇点,把每个点拆成两个,这两个点的流量是v,其他联通的边都设为无穷大 输入没有1的点就与源点连接,输出只有1的点就与汇点连接 还有这个输 ...

  9. 浅析使用vue-router实现前端路由的两种方式

    关于vue-router 由于最近的项目中一直在使用vue,所以前端路由方案也是使用的官方路由vue-router,之前在angularJS项目中也是用过UI-router,感觉大同小异,不过很显然v ...

  10. Reverse engineer powerdesigner link odbc

    Reverse engineer powerdesigner link odbc           Option Explicit ValidationMode = True Interactive ...