- List<ModuleIdentification> orderLibInstance1() {\r
- List<ModuleIdentification> orderList = new ArrayList<ModuleIdentification>();\r
- //\r
- // Stack of node which track the library instance name ant its visiting\r
- // flag.\r
- //\r
- List<Node> stackList = new ArrayList<Node>();\r
- int stackSize = 0;\r
- ModuleIdentification libInstanceId = null;\r
- if (libInstanceList.size() < 0) {\r
- return null;\r
- }\r
-\r
- //\r
- // Reorder the library instance.\r
- //\r
- for (int i = 0; i < libInstanceList.size(); i++) {\r
- //\r
- // If library instance is already in the order list skip it.\r
- //\r
- if (isInLibInstance(orderList, libInstanceList.get(i).libId)) {\r
- continue;\r
- }\r
- \r
- Node node = new Node(libInstanceList.get(i).libId, false);\r
- //\r
- // Use stack to reorder library instance.\r
- // Push node to stack.\r
- //\r
- stackList.add(node);\r
- while (stackList.size() > 0) {\r
- stackSize = stackList.size() - 1;\r
- //\r
- // Pop the first node in stack. If the node flag has been visited\r
- // add this node to orderlist and remove it from stack.\r
- //\r
- if (stackList.get(stackSize).isVisit) {\r
- if (!isInLibInstance(orderList,\r
- stackList.get(stackSize).nodeId)) {\r
- orderList.add(stackList.get(stackSize).nodeId);\r
- stackList.remove(stackSize);\r
- }\r
- \r
- } else {\r
- //\r
- // Get the node value and set visit flag as true.\r
- //\r
- stackList.get(stackList.size() - 1).isVisit = true;\r
- String[] libClassList = this.libInstanceMap.get(stackList\r
- .get(stackSize).nodeId);\r
- //\r
- // Push the node dependence library instance to the stack.\r
- //\r
- if (libClassList != null) {\r
- for (int j = 0; j < libClassList.length; j++) {\r
- libInstanceId = this.libClassMap.get(libClassList[j]);\r
- if (libInstanceId != null\r
- && !isInLibInstance(orderList, libInstanceId)) {\r
- //\r
- // If and only if the currently library instance\r
- // is not in stack and it have constructor or \r
- // destructor function, push this library \r
- // instacne in stack.\r
- //\r
- if (!isInStackList(stackList, this.libClassMap\r
- .get(libClassList[j])) /* && isHaveConsDestructor(libInstanceId) */) {\r
- stackList.add(new Node(this.libClassMap\r
- .get(libClassList[j]), false));\r
- }\r
- }\r
- }\r
- }\r
- }\r
- System.out.println("################################################");\r
- for (int ii = 0; ii < orderList.size(); ++ii) {\r
- System.out.println(" " + orderList.get(ii));\r
- }\r
- }\r
- }\r
- return orderList;\r
- }\r
-\r