related to bug 35729: some clean up in OrgTree
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 04 May 2017 09:55:58 +0200
changeset 32599 8fff4f5469e0
parent 32598 b7b9883e9f49
child 32600 944c8f82ef0d
related to bug 35729: some clean up in OrgTree

1. getDescendantTreeList had 2 boolean params which were always set to true,
so they have been removed
2. Removed also some code duplication
src/org/openbravo/base/secureApp/OrgTree.java
--- a/src/org/openbravo/base/secureApp/OrgTree.java	Wed May 03 14:15:41 2017 +0200
+++ b/src/org/openbravo/base/secureApp/OrgTree.java	Thu May 04 09:55:58 2017 +0200
@@ -289,57 +289,32 @@
     return returnTree;
   }
 
-  /**
-   * List param is modified with all the child nodes, repeatNodes decides what to do in case of
-   * repeated nodes.
-   * 
-   * @param parentNodeId
-   * @param list
-   * @param repeatNodes
-   */
-  private void getDescendantTreeList(String parentNodeId, List<OrgTreeNode> list,
-      boolean repeatNodes, boolean withZero) {
+  /** List param is modified with all the child nodes */
+  private void getDescendantTreeList(String parentNodeId, List<OrgTreeNode> list) {
     List<OrgTreeNode> childNodes = getNodesWithParent(parentNodeId);
-    if (repeatNodes) {
-      if (withZero || !getNodeById(parentNodeId).getId().equals("0"))
-        list.add(getNodeById(parentNodeId));
-    } else {
-      if ((list.size() == 0) && (withZero || !getNodeById(parentNodeId).getId().equals("0")))
-        list.add(getNodeById(parentNodeId));
-      else {
-        boolean exists = false;
-        for (int i = 0; i < list.size(); i++)
-          if (list.get(i).equals(parentNodeId))
-            exists = true;
-        if ((!exists) && (withZero || !getNodeById(parentNodeId).getId().equals("0")))
-          list.add(getNodeById(parentNodeId));
-      }
+
+    OrgTreeNode node = getNodeById(parentNodeId);
+    if (node != null) {
+      list.add(node);
     }
-    if (childNodes.size() != 0)
-      for (int i = 0; i < childNodes.size(); i++)
-        getDescendantTreeList(childNodes.get(i).getId(), list, repeatNodes, withZero);
 
-  }
-
-  /**
-   * List param is modified with all the child nodes
-   * 
-   * @param parentNodeId
-   * @param list
-   */
-  private void getDescendantTreeList(String parentNodeId, List<OrgTreeNode> list) {
-    getDescendantTreeList(parentNodeId, list, true, true);
+    for (OrgTreeNode child : childNodes) {
+      getDescendantTreeList(child.getId(), list);
+    }
   }
 
   /**
    * Returns the node matching the id, in case it does not exists it returns null
    */
   private OrgTreeNode getNodeById(String id) {
-    if (nodes == null)
+    if (nodes == null) {
       return null;
-    for (int i = 0; i < nodes.size(); i++)
-      if (nodes.get(i).equals(id))
-        return nodes.get(i);
+    }
+    for (OrgTreeNode node : nodes) {
+      if (node.equals(id)) {
+        return node;
+      }
+    }
     return null;
   }
 
@@ -347,12 +322,7 @@
    * In case the node id is in the tree it returns true, if not false.
    */
   private boolean isNodeInTree(String id) {
-    if (nodes == null)
-      return false;
-    for (int i = 0; i < nodes.size(); i++)
-      if (nodes.get(i).equals(id))
-        return true;
-    return false;
+    return getNodeById(id) != null;
   }
 
   /**