Source Code Cross Referenced for AbstractClauseSetComparator.java in  » Rule-Engine » Mandarax » org » mandarax » util » comparators » 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 » Rule Engine » Mandarax » org.mandarax.util.comparators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.mandarax.util.comparators;
002:
003:        /*
004:         * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        import java.io.Serializable;
022:        import java.util.Comparator;
023:        import java.util.List;
024:
025:        import org.mandarax.kernel.ComplexTerm;
026:        import org.mandarax.kernel.Prerequisite;
027:        import org.mandarax.kernel.Rule;
028:        import org.mandarax.kernel.Term;
029:        import org.mandarax.kernel.TermContainer;
030:        import org.mandarax.kernel.VariableTerm;
031:
032:        /**
033:         * Abstract class for clause set comparators.
034:         * Implements a couple of useful count methods that can be used
035:         * in subclasses.
036:         * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
037:         * @version 3.4 <7 March 05>
038:         * @since 2.2
039:         */
040:        public abstract class AbstractClauseSetComparator implements 
041:                Comparator, Serializable {
042:
043:            /**
044:             * Constructor.
045:             */
046:            public AbstractClauseSetComparator() {
047:                super ();
048:            }
049:
050:            /**
051:             * Count the number of negated prerequisites of a rule.
052:             * @return the number of prerequisites
053:             * @param rule a rule
054:             */
055:            protected int countNegatedPrerequisites(Rule rule) {
056:                int count = 0;
057:                List body = rule.getBody();
058:                for (int i = 0; i < body.size(); i++) {
059:                    Prerequisite prereq = (Prerequisite) body.get(i);
060:                    if (prereq.isNegatedAF())
061:                        count = count + 1;
062:                }
063:                return count;
064:            }
065:
066:            /**
067:             * Count the number of prerequisites of a rule.
068:             * @return the number of prerequisites
069:             * @param rule a rule
070:             */
071:            protected int countPrerequisites(Rule rule) {
072:
073:                return rule.getBody().size();
074:            }
075:
076:            /**
077:             * Count the number of variables in a term container
078:             * (fact of complex term).
079:             * @return the number of variables detected
080:             * @param tc the term container
081:             */
082:            protected int countVariables(TermContainer tc) {
083:                int count = 0;
084:                Term[] terms = tc.getTerms();
085:                for (int i = 0; i < terms.length; i++) {
086:                    if (terms[i] instanceof  VariableTerm)
087:                        count = count + 1;
088:                    else if (terms[i] instanceof  ComplexTerm)
089:                        count = count + countVariables((ComplexTerm) terms[i]);
090:                }
091:                return count;
092:            }
093:
094:            /**
095:             * Count the number of variables in the prerequisites of a rule.
096:             * @return the number of prerequisites
097:             * @param rule a rule
098:             */
099:            protected int countVariablesInPrerequisites(Rule rule) {
100:                int count = 0;
101:                List body = rule.getBody();
102:                for (int i = 0; i < body.size(); i++) {
103:                    Prerequisite prereq = (Prerequisite) body.get(i);
104:                    count = count + countVariables(prereq);
105:                }
106:                return count;
107:            }
108:
109:            /**
110:             * Get a descriptive name.
111:             * @return a string
112:             */
113:            public abstract String getName();
114:
115:            /**
116:             * Convert the object to a string.
117:             * @return a string
118:             */
119:            public String toString() {
120:                return getName();
121:            }
122:
123:            /**
124:             * Compares objects. All instances are stateless and considered to be equal if the classes are the same!
125:             * @param obj an object
126:             * @return a boolean
127:             */
128:            public boolean equals(Object obj) {
129:                return obj != null && obj.getClass() == getClass();
130:
131:            }
132:
133:            /**
134:             * Get the hash code of this object.
135:             * @return an integer
136:             */
137:            public int hashCode() {
138:                return getClass().hashCode();
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.