ca.quine.jcommons.freemind.maputil
Class MapUtils

java.lang.Object
  |
  +--ca.quine.jcommons.freemind.maputil.MapUtils

public class MapUtils
extends Object


Field Summary
static int TRAVERSAL_BFS
          Use a breadth first search traversal.
static int TRAVERSAL_DFS_POSTORDER
          Use a depth first search traversal, where we visit each node after its children.
static int TRAVERSAL_DFS_PRE_AND_POSTORDER
          Use a depth first search traversal, where each node is applied before and after its children.
static int TRAVERSAL_DFS_PREORDER
          Use a depth first search traversal, where we visit each node before its children.
 
Method Summary
static void addChild(Node parent, Node child)
          Adds the given child Node to the parent Node, creating a NodeItem wrapper for it.
static void addLink(Node node, String id)
          Creates a graphical link from the given Node to the Node with the given ID.
static void apply(Map map, int traversal, INodeApplicator applicator)
          Applies the given applicator to the given Map in the given traversal order.
static void apply(Node parentNode, Node node, int traversal, INodeApplicator applicator)
          Applies the given applicator to the given Node in the given traversal order.
static void closeLargeNodes(Map map, int maxNodeChildren)
          Close nodes that have more children than the given maximum.
static int countAndCloseLargeNodes(Node node, int maxNodeChildren)
          Perform a DFS (depth-first search) finding all nodes that have more than the given number of children, and close (fold) them.
static Node getChild(Node parent, int childNum)
          Returns the child Node of the given Node at the given index (the first Node is index 1), or null if no such child exists.
static Node getLeftNode(Map node)
          Returns the first child Node to the left of the root node in the given Map.
static Node getLeftNode(Map map, int childNum)
          Returns the child Node to the left of the root node in the given Map at the given index (the first Node is index 1), or null if no such child exists.
static Node getRightNode(Map map)
          Returns the first child Node to the right of the root node in the given Map.
static Node getRightNode(Map map, int childNum)
          Returns the child Node to the right of the root node in the given Map at the given index (the first Node is index 1), or null if no such child exists.
static Node makeNode(String text)
          Creates a new Node object with the given text.
static Node makeNode(String text, NodeItemPOSITIONType position)
          Creates a new Node with the given text and position.
static ArrayList search(Map map, int searchType, String searchText)
          Searches for the given searchText with the given searchType in the given Map and returns all the Nodes that match.
static void sortMap(Map map)
          Sorts the given FreeMind map based on the default NodeItemComparator.
static void sortMap(Map map, NodeItemComparator nodeItemComparator)
          Sorts the given FreeMind map using the given NodeItemComparator.
static void sortNode(Node node)
          Sorts the children of the given Node based on the default NodeItemComparator.
static void sortNode(Node node, NodeItemComparator nodeItemComparator)
          Sorts the children of the given Node based on the default NodeItemComparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRAVERSAL_DFS_PREORDER

public static final int TRAVERSAL_DFS_PREORDER
Use a depth first search traversal, where we visit each node before its children.

See Also:
apply(Map, int, INodeApplicator), apply(Node, Node, int, INodeApplicator), Constant Field Values

TRAVERSAL_DFS_POSTORDER

public static final int TRAVERSAL_DFS_POSTORDER
Use a depth first search traversal, where we visit each node after its children.

See Also:
apply(Map, int, INodeApplicator), apply(Node, Node, int, INodeApplicator), Constant Field Values

TRAVERSAL_BFS

public static final int TRAVERSAL_BFS
Use a breadth first search traversal.

See Also:
apply(Map, int, INodeApplicator), apply(Node, Node, int, INodeApplicator), Constant Field Values

TRAVERSAL_DFS_PRE_AND_POSTORDER

public static final int TRAVERSAL_DFS_PRE_AND_POSTORDER
Use a depth first search traversal, where each node is applied before and after its children.

See Also:
apply(Map, int, INodeApplicator), apply(Node, Node, int, INodeApplicator), Constant Field Values
Method Detail

sortMap

public static void sortMap(Map map)
Sorts the given FreeMind map based on the default NodeItemComparator. The default NodeItemComparator pulls out all the NodeItems that have Nodes in them and sorts them based on the text they hold.

Parameters:
map -

sortMap

public static void sortMap(Map map,
                           NodeItemComparator nodeItemComparator)
Sorts the given FreeMind map using the given NodeItemComparator.

Parameters:
map -
nodeItemComparator -

sortNode

public static void sortNode(Node node)
Sorts the children of the given Node based on the default NodeItemComparator. The default NodeItemComparator pulls out all the NodeItems that have Nodes in them and sorts them based on the text they hold.

Parameters:
node -

sortNode

public static void sortNode(Node node,
                            NodeItemComparator nodeItemComparator)
Sorts the children of the given Node based on the default NodeItemComparator. The default NodeItemComparator pulls out all the NodeItems that have Nodes in them and sorts them based on the text they hold.

Parameters:
node -

makeNode

public static Node makeNode(String text)
Creates a new Node object with the given text.

Parameters:
text -
Returns:
a new Node

makeNode

public static Node makeNode(String text,
                            NodeItemPOSITIONType position)
Creates a new Node with the given text and position.

Parameters:
text -
position - determines the side on which a Node directly off the root Node is displayed. The position is ignored for all other Nodes.
Returns:
a new Node

addChild

public static void addChild(Node parent,
                            Node child)
Adds the given child Node to the parent Node, creating a NodeItem wrapper for it.

Parameters:
parent -
child -

addLink

public static void addLink(Node node,
                           String id)
Creates a graphical link from the given Node to the Node with the given ID.

Parameters:
node -
id -

closeLargeNodes

public static void closeLargeNodes(Map map,
                                   int maxNodeChildren)
Close nodes that have more children than the given maximum.

Parameters:
map -
maxNodeChildren -

countAndCloseLargeNodes

public static int countAndCloseLargeNodes(Node node,
                                          int maxNodeChildren)
Perform a DFS (depth-first search) finding all nodes that have more than the given number of children, and close (fold) them. A parent node with (say) three folded children has a count of three regardless of how many children the folded nodes have.

Parameters:
node -
maxNodeChildren -
Returns:
the count of how many child nodes are open/unfolded. A closed/folded node has a count of 1.

getRightNode

public static Node getRightNode(Map map)
Returns the first child Node to the right of the root node in the given Map. NodeItem types that are not nodes (such as "ArrowLink", "Cloud", "Edge", "Font", etc.) are ignored.

Parameters:
map -
Returns:
the first Node to the right of the root Node in the given Map.

getRightNode

public static Node getRightNode(Map map,
                                int childNum)
Returns the child Node to the right of the root node in the given Map at the given index (the first Node is index 1), or null if no such child exists. NodeItem types that are not nodes (such as "ArrowLink", "Cloud", "Edge", "Font", etc.) are ignored.

Parameters:
map -
childNum -
Returns:
the child Node to the right of the root node in the given Map at the given index (the first Node is index 1), or null if no such child exists.

getLeftNode

public static Node getLeftNode(Map node)
Returns the first child Node to the left of the root node in the given Map. NodeItem types that are not nodes (such as "ArrowLink", "Cloud", "Edge", "Font", etc.) are ignored.

Parameters:
node -
Returns:
the first Node to the left of the root Node in the given Map.

getLeftNode

public static Node getLeftNode(Map map,
                               int childNum)
Returns the child Node to the left of the root node in the given Map at the given index (the first Node is index 1), or null if no such child exists.

Parameters:
map -
childNum -
Returns:
the child Node to the left of the root node in the given Map at the given index (the first Node is index 1), or null if no such child exists.

getChild

public static Node getChild(Node parent,
                            int childNum)
Returns the child Node of the given Node at the given index (the first Node is index 1), or null if no such child exists.

Parameters:
parent -
childNum -
Returns:
the child Node of the given Node at the given index (the first Node is index 1), or null if no such child exists.

search

public static ArrayList search(Map map,
                               int searchType,
                               String searchText)
Searches for the given searchText with the given searchType in the given Map and returns all the Nodes that match.

Parameters:
map - the Map in which to search
searchType - one of SearchNodeApplicator.SEARCH_CONTAINS, SearchNodeApplicator.SEARCH_EXACT_MATCH or SearchNodeApplicator.SEARCH_REGEXP
searchText - the text (or regex) to search for
Returns:
an ArrayList of Nodes

apply

public static void apply(Map map,
                         int traversal,
                         INodeApplicator applicator)
Applies the given applicator to the given Map in the given traversal order.

Parameters:
map -
traversal - one of TRAVERSAL_DFS_PREORDER or TRAVERSAL_DFS_POSTORDER
applicator -

apply

public static void apply(Node parentNode,
                         Node node,
                         int traversal,
                         INodeApplicator applicator)
Applies the given applicator to the given Node in the given traversal order.

Parameters:
parentNode - the parent Node of node (or null if node is the root node)
node -
traversal - one of TRAVERSAL_DFS_PREORDER or TRAVERSAL_DFS_POSTORDER
applicator -