Search in sources :

Example 1 with TreeNode

use of org.apache.myfaces.custom.tree2.TreeNode in project TNTConcept by autentia.

the class MenuBean method addLeaf.

/**
 * Add leaf node to parent node if it is accesible by current user
 * @param path path of current node
 * @param creds current user
 * @param neededRole role needed to render the node
 * @param parent parent node
 * @param cmd command name
 * @return true if node was added
 */
private boolean addLeaf(Stack<TreeNode> path, Principal creds, GrantedAuthority neededRole, String cmd) {
    boolean added = false;
    if (neededRole == null || creds.hasAuthority(neededRole)) {
        String text;
        try {
            text = msg.getString("menu." + cmd);
        } catch (MissingResourceException e) {
            text = "MISSING : " + cmd + " : MISSING";
        }
        TreeNode child = new TreeNodeBase("document", text, cmd, true);
        path.peek().getChildren().add(child);
        added = true;
    }
    log.debug("addLeaf - " + (added ? "ADD   " : "IGNORE") + ": " + cmd);
    return added;
}
Also used : TreeNode(org.apache.myfaces.custom.tree2.TreeNode) MissingResourceException(java.util.MissingResourceException) TreeNodeBase(org.apache.myfaces.custom.tree2.TreeNodeBase)

Example 2 with TreeNode

use of org.apache.myfaces.custom.tree2.TreeNode in project Data-Structures-Algorithms by pankajgangwar.

the class A method dfs.

public TreeNode dfs(int[] pre, int preStart, int preEnd, int[] post, int postStart, int postEnd) {
    if (preStart > preEnd)
        return null;
    TreeNode root = new TreeNode(pre[preStart]);
    if (preStart == preEnd)
        return root;
    int len = postMap.get(pre[preStart + 1]) - postStart + 1;
    root.left = dfs(pre, preStart + 1, preStart + len, post, postStart, postMap.get(pre[preStart + 1]));
    root.right = dfs(pre, preStart + len + 1, preEnd, post, postMap.get(pre[preStart + 1]) + 1, postEnd - 1);
    return root;
}
Also used : TreeNode(com.pkumar7.TreeNode)

Example 3 with TreeNode

use of org.apache.myfaces.custom.tree2.TreeNode in project Data-Structures-Algorithms by pankajgangwar.

the class A method helper.

public TreeNode helper(int[] pre, int[] post) {
    TreeNode root = new TreeNode(pre[preIndex++]);
    if (root.val != post[postIndex]) {
        root.left = helper(pre, post);
    }
    if (root.val != post[postIndex]) {
        root.right = helper(pre, post);
    }
    postIndex++;
    return root;
}
Also used : TreeNode(com.pkumar7.TreeNode)

Example 4 with TreeNode

use of org.apache.myfaces.custom.tree2.TreeNode in project Data-Structures-Algorithms by pankajgangwar.

the class B method bfs.

public TreeNode bfs(TreeNode root, int val, int depth) {
    if (depth == 1) {
        TreeNode newRoot = new TreeNode(val);
        newRoot.left = root;
        return newRoot;
    }
    Queue<TreeNode> q = new LinkedList<>();
    q.offer(root);
    int currD = 0;
    outer: while (!q.isEmpty()) {
        int size = q.size();
        currD += 1;
        while (size-- > 0) {
            TreeNode curr = q.poll();
            if (currD + 1 == depth) {
                TreeNode left = new TreeNode(val);
                if (curr.left != null) {
                    TreeNode prevLeft = curr.left;
                    curr.left = left;
                    left.left = prevLeft;
                } else {
                    curr.left = left;
                }
                TreeNode right = new TreeNode(val);
                if (curr.right != null) {
                    TreeNode prevRight = curr.right;
                    curr.right = right;
                    right.right = prevRight;
                } else {
                    curr.right = right;
                }
            } else {
                if (curr.left != null) {
                    q.offer(curr.left);
                }
                if (curr.right != null) {
                    q.offer(curr.right);
                }
            }
        }
    }
    return root;
}
Also used : TreeNode(com.pkumar7.TreeNode) LinkedList(java.util.LinkedList)

Example 5 with TreeNode

use of org.apache.myfaces.custom.tree2.TreeNode in project Data-Structures-Algorithms by pankajgangwar.

the class B method constructBst.

public TreeNode constructBst(List<Integer> list, int low, int high) {
    if (low > high)
        return null;
    int mid = low + (high - low) / 2;
    TreeNode root = new TreeNode(list.get(mid));
    root.left = constructBst(list, low, mid - 1);
    root.right = constructBst(list, mid + 1, high);
    return root;
}
Also used : TreeNode(com.pkumar7.TreeNode)

Aggregations

TreeNode (com.pkumar7.TreeNode)47 LinkedList (java.util.LinkedList)16 ArrayList (java.util.ArrayList)12 TreeNode (hatecode._0001_0999.TreeNode)11 Stack (java.util.Stack)7 TreeNode (org.apache.myfaces.custom.tree2.TreeNode)6 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 List (java.util.List)3 TreeNodeBase (org.apache.myfaces.custom.tree2.TreeNodeBase)3 Account (com.autentia.tnt.businessobject.Account)1 AccountEntry (com.autentia.tnt.businessobject.AccountEntry)1 AccountEntryType (com.autentia.tnt.businessobject.AccountEntryType)1 Activity (com.autentia.tnt.businessobject.Activity)1 AdminHoliday (com.autentia.tnt.businessobject.AdminHoliday)1 Bill (com.autentia.tnt.businessobject.Bill)1 Book (com.autentia.tnt.businessobject.Book)1 BulletinBoard (com.autentia.tnt.businessobject.BulletinBoard)1 BulletinBoardCategory (com.autentia.tnt.businessobject.BulletinBoardCategory)1 CompanyState (com.autentia.tnt.businessobject.CompanyState)1