public class MapUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_KEY_AND_VALUE_PAIR_SEPARATOR
default separator between key-value pairs
|
static java.lang.String |
DEFAULT_KEY_AND_VALUE_SEPARATOR
default separator between key and value
|
Constructor and Description |
---|
MapUtils() |
Modifier and Type | Method and Description |
---|---|
static <K,V> K |
getKeyByValue(java.util.Map<K,V> map,
V value)
get key by value, match the first entry front to back
Attentions:
for HashMap, the order of entry not same to put order, so you may need to use TreeMap
|
static <K,V> boolean |
isEmpty(java.util.Map<K,V> sourceMap)
is null or its size is 0
isEmpty(null) = true;
isEmpty({}) = true;
isEmpty({1, 2}) = false;
|
static java.util.Map<java.lang.String,java.lang.String> |
parseKeyAndValueToMap(java.lang.String source)
parse key-value pairs to map, ignore empty key, ignore space at the begging or end of key and value
|
static java.util.Map<java.lang.String,java.lang.String> |
parseKeyAndValueToMap(java.lang.String source,
boolean ignoreSpace)
parse key-value pairs to map, ignore empty key
|
static java.util.Map<java.lang.String,java.lang.String> |
parseKeyAndValueToMap(java.lang.String source,
java.lang.String keyAndValueSeparator,
java.lang.String keyAndValuePairSeparator,
boolean ignoreSpace)
parse key-value pairs to map, ignore empty key
parseKeyAndValueToMap("","","",true)=null
parseKeyAndValueToMap(null,"","",true)=null
parseKeyAndValueToMap("a:b,:","","",true)={(a,b)}
parseKeyAndValueToMap("a:b,:d","","",true)={(a,b)}
parseKeyAndValueToMap("a:b,c:d","","",true)={(a,b),(c,d)}
parseKeyAndValueToMap("a=b, c = d","=",",",true)={(a,b),(c,d)}
parseKeyAndValueToMap("a=b, c = d","=",",",false)={(a, b),( c , d)}
parseKeyAndValueToMap("a=b, c=d","=", ",", false)={(a,b),( c,d)}
parseKeyAndValueToMap("a=b; c=d","=", ";", false)={(a,b),( c,d)}
parseKeyAndValueToMap("a=b, c=d", ",", ";", false)={(a=b, c=d)}
|
static boolean |
putMapNotEmptyKey(java.util.Map<java.lang.String,java.lang.String> map,
java.lang.String key,
java.lang.String value)
add key-value pair to map, and key need not null or empty
|
static boolean |
putMapNotEmptyKeyAndValue(java.util.Map<java.lang.String,java.lang.String> map,
java.lang.String key,
java.lang.String value)
add key-value pair to map, both key and value need not null or empty
|
static boolean |
putMapNotEmptyKeyAndValue(java.util.Map<java.lang.String,java.lang.String> map,
java.lang.String key,
java.lang.String value,
java.lang.String defaultValue)
add key-value pair to map, key need not null or empty
|
static <K,V> boolean |
putMapNotNullKey(java.util.Map<K,V> map,
K key,
V value)
add key-value pair to map, key need not null
|
static <K,V> boolean |
putMapNotNullKeyAndValue(java.util.Map<K,V> map,
K key,
V value)
add key-value pair to map, both key and value need not null
|
static java.lang.String |
toJson(java.util.Map<java.lang.String,java.lang.String> map)
join map
|
public static final java.lang.String DEFAULT_KEY_AND_VALUE_SEPARATOR
public static final java.lang.String DEFAULT_KEY_AND_VALUE_PAIR_SEPARATOR
public static <K,V> boolean isEmpty(java.util.Map<K,V> sourceMap)
isEmpty(null) = true; isEmpty({}) = true; isEmpty({1, 2}) = false;
sourceMap
- public static boolean putMapNotEmptyKey(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String key, java.lang.String value)
map
- key
- value
- Map.put(Object, Object)
public static boolean putMapNotEmptyKeyAndValue(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String key, java.lang.String value)
map
- key
- value
- Map.put(Object, Object)
public static boolean putMapNotEmptyKeyAndValue(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String key, java.lang.String value, java.lang.String defaultValue)
map
- key
- value
- defaultValue
- public static <K,V> boolean putMapNotNullKey(java.util.Map<K,V> map, K key, V value)
map
- key
- value
- Map.put(Object, Object)
public static <K,V> boolean putMapNotNullKeyAndValue(java.util.Map<K,V> map, K key, V value)
map
- key
- value
- Map.put(Object, Object)
public static <K,V> K getKeyByValue(java.util.Map<K,V> map, V value)
V
- map
- value
- public static java.util.Map<java.lang.String,java.lang.String> parseKeyAndValueToMap(java.lang.String source, java.lang.String keyAndValueSeparator, java.lang.String keyAndValuePairSeparator, boolean ignoreSpace)
parseKeyAndValueToMap("","","",true)=null parseKeyAndValueToMap(null,"","",true)=null parseKeyAndValueToMap("a:b,:","","",true)={(a,b)} parseKeyAndValueToMap("a:b,:d","","",true)={(a,b)} parseKeyAndValueToMap("a:b,c:d","","",true)={(a,b),(c,d)} parseKeyAndValueToMap("a=b, c = d","=",",",true)={(a,b),(c,d)} parseKeyAndValueToMap("a=b, c = d","=",",",false)={(a, b),( c , d)} parseKeyAndValueToMap("a=b, c=d","=", ",", false)={(a,b),( c,d)} parseKeyAndValueToMap("a=b; c=d","=", ";", false)={(a,b),( c,d)} parseKeyAndValueToMap("a=b, c=d", ",", ";", false)={(a=b, c=d)}
source
- key-value pairskeyAndValueSeparator
- separator between key and valuekeyAndValuePairSeparator
- separator between key-value pairsignoreSpace
- whether ignore space at the begging or end of key and valuepublic static java.util.Map<java.lang.String,java.lang.String> parseKeyAndValueToMap(java.lang.String source, boolean ignoreSpace)
source
- key-value pairsignoreSpace
- whether ignore space at the begging or end of key and valueMapUtils#parseKeyAndValueToMap(String, String, String, boolean)}, keyAndValueSeparator is
{@link #DEFAULT_KEY_AND_VALUE_SEPARATOR}, keyAndValuePairSeparator is
{@link #DEFAULT_KEY_AND_VALUE_PAIR_SEPARATOR}
public static java.util.Map<java.lang.String,java.lang.String> parseKeyAndValueToMap(java.lang.String source)
source
- key-value pairsMapUtils#parseKeyAndValueToMap(String, String, String, boolean)}, keyAndValueSeparator is
{@link #DEFAULT_KEY_AND_VALUE_SEPARATOR}, keyAndValuePairSeparator is
{@link #DEFAULT_KEY_AND_VALUE_PAIR_SEPARATOR}, ignoreSpace is true
public static java.lang.String toJson(java.util.Map<java.lang.String,java.lang.String> map)
map
-