Source Code Cross Referenced for Not.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » rules » engine » 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 » SourceTap CRM » org.ofbiz.rules.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.ofbiz.rules.engine;
002:
003:        /**
004:         * <p><b>Title:</b> Not
005:         * <p><b>Description:</b> None
006:         * <p>Copyright (c) 1999 Steven J. Metsker.
007:         * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
008:         *
009:         * <p>Permission is hereby granted, free of charge, to any person obtaining a
010:         *  copy of this software and associated documentation files (the "Software"),
011:         *  to deal in the Software without restriction, including without limitation
012:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
013:         *  and/or sell copies of the Software, and to permit persons to whom the
014:         *  Software is furnished to do so, subject to the following conditions:
015:         *
016:         * <p>The above copyright notice and this permission notice shall be included
017:         *  in all copies or substantial portions of the Software.
018:         *
019:         * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
020:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
021:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
022:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
023:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
024:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
025:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
026:         *
027:         * <br>
028:         * <p>A Not is a structure that fails if it can prove itself
029:         * against a program.
030:         * <p>
031:         * This simple behavior can have surprising results. For
032:         * example:
033:         * <blockquote><pre>
034:         *     goodBachelor(X) :- male (X), not married(X);
035:         *     badBachelor(X) :- not married(X), male(X);
036:         *     married(jim);
037:         *     male(jeremy);
038:         *     male(jim);
039:         * </pre></blockquote>
040:         *
041:         * Against this program, a query <code>badBachelor(X)</code>
042:         * will find no bachelors. This rule negates <code>married(X)
043:         * </code> which will bind uninstantiated <code>X</code> to
044:         * <code>jim</code> every time. Thus <code>married(X)</code>
045:         * will always be true, <code>not married(X)</code> will
046:         * always be false, and there are no bad bachelors, which is
047:         * untrue. The good rule instantiates <code>X</code> to a good
048:         * candidate first, and the negation will prove or disprove
049:         * itself for that candidate.
050:         * <p>
051:         * (A parser of the logic code given above will produce
052:         * engine calls similar to the following code.)
053:         *
054:         * <blockquote><pre>
055:         *     Program p = new Program();
056:         *     Variable x = new Variable("X");
057:         *
058:         *     p.addAxiom(new Rule(new Structure[]{
059:         *         new Structure("goodBachelor", new Term[]{x}),
060:         *         new Structure("male",         new Term[]{x}),
061:         *         new Not      ("married",      new Term[]{x})}));
062:         *
063:         *     p.addAxiom(new Rule(new Structure[]{
064:         *         new Structure("badBachelor",  new Term[]{x}),
065:         *         new Not      ("married",      new Term[]{x}),
066:         *         new Structure("male",         new Term[]{x})}));
067:         *     p.addAxiom(new Fact("married", "jim"));
068:         *     p.addAxiom(new Fact("male", "jeremy"));
069:         *     p.addAxiom(new Fact("male", "jim"));
070:         *
071:         *     Query qGood = new Query(
072:         *         p, new Structure("goodBachelor", new Term[]{x}));
073:         *     while(qGood.canFindNextProof()) {
074:         *         System.out.println(
075:         *             "goodBachelor query finds: " + qGood.lookup("X"));
076:         *     }
077:         *
078:         *     Query qBad = new Query(
079:         *         p, new Structure("badBachelor", new Term[]{x}));
080:         *     while(qBad.canFindNextProof()) {
081:         *         System.out.println(
082:         *             "badBachelor query finds: " + qBad.lookup("X"));
083:         *     }
084:         *
085:         * </pre></blockquote>
086:         *
087:         * Running this code prints out:
088:         * <blockquote><pre>
089:         *     goodBachelor query finds: jeremy
090:         * </pre></blockquote>
091:         *
092:         * @author Steven J. Metsker
093:         * @version 1.0
094:         */
095:        public class Not extends Structure {
096:
097:            /**
098:             * Contructs a Not from the specified object.
099:             * <p>
100:             * Such a Not will search a program for a fact that contains
101:             * just the functor. For example, it might make sense to create a
102:             * <code>Not("demo")</code> that would look for the fact
103:             * <code>demo</code> to see if the program is in demo mode.
104:             *
105:             * @param   functor   the functor for this structure
106:             */
107:            public Not(Object functor) {
108:                this (functor, new Term[0]);
109:            }
110:
111:            /**
112:             * Constructs a Not with the specified functor and terms.
113:             *
114:             * This is the normal way to define a Not. This structure will
115:             * be true if there is no possible proof of it in a program.
116:             *
117:             * @param   functor   the functor of the structure
118:             *
119:             * @param   terms   the terms of the structure, which may be either
120:             *                  variables or other structures
121:             */
122:            public Not(Object functor, Term[] terms) {
123:                super (functor, terms);
124:            }
125:
126:            /**
127:             * Constructs a Not version of the supplied structure.
128:             *
129:             * @param   structure   the structure to negate
130:             */
131:            public Not(Structure s) {
132:                this (s.functor, s.terms);
133:            }
134:
135:            /**
136:             * Create a <code>ConsultingNot</code> counterpart that
137:             * can prove itself.
138:             *
139:             * @param AxiomSource where to find axioms to prove
140:             *        against
141:             *
142:             * @param Scope the scope to use for variables in the
143:             *        <code>ConsultingStructure</code>
144:             *
145:             * @return a <code>ConsultingNot</code> counterpart that
146:             *         can prove itself
147:             */
148:            public Term copyForProof(AxiomSource as, Scope scope) {
149:                Term[] newTerms = new Term[terms.length];
150:
151:                for (int i = 0; i < terms.length; i++) {
152:                    newTerms[i] = terms[i].copyForProof(as, scope);
153:                }
154:                return new ConsultingNot(new ConsultingStructure(as, functor,
155:                        newTerms));
156:            }
157:
158:            /**
159:             * Returns true if the supplied object is an equivalent
160:             * not structure.
161:             *
162:             * @param   object   the object to compare
163:             *
164:             * @return   true, if the supplied object is a Not, and
165:             *           the two object's sub-structures are equal
166:             */
167:            public boolean equals(Object o) {
168:                if (!(o instanceof  Not))
169:                    return false;
170:                Not n = (Not) o;
171:
172:                if (!functorAndArityEquals(n)) {
173:                    return false;
174:                }
175:                for (int i = 0; i < terms.length; i++) {
176:                    if (!(terms[i].equals(n.terms[i]))) {
177:                        return false;
178:                    }
179:                }
180:                return true;
181:            }
182:
183:            /**
184:             * Returns a string description of this Not.
185:             *
186:             * @return    a string description of this Not
187:             */
188:            public String toString() {
189:                return "not " + super.toString();
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.