Source Code Cross Referenced for TreeLevel.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » jsf » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.jsf.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/model/TreeLevel.java $
003:         * $Id: TreeLevel.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004 The Sakai Foundation.
007:         *
008:         * Licensed under the Educational Community License, Version 1.0 (the "License");
009:         * you may not use this file except in compliance with the License.
010:         * You may obtain a copy of the License at
011:         *
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         *
014:         * Unless required by applicable law or agreed to in writing, software
015:         * distributed under the License is distributed on an "AS IS" BASIS,
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:         * See the License for the specific language governing permissions and
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.jsf.model;
021:
022:        import java.util.ArrayList;
023:        import java.util.List;
024:        import java.util.*;
025:
026:        public class TreeLevel {
027:            private TreeLevel parent = null;
028:            private ArrayList childList;
029:            private int index;
030:            boolean child;
031:
032:            /**
033:             * "Parent" constructor.  This is a top level and is its own parent and is a
034:             * child of none.
035:             */
036:            public TreeLevel(int index) {
037:                this .childList = new ArrayList();
038:                this .parent = this ;
039:                this .index = index;
040:                this .child = false;
041:            }
042:
043:            /**
044:             * No-arg constructor.  "Parent" constructor equivalent, with index set to 0.
045:             */
046:            public TreeLevel() {
047:                this .childList = new ArrayList();
048:                this .parent = this ;
049:                this .index = 0;
050:                this .child = false;
051:            }
052:
053:            /**
054:             * "Child" constructor.  Create a child of "parent".
055:             * @param parent TreeLevel
056:             */
057:            public TreeLevel(TreeLevel parent) {
058:                this .childList = new ArrayList();
059:                this .parent = parent;
060:                this .index = parent.addChild(this );
061:                this .child = true;
062:            }
063:
064:            /**
065:             * Get parent, or self if no parent.
066:             * @return TreeLevel
067:             */
068:            public TreeLevel getParent() {
069:                return parent;
070:            }
071:
072:            /**
073:             * Get list of all child TreeLevels
074:             * @return List
075:             */
076:            public List getChildren() {
077:                return childList;
078:            }
079:
080:            /**
081:             * True if this has a parent.
082:             * @return boolean
083:             */
084:            public boolean isChild() {
085:                return child;
086:            }
087:
088:            /**
089:             * String representing 0-indexed parent-child relationships.
090:             * Example: 18_9_4 is the fourth child of the nineth child of 18
091:             * @return String
092:             */
093:            public String toString() {
094:                // recurse for children, done if parent
095:                if (this .isChild()) {
096:                    return this .getParent().toString() + "_" + index;
097:                } else {
098:                    return "" + index;
099:                }
100:            }
101:
102:            /**
103:             * Utility reciprocal method to add a child when it chooses this as its parent.
104:             * @param child TreeLevel
105:             * @return int
106:             */
107:            protected int addChild(TreeLevel child) {
108:                childList.add(child);
109:                return childList.size();
110:            }
111:
112:            /**
113:             * test code, demonstrates usage.
114:             * @param args String[]
115:             */
116:            public static void main(String[] args) {
117:                System.out.println("testing flat");
118:                ArrayList treeList = new ArrayList();
119:                for (int i = 0; i < 10; i++) {
120:                    treeList.add(new TreeLevel(i));
121:                }
122:                for (Iterator iter = treeList.iterator(); iter.hasNext();) {
123:                    Object item = (Object) iter.next();
124:                    System.out.println("LEVEL: " + item);
125:                }
126:                System.out.println("testing hierarchy");
127:                treeList = new ArrayList();
128:                TreeLevel t0 = new TreeLevel(0);
129:                treeList.add(t0);
130:
131:                for (int i = 0; i < 10; i++) {
132:                    TreeLevel t1 = new TreeLevel(t0);
133:                    treeList.add(t1);
134:                    for (int j = 0; j < 5; j++) {
135:                        TreeLevel t2 = new TreeLevel(t1);
136:                        treeList.add(t2);
137:                    }
138:                }
139:
140:                for (Iterator iter = treeList.iterator(); iter.hasNext();) {
141:                    Object item = (Object) iter.next();
142:                    System.out.println("LEVEL: " + item);
143:                }
144:            }
145:
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.