org.omnaest.utils.structure.hierarchy.nodemap
Class NodeMapFactory

java.lang.Object
  extended by org.omnaest.utils.structure.hierarchy.nodemap.NodeMapFactory

public class NodeMapFactory
extends Object

Helper to create NodeMap instances

Author:
Omnaest

Nested Class Summary
static interface NodeMapFactory.ModelAndChildExtractor<K,V,M>
           
 
Constructor Summary
NodeMapFactory()
           
 
Method Summary
static
<M> Map<String,M>
convertNodeMapToHierarchicalKeyMap(NodeMap<String,M> nodeMap, String delimiter)
          Converts a NodeMap into a normal Map with hierarchical keys.
static
<M> Map<String,M>
convertNodeMapWithLastLevelAsMapToHierarchicalKeyMap(NodeMap<String,Map<String,M>> nodeMap, String delimiter)
          Converts a NodeMap into a normal Map with hierarchical keys.
static
<K,V,M> NodeMap<K,Map<K,M>>
newNodeMap(Map<K,V> map, NodeMapFactory.ModelAndChildExtractor<K,V,M> modelAndChildExtractor)
           
static NodeMap<String,Map<String,Object>> newNodeMap(Map<String,Object> nestedMap)
          Returns a new NodeMap for a given Map which contains nested further Map instances
static NodeMap<String,Map<String,Object>> newNodeMap(Object object)
          Returns a new NodeMap for a given Object which is based on the Java bean properties
static
<V> NodeMap<String,V>
newNodeMapFromHierarchicalKeyMap(Map<String,V> map, String delimiterRegEx)
          Returns a new NodeMap based on a normal Map containing hierarchical structured keys.
static
<V> NodeMap<String,Map<String,V>>
newNodeMapFromHierarchicalKeyMapWithLastLevelAsMap(Map<String,V> map, String delimiterRegEx)
          Similar to newNodeMapFromHierarchicalKeyMap(Map, String) but having the last hierarchy level put into a Map which acts as model
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeMapFactory

public NodeMapFactory()
Method Detail

newNodeMap

public static <K,V,M> NodeMap<K,Map<K,M>> newNodeMap(Map<K,V> map,
                                                     NodeMapFactory.ModelAndChildExtractor<K,V,M> modelAndChildExtractor)
Parameters:
map -
modelAndChildExtractor -
Returns:

newNodeMap

public static NodeMap<String,Map<String,Object>> newNodeMap(Object object)
Returns a new NodeMap for a given Object which is based on the Java bean properties

Parameters:
object -
Returns:

newNodeMap

public static NodeMap<String,Map<String,Object>> newNodeMap(Map<String,Object> nestedMap)
Returns a new NodeMap for a given Map which contains nested further Map instances

Parameters:
nestedMap -
Returns:

newNodeMapFromHierarchicalKeyMap

public static <V> NodeMap<String,V> newNodeMapFromHierarchicalKeyMap(Map<String,V> map,
                                                                     String delimiterRegEx)
Returns a new NodeMap based on a normal Map containing hierarchical structured keys. A hierarchical key could be e.g. node1.subnode1.subsubnode1 where '.' is the delimiter. Note: the point has to be quoted actually using Pattern.quote(String).

Parameters:
map - Map
delimiterRegEx -
Returns:
See Also:
convertNodeMapToHierarchicalKeyMap(NodeMap, String), Pattern.quote(String)

newNodeMapFromHierarchicalKeyMapWithLastLevelAsMap

public static <V> NodeMap<String,Map<String,V>> newNodeMapFromHierarchicalKeyMapWithLastLevelAsMap(Map<String,V> map,
                                                                                                   String delimiterRegEx)
Similar to newNodeMapFromHierarchicalKeyMap(Map, String) but having the last hierarchy level put into a Map which acts as model

Parameters:
map -
delimiterRegEx -
Returns:
See Also:
convertNodeMapWithLastLevelAsMapToHierarchicalKeyMap(NodeMap, String)

convertNodeMapToHierarchicalKeyMap

public static <M> Map<String,M> convertNodeMapToHierarchicalKeyMap(NodeMap<String,M> nodeMap,
                                                                   String delimiter)
Converts a NodeMap into a normal Map with hierarchical keys.
Example:
 parent +
        |
        +-subnode1
        +-subnode2
 
results in
parent.subnode1=xyz
parent.subnode2=xyz

Parameters:
nodeMap -
delimiter -
Returns:
See Also:
newNodeMapFromHierarchicalKeyMap(Map, String)

convertNodeMapWithLastLevelAsMapToHierarchicalKeyMap

public static <M> Map<String,M> convertNodeMapWithLastLevelAsMapToHierarchicalKeyMap(NodeMap<String,Map<String,M>> nodeMap,
                                                                                     String delimiter)
Converts a NodeMap into a normal Map with hierarchical keys.
Example:
 parent +
        |
        Map
          +-subnode1
          +-subnode2
 
results in
parent.subnode1=xyz
parent.subnode2=xyz

Parameters:
nodeMap -
delimiter -
Returns:
See Also:
newNodeMapFromHierarchicalKeyMapWithLastLevelAsMap(Map, String)


Copyright © 2013. All Rights Reserved.