net.dongliu.commons.lang.Maps Maven / Gradle / Ivy
package net.dongliu.commons.lang;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* utils method for map
*
* create map:
* Map<String, Integer> map = Maps.of(
* Pair.of("test", 1),
* Pair.of("test2", 2),
* Pair.of("test3", 3)
* );
*
*
* @author Dong Liu
*/
public class Maps {
/**
* get map, key-value
*
* @param pairs key-value list
*/
@SuppressWarnings("all")
public static Map of(Pair... pairs) {
Map map = new HashMap<>();
for (Pair pair : pairs) {
map.put(pair.getKey(), pair.getValue());
}
return map;
}
@SuppressWarnings("all")
public static Map immutableOf(Pair... pairs) {
return Collections.unmodifiableMap(of(pairs));
}
}