Source Code Cross Referenced for AndOrExpression.java in  » Development » JoSQL » org » josql » expressions » 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 » Development » JoSQL » org.josql.expressions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2007 Gary Bentley 
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may 
005:         * not use this file except in compliance with the License. 
006:         * You may obtain a copy of the License at 
007:         *    http://www.apache.org/licenses/LICENSE-2.0 
008:         *
009:         * Unless required by applicable law or agreed to in writing, software 
010:         * distributed under the License is distributed on an "AS IS" BASIS, 
011:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
012:         * See the License for the specific language governing permissions and 
013:         * limitations under the License.
014:         */
015:        package org.josql.expressions;
016:
017:        import org.josql.Query;
018:        import org.josql.QueryExecutionException;
019:
020:        /**
021:         * Represents either an <code>AND</code> expression or a <code>OR</code> expression.
022:         * Lazy evaluation is employed here such if the expression is: <code>LHS OR RHS</code>
023:         * and LHS = true then the RHS is NOT evaluated, if the expression is: <code>LHS AND RHS</code>
024:         * and LHS = false then the RHS is NOT evaluated (see {@link #isTrue(Object,Query)}).  This is important to note if you expect
025:         * side-effects to occur in the RHS (bad practice anyway so don't do it!).
026:         */
027:        public class AndOrExpression extends BinaryExpression {
028:
029:            private boolean and = false;
030:
031:            public boolean isAnd() {
032:
033:                return this .and;
034:
035:            }
036:
037:            public void setAnd(boolean v) {
038:
039:                this .and = v;
040:
041:            }
042:
043:            /**
044:             * Evaulates the expression and returns true if the expression evaulates to <code>true</code>.
045:             * <p>
046:             * <table border="1" cellpadding="3" cellspacing="0">
047:             *   <tr>
048:             *     <th>Type</th>
049:             *     <th>LHS</th>
050:             *     <th>RHS</th>
051:             *     <th>Result</th>
052:             *     <th>Notes</th>
053:             *   </tr>
054:             *   <tr>
055:             *     <td>AND</td>
056:             *     <td>true</td>
057:             *     <td>true</td>
058:             *     <td>true</td>
059:             *     <td>Both LHS and RHS are evaulated.</td>
060:             *   </tr>
061:             *   <tr>
062:             *     <td>AND</td>
063:             *     <td>true</td>
064:             *     <td>false</td>
065:             *     <td>false</td>
066:             *     <td>Both LHS and RHS are evaulated.</td>
067:             *   </tr>
068:             *   <tr>
069:             *     <td>AND</td>
070:             *     <td>false</td>
071:             *     <td>unknown or false</td>
072:             *     <td>false</td>
073:             *     <td>Only the LHS is evaulated.</td>
074:             *   </tr>
075:             *   <tr>
076:             *     <td>OR</td>
077:             *     <td>true</td>
078:             *     <td>unknown</td>
079:             *     <td>true</td>
080:             *     <td>Only the LHS is evaulated.</td>
081:             *   </tr>
082:             *   <tr>
083:             *     <td>OR</td>
084:             *     <td>false</td>
085:             *     <td>true</td>
086:             *     <td>true</td>
087:             *     <td>Both the LHS and RHS are evaulated.</td>
088:             *   </tr>
089:             *   <tr>
090:             *     <td>OR</td>
091:             *     <td>false</td>
092:             *     <td>false</td>
093:             *     <td>false</td>
094:             *     <td>Both the LHS and RHS are evaulated.</td>
095:             *   </tr>
096:             * </table>
097:             * <p>
098:             * In general what this means is that you should "left-weight" your expressions so that
099:             * the expression that returns <code>true</code> most often (or more likely to return 
100:             * <code>true</code>) should be on the LHS.
101:             *
102:             * @param o The current object to perform the expression on. 
103:             * @param q The query object.
104:             * @return <code>true</code> if the expression evaulates to <code>true</code>, <code>false</code>
105:             *         otherwise.
106:             * @throws QueryExecutionException If the expression cannot be evaulated.
107:             */
108:            public boolean isTrue(Object o, Query q)
109:                    throws QueryExecutionException {
110:
111:                // Execute left first.
112:                boolean l = this .left.isTrue(o, q);
113:
114:                // See what our predicate is...
115:                if (this .and) {
116:
117:                    if (!l) {
118:
119:                        return false;
120:
121:                    }
122:
123:                    boolean r = this .right.isTrue(o, q);
124:
125:                    return l && r;
126:
127:                }
128:
129:                if (l) {
130:
131:                    return true;
132:
133:                }
134:
135:                boolean r = this .right.isTrue(o, q);
136:
137:                return r;
138:
139:            }
140:
141:            /**
142:             * Return a string version of this expression.
143:             * Note: any formatting of the statement (such as line breaks) will be removed.
144:             *
145:             * @return A string version of the expression.  
146:             */
147:            public String toString() {
148:
149:                String pred = " OR ";
150:
151:                if (this .and) {
152:
153:                    pred = " AND ";
154:
155:                }
156:
157:                if (this .isBracketed()) {
158:
159:                    return "(" + this .left.toString() + pred
160:                            + this .right.toString() + ")";
161:
162:                }
163:
164:                return this.left.toString() + pred + this.right.toString();
165:
166:            }
167:
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.