org.openxava.util
Class Maps

java.lang.Object
  extended by org.openxava.util.Maps

public class Maps
extends java.lang.Object

Utilities to work with maps.

Author:
Javier Paniza

Constructor Summary
Maps()
           
 
Method Summary
static java.util.Map clone(java.util.Map m)
          Create a clone.
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 treeToPlain(java.util.Map treeMap)
          Converts a tree map in a plain map (without levels).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Maps

public Maps()
Method Detail

clone

public static java.util.Map clone(java.util.Map m)
Create a clone.

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).

Parameters:
m - Original map to clone. Has to be Cloneable or has a default contructor and implementing putAll method.
Returns:
Can be null (if the original is null), and the same type of original.
Throws:
java.lang.IllegalArgumentException - If precondition is broken

getValueFromQualifiedName

public 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. For example: (((Map) mymap.get("a")).get("b")).get("c") is equal to: Maps.getValueFromQualifiedName(mymap, "a.b.c")

Parameters:
tree - Map with map in some values, hence in tree-form.
qualifiedName - Name in form a.b.c.

putValueFromQualifiedName

public 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. For example: (((Map) mymap.get("a")).get("b")).put("c", value) is equal to: Maps.putValueFromQualifiedName(mymap, "a.b.c", value)

Parameters:
tree - Map with map in some values, hence in tree-form.
qualifiedName - Name in form a.b.c.
value - Value to put

recursiveClone

public static java.util.Map recursiveClone(java.util.Map origin)
Does a recursive clone of map.

A recursive clone means that if some value is a map itself this method is applied to it.

Parameters:
origin - Cannot be null. Must to have a default constructor
Returns:
instanceof origen.getClass()

isEmpty

public 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).

Numeric values with value 0 not are considered empty.

Parameters:
values - Can be null.

isEmptyOrZero

public 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).

Numeric values with value 0 are considered empty.

Parameters:
values - Can be null.

plainToTree

public static java.util.Map plainToTree(java.util.Map plainMap)
Converts a plain map (without levels) in a tree map.

That is, convert:

 {invoice.year=2006, invoice.number=1, number=3}
 
in
 {invoice={year=2006, number=1}, number=3}
 

Parameters:
plainMap - This argument is not changed. The keys must be strings. Mustn't be null
Returns:
A map with the data in tree format.

treeToPlain

public static java.util.Map treeToPlain(java.util.Map treeMap)
Converts a tree map in a plain map (without levels).

That is, convert:

 {invoice={year=2006, number=1}, number=3}
 
in
 {invoice.year=2006, invoice.number=1, number=3}
 

Parameters:
treeMap - This argument is not changed. The keys must be strings. Mustn't be null
Returns:
A map with the data in plain format.