Source Code Cross Referenced for Filter.java in  » Testing » jacareto » jacareto » filter » 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 » Testing » jacareto » jacareto.filter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.filter;
025:
026:        import jacareto.struct.Structure;
027:        import jacareto.struct.StructureElement;
028:        import jacareto.system.Environment;
029:        import jacareto.system.EnvironmentMember;
030:
031:        import java.util.Stack;
032:        import java.util.Vector;
033:
034:        /**
035:         * A class which filters structures. The method {@link #getElements(Structure,boolean)} returns all
036:         * structure elements contained in the structure for which the method {@link
037:         * #matches(StructureElement)} returns <code>true</code>.
038:         *
039:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
040:         * @version 1.0
041:         */
042:        public abstract class Filter extends EnvironmentMember {
043:            /**
044:             * Creates a new filter.
045:             *
046:             * @param env the environment
047:             */
048:            public Filter(Environment env) {
049:                super (env);
050:            }
051:
052:            /**
053:             * Returns <code>true</code> when a given structure elements matches the filter criterion,
054:             * otherwise <code>false</code>.
055:             *
056:             * @param element DOCUMENT ME!
057:             *
058:             * @return DOCUMENT ME!
059:             */
060:            public abstract boolean matches(StructureElement element);
061:
062:            /**
063:             * Returns the name of the filter.
064:             *
065:             * @return DOCUMENT ME!
066:             */
067:            public abstract String getName();
068:
069:            /**
070:             * Returns all structure elements contained in the given structure for which the method {@link
071:             * #matches(StructureElement)} returns <code>true</code>. If a structure element does not
072:             * match the filter criterion, its children will be tested. If a structure element matches the
073:             * criterion, its children will only be tested when the argument <code>recurseOnMatch</code>
074:             * is set to <code>true</code>.
075:             *
076:             * @param structure the structure
077:             * @param recurseOnMatch whether or not recursing into an element's children when the element
078:             *        matches a criterion
079:             *
080:             * @return the structure elements contained in the structure which match the filter criterion
081:             */
082:            public StructureElement[] getElements(Structure structure,
083:                    boolean recurseOnMatch) {
084:                return getElements(structure.getRootElement(), recurseOnMatch);
085:            }
086:
087:            /**
088:             * Returns all structure elements contained in the subtree of the given structure element for
089:             * which the method {@link #matches(StructureElement)} returns <code>true</code>. If a
090:             * structure element does not match the filter criterion, its children will be tested. If a
091:             * structure element matches the criterion, its children will only be tested when the argument
092:             * <code>recurseOnMatch</code> is set to <code>true</code>.
093:             *
094:             * @param element the structure element
095:             * @param recurseOnMatch whether or not recursing into an element's children when the element
096:             *        matches a criterion
097:             *
098:             * @return the structure elements contained in the structure which match the filter criterion
099:             */
100:            public StructureElement[] getElements(StructureElement element,
101:                    boolean recurseOnMatch) {
102:                Vector vResult = new Vector(10, 10);
103:                StructureElement[] result;
104:
105:                // initialize the stack
106:                Stack stack = new Stack();
107:                stack.push(element);
108:
109:                while (!stack.isEmpty()) {
110:                    StructureElement el = (StructureElement) stack.pop();
111:                    boolean addChildren;
112:
113:                    if (matches(el)) {
114:                        vResult.add(el);
115:                        addChildren = recurseOnMatch && el.hasChildren();
116:                    } else {
117:                        addChildren = el.hasChildren();
118:                    }
119:
120:                    // add the structure element's children
121:                    if (addChildren) {
122:                        StructureElement[] children = el.getChildren();
123:
124:                        for (int i = children.length - 1; i >= 0; i--) {
125:                            stack.push(children[i]);
126:                        }
127:                    }
128:                }
129:
130:                result = new StructureElement[vResult.size()];
131:
132:                for (int i = 0; i < result.length; i++) {
133:                    result[i] = (StructureElement) vResult.get(i);
134:                }
135:
136:                return result;
137:            }
138:
139:            /**
140:             * Returns a string representation (the name of the filter)
141:             *
142:             * @return DOCUMENT ME!
143:             */
144:            public String toString() {
145:                return getName();
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.