Source Code Cross Referenced for LongFactory.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » base » evaluators » 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 » drolls Rule Engine » org.drools.base.evaluators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.base.evaluators;
002:
003:        /*
004:         * Copyright 2005 JBoss Inc
005:         * 
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import org.drools.base.BaseEvaluator;
020:        import org.drools.base.ValueType;
021:        import org.drools.common.InternalWorkingMemory;
022:        import org.drools.rule.VariableRestriction.LongVariableContextEntry;
023:        import org.drools.rule.VariableRestriction.VariableContextEntry;
024:        import org.drools.spi.Evaluator;
025:        import org.drools.spi.Extractor;
026:        import org.drools.spi.FieldValue;
027:
028:        public class LongFactory implements  EvaluatorFactory {
029:
030:            private static final long serialVersionUID = 400L;
031:            private static EvaluatorFactory INSTANCE = new LongFactory();
032:
033:            private LongFactory() {
034:
035:            }
036:
037:            public static EvaluatorFactory getInstance() {
038:                if (LongFactory.INSTANCE == null) {
039:                    LongFactory.INSTANCE = new LongFactory();
040:                }
041:                return LongFactory.INSTANCE;
042:            }
043:
044:            public Evaluator getEvaluator(final Operator operator) {
045:                if (operator == Operator.EQUAL) {
046:                    return LongEqualEvaluator.INSTANCE;
047:                } else if (operator == Operator.NOT_EQUAL) {
048:                    return LongNotEqualEvaluator.INSTANCE;
049:                } else if (operator == Operator.LESS) {
050:                    return LongLessEvaluator.INSTANCE;
051:                } else if (operator == Operator.LESS_OR_EQUAL) {
052:                    return LongLessOrEqualEvaluator.INSTANCE;
053:                } else if (operator == Operator.GREATER) {
054:                    return LongGreaterEvaluator.INSTANCE;
055:                } else if (operator == Operator.GREATER_OR_EQUAL) {
056:                    return LongGreaterOrEqualEvaluator.INSTANCE;
057:                } else if (operator == Operator.MEMBEROF) {
058:                    return LongMemberOfEvaluator.INSTANCE;
059:                } else if (operator == Operator.NOTMEMBEROF) {
060:                    return LongNotMemberOfEvaluator.INSTANCE;
061:                } else {
062:                    throw new RuntimeException("Operator '" + operator
063:                            + "' does not exist for LongEvaluator");
064:                }
065:            }
066:
067:            static class LongEqualEvaluator extends BaseEvaluator {
068:                /**
069:                 * 
070:                 */
071:                private static final long serialVersionUID = 400L;
072:                public final static Evaluator INSTANCE = new LongEqualEvaluator();
073:
074:                private LongEqualEvaluator() {
075:                    super (ValueType.PLONG_TYPE, Operator.EQUAL);
076:                }
077:
078:                public boolean evaluate(InternalWorkingMemory workingMemory,
079:                        final Extractor extractor, final Object object1,
080:                        final FieldValue object2) {
081:                    if (extractor.isNullValue(workingMemory, object1)) {
082:                        return object2.isNull();
083:                    } else if (object2.isNull()) {
084:                        return false;
085:                    }
086:
087:                    return extractor.getLongValue(workingMemory, object1) == object2
088:                            .getLongValue();
089:                }
090:
091:                public boolean evaluateCachedRight(
092:                        InternalWorkingMemory workingMemory,
093:                        final VariableContextEntry context, final Object left) {
094:                    if (context.declaration.getExtractor().isNullValue(
095:                            workingMemory, left)) {
096:                        return context.isRightNull();
097:                    } else if (context.isRightNull()) {
098:                        return false;
099:                    }
100:
101:                    return context.declaration.getExtractor().getLongValue(
102:                            workingMemory, left) == ((LongVariableContextEntry) context).right;
103:                }
104:
105:                public boolean evaluateCachedLeft(
106:                        InternalWorkingMemory workingMemory,
107:                        final VariableContextEntry context, final Object right) {
108:                    if (context.extractor.isNullValue(workingMemory, right)) {
109:                        return context.isLeftNull();
110:                    } else if (context.isLeftNull()) {
111:                        return false;
112:                    }
113:
114:                    return ((LongVariableContextEntry) context).left == context.extractor
115:                            .getLongValue(workingMemory, right);
116:                }
117:
118:                public boolean evaluate(InternalWorkingMemory workingMemory,
119:                        final Extractor extractor1, final Object object1,
120:                        final Extractor extractor2, final Object object2) {
121:                    if (extractor1.isNullValue(workingMemory, object1)) {
122:                        return extractor2.isNullValue(workingMemory, object2);
123:                    } else if (extractor2.isNullValue(workingMemory, object2)) {
124:                        return false;
125:                    }
126:
127:                    return extractor1.getLongValue(workingMemory, object1) == extractor2
128:                            .getLongValue(workingMemory, object2);
129:                }
130:
131:                public String toString() {
132:                    return "Long ==";
133:                }
134:            }
135:
136:            static class LongNotEqualEvaluator extends BaseEvaluator {
137:                /**
138:                 * 
139:                 */
140:                private static final long serialVersionUID = 400L;
141:                public final static Evaluator INSTANCE = new LongNotEqualEvaluator();
142:
143:                private LongNotEqualEvaluator() {
144:                    super (ValueType.PLONG_TYPE, Operator.NOT_EQUAL);
145:                }
146:
147:                public boolean evaluate(InternalWorkingMemory workingMemory,
148:                        final Extractor extractor, final Object object1,
149:                        final FieldValue object2) {
150:                    if (extractor.isNullValue(workingMemory, object1)) {
151:                        return !object2.isNull();
152:                    } else if (object2.isNull()) {
153:                        return true;
154:                    }
155:
156:                    return extractor.getLongValue(workingMemory, object1) != object2
157:                            .getLongValue();
158:                }
159:
160:                public boolean evaluateCachedRight(
161:                        InternalWorkingMemory workingMemory,
162:                        final VariableContextEntry context, final Object left) {
163:                    if (context.declaration.getExtractor().isNullValue(
164:                            workingMemory, left)) {
165:                        return !context.isRightNull();
166:                    } else if (context.isRightNull()) {
167:                        return true;
168:                    }
169:
170:                    return context.declaration.getExtractor().getLongValue(
171:                            workingMemory, left) != ((LongVariableContextEntry) context).right;
172:                }
173:
174:                public boolean evaluateCachedLeft(
175:                        InternalWorkingMemory workingMemory,
176:                        final VariableContextEntry context, final Object right) {
177:                    if (context.extractor.isNullValue(workingMemory, right)) {
178:                        return !context.isLeftNull();
179:                    } else if (context.isLeftNull()) {
180:                        return true;
181:                    }
182:
183:                    return ((LongVariableContextEntry) context).left != context.extractor
184:                            .getLongValue(workingMemory, right);
185:                }
186:
187:                public boolean evaluate(InternalWorkingMemory workingMemory,
188:                        final Extractor extractor1, final Object object1,
189:                        final Extractor extractor2, final Object object2) {
190:                    if (extractor1.isNullValue(workingMemory, object1)) {
191:                        return !extractor2.isNullValue(workingMemory, object2);
192:                    } else if (extractor2.isNullValue(workingMemory, object2)) {
193:                        return true;
194:                    }
195:
196:                    return extractor1.getLongValue(workingMemory, object1) != extractor2
197:                            .getLongValue(workingMemory, object2);
198:                }
199:
200:                public String toString() {
201:                    return "Long !=";
202:                }
203:            }
204:
205:            static class LongLessEvaluator extends BaseEvaluator {
206:                /**
207:                 * 
208:                 */
209:                private static final long serialVersionUID = 400L;
210:                public final static Evaluator INSTANCE = new LongLessEvaluator();
211:
212:                private LongLessEvaluator() {
213:                    super (ValueType.PLONG_TYPE, Operator.LESS);
214:                }
215:
216:                public boolean evaluate(InternalWorkingMemory workingMemory,
217:                        final Extractor extractor, final Object object1,
218:                        final FieldValue object2) {
219:                    if (extractor.isNullValue(workingMemory, object1)) {
220:                        return false;
221:                    }
222:                    return extractor.getLongValue(workingMemory, object1) < object2
223:                            .getLongValue();
224:                }
225:
226:                public boolean evaluateCachedRight(
227:                        InternalWorkingMemory workingMemory,
228:                        final VariableContextEntry context, final Object left) {
229:                    if (context.rightNull) {
230:                        return false;
231:                    }
232:                    return ((LongVariableContextEntry) context).right < context.declaration
233:                            .getExtractor().getLongValue(workingMemory, left);
234:                }
235:
236:                public boolean evaluateCachedLeft(
237:                        InternalWorkingMemory workingMemory,
238:                        final VariableContextEntry context, final Object right) {
239:                    if (context.extractor.isNullValue(workingMemory, right)) {
240:                        return false;
241:                    }
242:                    return context.extractor.getLongValue(workingMemory, right) < ((LongVariableContextEntry) context).left;
243:                }
244:
245:                public boolean evaluate(InternalWorkingMemory workingMemory,
246:                        final Extractor extractor1, final Object object1,
247:                        final Extractor extractor2, final Object object2) {
248:                    if (extractor1.isNullValue(workingMemory, object1)) {
249:                        return false;
250:                    }
251:                    return extractor1.getLongValue(workingMemory, object1) < extractor2
252:                            .getLongValue(workingMemory, object2);
253:                }
254:
255:                public String toString() {
256:                    return "Long <";
257:                }
258:            }
259:
260:            static class LongLessOrEqualEvaluator extends BaseEvaluator {
261:                /**
262:                 * 
263:                 */
264:                private static final long serialVersionUID = 400L;
265:                public final static Evaluator INSTANCE = new LongLessOrEqualEvaluator();
266:
267:                private LongLessOrEqualEvaluator() {
268:                    super (ValueType.PLONG_TYPE, Operator.LESS_OR_EQUAL);
269:                }
270:
271:                public boolean evaluate(InternalWorkingMemory workingMemory,
272:                        final Extractor extractor, final Object object1,
273:                        final FieldValue object2) {
274:                    if (extractor.isNullValue(workingMemory, object1)) {
275:                        return false;
276:                    }
277:                    return extractor.getLongValue(workingMemory, object1) <= object2
278:                            .getLongValue();
279:                }
280:
281:                public boolean evaluateCachedRight(
282:                        InternalWorkingMemory workingMemory,
283:                        final VariableContextEntry context, final Object left) {
284:                    if (context.rightNull) {
285:                        return false;
286:                    }
287:                    return ((LongVariableContextEntry) context).right <= context.declaration
288:                            .getExtractor().getLongValue(workingMemory, left);
289:                }
290:
291:                public boolean evaluateCachedLeft(
292:                        InternalWorkingMemory workingMemory,
293:                        final VariableContextEntry context, final Object right) {
294:                    if (context.extractor.isNullValue(workingMemory, right)) {
295:                        return false;
296:                    }
297:                    return context.extractor.getLongValue(workingMemory, right) <= ((LongVariableContextEntry) context).left;
298:                }
299:
300:                public boolean evaluate(InternalWorkingMemory workingMemory,
301:                        final Extractor extractor1, final Object object1,
302:                        final Extractor extractor2, final Object object2) {
303:                    if (extractor1.isNullValue(workingMemory, object1)) {
304:                        return false;
305:                    }
306:                    return extractor1.getLongValue(workingMemory, object1) <= extractor2
307:                            .getLongValue(workingMemory, object2);
308:                }
309:
310:                public String toString() {
311:                    return "Long <=";
312:                }
313:            }
314:
315:            static class LongGreaterEvaluator extends BaseEvaluator {
316:                /**
317:                 * 
318:                 */
319:                private static final long serialVersionUID = 400L;
320:                public final static Evaluator INSTANCE = new LongGreaterEvaluator();
321:
322:                private LongGreaterEvaluator() {
323:                    super (ValueType.PLONG_TYPE, Operator.GREATER);
324:                }
325:
326:                public boolean evaluate(InternalWorkingMemory workingMemory,
327:                        final Extractor extractor, final Object object1,
328:                        final FieldValue object2) {
329:                    if (extractor.isNullValue(workingMemory, object1)) {
330:                        return false;
331:                    }
332:                    return extractor.getLongValue(workingMemory, object1) > object2
333:                            .getLongValue();
334:                }
335:
336:                public boolean evaluateCachedRight(
337:                        InternalWorkingMemory workingMemory,
338:                        final VariableContextEntry context, final Object left) {
339:                    if (context.rightNull) {
340:                        return false;
341:                    }
342:                    return ((LongVariableContextEntry) context).right > context.declaration
343:                            .getExtractor().getLongValue(workingMemory, left);
344:                }
345:
346:                public boolean evaluateCachedLeft(
347:                        InternalWorkingMemory workingMemory,
348:                        final VariableContextEntry context, final Object right) {
349:                    if (context.extractor.isNullValue(workingMemory, right)) {
350:                        return false;
351:                    }
352:                    return context.extractor.getLongValue(workingMemory, right) > ((LongVariableContextEntry) context).left;
353:                }
354:
355:                public boolean evaluate(InternalWorkingMemory workingMemory,
356:                        final Extractor extractor1, final Object object1,
357:                        final Extractor extractor2, final Object object2) {
358:                    if (extractor1.isNullValue(workingMemory, object1)) {
359:                        return false;
360:                    }
361:                    return extractor1.getLongValue(workingMemory, object1) > extractor2
362:                            .getLongValue(workingMemory, object2);
363:                }
364:
365:                public String toString() {
366:                    return "Long >";
367:                }
368:            }
369:
370:            static class LongGreaterOrEqualEvaluator extends BaseEvaluator {
371:                /**
372:                 * 
373:                 */
374:                private static final long serialVersionUID = 400L;
375:                private final static Evaluator INSTANCE = new LongGreaterOrEqualEvaluator();
376:
377:                private LongGreaterOrEqualEvaluator() {
378:                    super (ValueType.PLONG_TYPE, Operator.GREATER_OR_EQUAL);
379:                }
380:
381:                public boolean evaluate(InternalWorkingMemory workingMemory,
382:                        final Extractor extractor, final Object object1,
383:                        final FieldValue object2) {
384:                    if (extractor.isNullValue(workingMemory, object1)) {
385:                        return false;
386:                    }
387:                    return extractor.getLongValue(workingMemory, object1) >= object2
388:                            .getLongValue();
389:                }
390:
391:                public boolean evaluateCachedRight(
392:                        InternalWorkingMemory workingMemory,
393:                        final VariableContextEntry context, final Object left) {
394:                    if (context.rightNull) {
395:                        return false;
396:                    }
397:                    return ((LongVariableContextEntry) context).right >= context.declaration
398:                            .getExtractor().getLongValue(workingMemory, left);
399:                }
400:
401:                public boolean evaluateCachedLeft(
402:                        InternalWorkingMemory workingMemory,
403:                        final VariableContextEntry context, final Object right) {
404:                    if (context.extractor.isNullValue(workingMemory, right)) {
405:                        return false;
406:                    }
407:                    return context.extractor.getLongValue(workingMemory, right) >= ((LongVariableContextEntry) context).left;
408:                }
409:
410:                public boolean evaluate(InternalWorkingMemory workingMemory,
411:                        final Extractor extractor1, final Object object1,
412:                        final Extractor extractor2, final Object object2) {
413:                    if (extractor1.isNullValue(workingMemory, object1)) {
414:                        return false;
415:                    }
416:                    return extractor1.getLongValue(workingMemory, object1) >= extractor2
417:                            .getLongValue(workingMemory, object2);
418:                }
419:
420:                public String toString() {
421:                    return "Long >=";
422:                }
423:            }
424:
425:            static class LongMemberOfEvaluator extends BaseMemberOfEvaluator {
426:
427:                private static final long serialVersionUID = 400L;
428:                public final static Evaluator INSTANCE = new LongMemberOfEvaluator();
429:
430:                private LongMemberOfEvaluator() {
431:                    super (ValueType.PLONG_TYPE, Operator.MEMBEROF);
432:                }
433:
434:                public String toString() {
435:                    return "Long memberOf";
436:                }
437:            }
438:
439:            static class LongNotMemberOfEvaluator extends
440:                    BaseNotMemberOfEvaluator {
441:
442:                private static final long serialVersionUID = 400L;
443:                public final static Evaluator INSTANCE = new LongNotMemberOfEvaluator();
444:
445:                private LongNotMemberOfEvaluator() {
446:                    super (ValueType.PLONG_TYPE, Operator.NOTMEMBEROF);
447:                }
448:
449:                public String toString() {
450:                    return "Long not memberOf";
451:                }
452:            }
453:
454:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.