public class Maps
extends java.lang.Object
Constructor and Description |
---|
Maps() |
Modifier and Type | Method and Description |
---|---|
static java.util.Map |
clone(java.util.Map m)
Create a clone.
|
static java.lang.Object |
getKeyFromValue(java.util.Map map,
java.lang.Object value) |
static java.lang.Object |
getKeyFromValue(java.util.Map map,
java.lang.Object value,
java.lang.Object defaultValue) |
static java.lang.Object |
getValueFromQualifiedName(java.util.Map tree,
java.lang.String qualifiedName)
Obtain a value in a map with nested maps from a qualified name.
|
static boolean |
isEmpty(java.util.Map values)
It's empty if is null, without elements, with null elements or
elements with neutral value (empty strings, collections, nulls).
|
static boolean |
isEmptyOrZero(java.util.Map values)
It's empty if is null, without elements, with null elements or
elements with neutral value (empty strings, collections, nulls or zeroes).
|
static java.util.Map |
plainToTree(java.util.Map plainMap)
Converts a plain map (without levels) in a tree map.
|
static void |
putValueFromQualifiedName(java.util.Map tree,
java.lang.String qualifiedName,
java.lang.Object value)
Put a value in a map with nested maps from a qualified name.
|
static java.util.Map |
recursiveClone(java.util.Map origin)
Does a recursive clone of map.
|
static java.util.Map |
recursiveCloneWithCollections(java.util.Map origin)
Does a recursive clone of map, cloning collections too.
|
static java.util.Map |
toMap(java.lang.Object... values)
Converts the objects sent into a map.
|
static java.util.Map |
treeToPlain(java.util.Map treeMap)
Converts a tree map in a plain map (without levels).
|
static java.util.Map |
treeToPlainIncludingCollections(java.util.Map treeMap) |
static java.util.Map |
treeToPlainIncludingCollections(java.util.Map treeMap,
int baseIndex) |
public static java.util.Map clone(java.util.Map m)
Tries to make a clone using the clone()
method of
the origin if this is Cloneable, otherwise do a manual clon
of the map, without clone the elements (it's to say, it does not
make a deep clone).
m
- Original map to clone. Has to be Cloneable or has a
default contructor and implementing putAll
method.java.lang.IllegalArgumentException
- If precondition is brokenpublic static java.lang.Object getValueFromQualifiedName(java.util.Map tree, java.lang.String qualifiedName)
(((Map) mymap.get("a")).get("b")).get("c")
is equal to:
Maps.getValueFromQualifiedName(mymap, "a.b.c")
tree
- Map with map in some values, hence in tree-form.qualifiedName
- Name in form a.b.c.public static void putValueFromQualifiedName(java.util.Map tree, java.lang.String qualifiedName, java.lang.Object value)
(((Map) mymap.get("a")).get("b")).put("c", value)
is equal to:
Maps.putValueFromQualifiedName(mymap, "a.b.c", value)
tree
- Map with map in some values, hence in tree-form.qualifiedName
- Name in form a.b.c.value
- Value to putpublic static java.util.Map recursiveClone(java.util.Map origin)
A recursive clone means that if some value is a map itself this method is applied to it.
origin
- Cannot be null.public static java.util.Map recursiveCloneWithCollections(java.util.Map origin)
A recursive clone means that if some value is a map itself this method is applied to it. If some value is a collection the collection is duplicated.
origin
- Cannot be null.public static boolean isEmpty(java.util.Map values)
Numeric values with value 0 not are considered empty.
values
- Can be null.public static boolean isEmptyOrZero(java.util.Map values)
Numeric values with value 0 are considered empty.
values
- Can be null.public static java.util.Map plainToTree(java.util.Map plainMap)
That is, convert:
{invoice.year=2006, invoice.number=1, number=3}in
{invoice={year=2006, number=1}, number=3}
plainMap
- This argument is not changed. The keys must be strings. Mustn't be nullpublic static java.util.Map treeToPlain(java.util.Map treeMap)
That is, convert:
{invoice={year=2006, number=1}, number=3}in
{invoice.year=2006, invoice.number=1, number=3}
treeMap
- This argument is not changed. The keys must be strings. Mustn't be nullpublic static java.util.Map treeToPlainIncludingCollections(java.util.Map treeMap)
public static java.util.Map treeToPlainIncludingCollections(java.util.Map treeMap, int baseIndex)
public static java.util.Map toMap(java.lang.Object... values)
Useful to initialize maps:
Mapscores = Maps.toMap("Manolo", 7, "Angela", 10);
Vararg
- with key, value, key, value, etcpublic static java.lang.Object getKeyFromValue(java.util.Map map, java.lang.Object value, java.lang.Object defaultValue)
public static java.lang.Object getKeyFromValue(java.util.Map map, java.lang.Object value)