Source Code Cross Referenced for IntegerFactory.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 IntegerFactory implements  EvaluatorFactory {
029:
030:            private static final long serialVersionUID = 400L;
031:            private static EvaluatorFactory INSTANCE = new IntegerFactory();
032:
033:            private IntegerFactory() {
034:
035:            }
036:
037:            public static EvaluatorFactory getInstance() {
038:                if (IntegerFactory.INSTANCE == null) {
039:                    IntegerFactory.INSTANCE = new IntegerFactory();
040:                }
041:                return IntegerFactory.INSTANCE;
042:            }
043:
044:            public Evaluator getEvaluator(final Operator operator) {
045:                if (operator == Operator.EQUAL) {
046:                    return IntegerEqualEvaluator.INSTANCE;
047:                } else if (operator == Operator.NOT_EQUAL) {
048:                    return IntegerNotEqualEvaluator.INSTANCE;
049:                } else if (operator == Operator.LESS) {
050:                    return IntegerLessEvaluator.INSTANCE;
051:                } else if (operator == Operator.LESS_OR_EQUAL) {
052:                    return IntegerLessOrEqualEvaluator.INSTANCE;
053:                } else if (operator == Operator.GREATER) {
054:                    return IntegerGreaterEvaluator.INSTANCE;
055:                } else if (operator == Operator.GREATER_OR_EQUAL) {
056:                    return IntegerGreaterOrEqualEvaluator.INSTANCE;
057:                } else if (operator == Operator.MEMBEROF) {
058:                    return IntegerMemberOfEvaluator.INSTANCE;
059:                } else if (operator == Operator.NOTMEMBEROF) {
060:                    return IntegerNotMemberOfEvaluator.INSTANCE;
061:                } else {
062:                    throw new RuntimeException("Operator '" + operator
063:                            + "' does not exist for IntegerEvaluator");
064:                }
065:            }
066:
067:            static class IntegerEqualEvaluator extends BaseEvaluator {
068:                /**
069:                 * 
070:                 */
071:                private static final long serialVersionUID = 400L;
072:                public final static Evaluator INSTANCE = new IntegerEqualEvaluator();
073:
074:                private IntegerEqualEvaluator() {
075:                    super (ValueType.PINTEGER_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.getIntValue(workingMemory, object1) == object2
088:                            .getIntValue();
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().getIntValue(
102:                            workingMemory, left) == ((LongVariableContextEntry) context).right;
103:                }
104:
105:                public boolean evaluateCachedLeft(
106:                        InternalWorkingMemory workingMemory,
107:                        final VariableContextEntry context, final Object object2) {
108:                    if (context.extractor.isNullValue(workingMemory, object2)) {
109:                        return context.isLeftNull();
110:                    } else if (context.isLeftNull()) {
111:                        return false;
112:                    }
113:
114:                    return context.extractor
115:                            .getIntValue(workingMemory, object2) == ((LongVariableContextEntry) context).left;
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.getIntValue(workingMemory, object1) == extractor2
128:                            .getIntValue(workingMemory, object2);
129:                }
130:
131:                public String toString() {
132:                    return "Integer ==";
133:                }
134:
135:            }
136:
137:            static class IntegerNotEqualEvaluator extends BaseEvaluator {
138:                /**
139:                 * 
140:                 */
141:                private static final long serialVersionUID = 400L;
142:                public final static Evaluator INSTANCE = new IntegerNotEqualEvaluator();
143:
144:                private IntegerNotEqualEvaluator() {
145:                    super (ValueType.PINTEGER_TYPE, Operator.NOT_EQUAL);
146:                }
147:
148:                public boolean evaluate(InternalWorkingMemory workingMemory,
149:                        final Extractor extractor, final Object object1,
150:                        final FieldValue object2) {
151:                    if (extractor.isNullValue(workingMemory, object1)) {
152:                        return !object2.isNull();
153:                    } else if (object2.isNull()) {
154:                        return true;
155:                    }
156:
157:                    return extractor.getIntValue(workingMemory, object1) != object2
158:                            .getIntValue();
159:                }
160:
161:                public boolean evaluateCachedRight(
162:                        InternalWorkingMemory workingMemory,
163:                        final VariableContextEntry context, final Object left) {
164:                    if (context.declaration.getExtractor().isNullValue(
165:                            workingMemory, left)) {
166:                        return !context.isRightNull();
167:                    } else if (context.isRightNull()) {
168:                        return true;
169:                    }
170:
171:                    return context.declaration.getExtractor().getIntValue(
172:                            workingMemory, left) != ((LongVariableContextEntry) context).right;
173:                }
174:
175:                public boolean evaluateCachedLeft(
176:                        InternalWorkingMemory workingMemory,
177:                        final VariableContextEntry context, final Object object2) {
178:                    if (context.extractor.isNullValue(workingMemory, object2)) {
179:                        return !context.isLeftNull();
180:                    } else if (context.isLeftNull()) {
181:                        return true;
182:                    }
183:
184:                    return context.extractor
185:                            .getIntValue(workingMemory, object2) != ((LongVariableContextEntry) context).left;
186:                }
187:
188:                public boolean evaluate(InternalWorkingMemory workingMemory,
189:                        final Extractor extractor1, final Object object1,
190:                        final Extractor extractor2, final Object object2) {
191:                    if (extractor1.isNullValue(workingMemory, object1)) {
192:                        return !extractor2.isNullValue(workingMemory, object2);
193:                    } else if (extractor2.isNullValue(workingMemory, object2)) {
194:                        return true;
195:                    }
196:
197:                    return extractor1.getIntValue(workingMemory, object1) != extractor2
198:                            .getIntValue(workingMemory, object2);
199:                }
200:
201:                public String toString() {
202:                    return "Integer !=";
203:                }
204:            }
205:
206:            static class IntegerLessEvaluator extends BaseEvaluator {
207:                /**
208:                 * 
209:                 */
210:                private static final long serialVersionUID = 400L;
211:                public final static Evaluator INSTANCE = new IntegerLessEvaluator();
212:
213:                private IntegerLessEvaluator() {
214:                    super (ValueType.PINTEGER_TYPE, Operator.LESS);
215:                }
216:
217:                public boolean evaluate(InternalWorkingMemory workingMemory,
218:                        final Extractor extractor, final Object object1,
219:                        final FieldValue object2) {
220:                    if (extractor.isNullValue(workingMemory, object1)) {
221:                        return false;
222:                    }
223:                    return extractor.getIntValue(workingMemory, object1) < object2
224:                            .getIntValue();
225:                }
226:
227:                public boolean evaluateCachedRight(
228:                        InternalWorkingMemory workingMemory,
229:                        final VariableContextEntry context, final Object left) {
230:                    if (context.rightNull) {
231:                        return false;
232:                    }
233:                    return ((LongVariableContextEntry) context).right < context.declaration
234:                            .getExtractor().getIntValue(workingMemory, left);
235:                }
236:
237:                public boolean evaluateCachedLeft(
238:                        InternalWorkingMemory workingMemory,
239:                        final VariableContextEntry context, final Object right) {
240:                    if (context.extractor.isNullValue(workingMemory, right)) {
241:                        return false;
242:                    }
243:                    return context.extractor.getIntValue(workingMemory, right) < ((LongVariableContextEntry) context).left;
244:                }
245:
246:                public boolean evaluate(InternalWorkingMemory workingMemory,
247:                        final Extractor extractor1, final Object object1,
248:                        final Extractor extractor2, final Object object2) {
249:                    if (extractor1.isNullValue(workingMemory, object1)) {
250:                        return false;
251:                    }
252:                    return extractor1.getIntValue(workingMemory, object1) < extractor2
253:                            .getIntValue(workingMemory, object2);
254:                }
255:
256:                public String toString() {
257:                    return "Integer <";
258:                }
259:            }
260:
261:            static class IntegerLessOrEqualEvaluator extends BaseEvaluator {
262:                /**
263:                 * 
264:                 */
265:                private static final long serialVersionUID = 400L;
266:                public final static Evaluator INSTANCE = new IntegerLessOrEqualEvaluator();
267:
268:                private IntegerLessOrEqualEvaluator() {
269:                    super (ValueType.PINTEGER_TYPE, Operator.LESS_OR_EQUAL);
270:                }
271:
272:                public boolean evaluate(InternalWorkingMemory workingMemory,
273:                        final Extractor extractor, final Object object1,
274:                        final FieldValue object2) {
275:                    if (extractor.isNullValue(workingMemory, object1)) {
276:                        return false;
277:                    }
278:                    return extractor.getIntValue(workingMemory, object1) <= object2
279:                            .getIntValue();
280:                }
281:
282:                public boolean evaluateCachedRight(
283:                        InternalWorkingMemory workingMemory,
284:                        final VariableContextEntry context, final Object left) {
285:                    if (context.rightNull) {
286:                        return false;
287:                    }
288:                    return ((LongVariableContextEntry) context).right <= context.declaration
289:                            .getExtractor().getIntValue(workingMemory, left);
290:                }
291:
292:                public boolean evaluateCachedLeft(
293:                        InternalWorkingMemory workingMemory,
294:                        final VariableContextEntry context, final Object right) {
295:                    if (context.extractor.isNullValue(workingMemory, right)) {
296:                        return false;
297:                    }
298:                    return context.extractor.getIntValue(workingMemory, right) <= ((LongVariableContextEntry) context).left;
299:                }
300:
301:                public boolean evaluate(InternalWorkingMemory workingMemory,
302:                        final Extractor extractor1, final Object object1,
303:                        final Extractor extractor2, final Object object2) {
304:                    if (extractor1.isNullValue(workingMemory, object1)) {
305:                        return false;
306:                    }
307:                    return extractor1.getIntValue(workingMemory, object1) <= extractor2
308:                            .getIntValue(workingMemory, object2);
309:                }
310:
311:                public String toString() {
312:                    return "Integer <=";
313:                }
314:            }
315:
316:            static class IntegerGreaterEvaluator extends BaseEvaluator {
317:                /**
318:                 * 
319:                 */
320:                private static final long serialVersionUID = 400L;
321:                public final static Evaluator INSTANCE = new IntegerGreaterEvaluator();
322:
323:                private IntegerGreaterEvaluator() {
324:                    super (ValueType.PINTEGER_TYPE, Operator.GREATER);
325:                }
326:
327:                public boolean evaluate(InternalWorkingMemory workingMemory,
328:                        final Extractor extractor, final Object object1,
329:                        final FieldValue object2) {
330:                    if (extractor.isNullValue(workingMemory, object1)) {
331:                        return false;
332:                    }
333:                    return extractor.getIntValue(workingMemory, object1) > object2
334:                            .getIntValue();
335:                }
336:
337:                public boolean evaluateCachedRight(
338:                        InternalWorkingMemory workingMemory,
339:                        final VariableContextEntry context, final Object left) {
340:                    if (context.rightNull) {
341:                        return false;
342:                    }
343:                    return ((LongVariableContextEntry) context).right > context.declaration
344:                            .getExtractor().getIntValue(workingMemory, left);
345:                }
346:
347:                public boolean evaluateCachedLeft(
348:                        InternalWorkingMemory workingMemory,
349:                        final VariableContextEntry context, final Object right) {
350:                    if (context.extractor.isNullValue(workingMemory, right)) {
351:                        return false;
352:                    }
353:                    return context.extractor.getIntValue(workingMemory, right) > ((LongVariableContextEntry) context).left;
354:                }
355:
356:                public boolean evaluate(InternalWorkingMemory workingMemory,
357:                        final Extractor extractor1, final Object object1,
358:                        final Extractor extractor2, final Object object2) {
359:                    if (extractor1.isNullValue(workingMemory, object1)) {
360:                        return false;
361:                    }
362:                    return extractor1.getIntValue(workingMemory, object1) > extractor2
363:                            .getIntValue(workingMemory, object2);
364:                }
365:
366:                public String toString() {
367:                    return "Integer >";
368:                }
369:            }
370:
371:            static class IntegerGreaterOrEqualEvaluator extends BaseEvaluator {
372:                /**
373:                 * 
374:                 */
375:                private static final long serialVersionUID = 400L;
376:                private final static Evaluator INSTANCE = new IntegerGreaterOrEqualEvaluator();
377:
378:                private IntegerGreaterOrEqualEvaluator() {
379:                    super (ValueType.PINTEGER_TYPE, Operator.GREATER_OR_EQUAL);
380:                }
381:
382:                public boolean evaluate(InternalWorkingMemory workingMemory,
383:                        final Extractor extractor, final Object object1,
384:                        final FieldValue object2) {
385:                    if (extractor.isNullValue(workingMemory, object1)) {
386:                        return false;
387:                    }
388:                    return extractor.getIntValue(workingMemory, object1) >= object2
389:                            .getIntValue();
390:                }
391:
392:                public boolean evaluateCachedRight(
393:                        InternalWorkingMemory workingMemory,
394:                        final VariableContextEntry context, final Object left) {
395:                    if (context.rightNull) {
396:                        return false;
397:                    }
398:                    return ((LongVariableContextEntry) context).right >= context.declaration
399:                            .getExtractor().getIntValue(workingMemory, left);
400:                }
401:
402:                public boolean evaluateCachedLeft(
403:                        InternalWorkingMemory workingMemory,
404:                        final VariableContextEntry context, final Object right) {
405:                    if (context.extractor.isNullValue(workingMemory, right)) {
406:                        return false;
407:                    }
408:                    return context.extractor.getIntValue(workingMemory, right) >= ((LongVariableContextEntry) context).left;
409:                }
410:
411:                public boolean evaluate(InternalWorkingMemory workingMemory,
412:                        final Extractor extractor1, final Object object1,
413:                        final Extractor extractor2, final Object object2) {
414:                    if (extractor1.isNullValue(workingMemory, object1)) {
415:                        return false;
416:                    }
417:                    return extractor1.getIntValue(workingMemory, object1) >= extractor2
418:                            .getIntValue(workingMemory, object2);
419:                }
420:
421:                public String toString() {
422:                    return "Integer >=";
423:                }
424:            }
425:
426:            static class IntegerMemberOfEvaluator extends BaseMemberOfEvaluator {
427:
428:                private static final long serialVersionUID = 400L;
429:                public final static Evaluator INSTANCE = new IntegerMemberOfEvaluator();
430:
431:                private IntegerMemberOfEvaluator() {
432:                    super (ValueType.PINTEGER_TYPE, Operator.MEMBEROF);
433:                }
434:
435:                public String toString() {
436:                    return "Integer memberOf";
437:                }
438:            }
439:
440:            static class IntegerNotMemberOfEvaluator extends
441:                    BaseNotMemberOfEvaluator {
442:
443:                private static final long serialVersionUID = 400L;
444:                public final static Evaluator INSTANCE = new IntegerNotMemberOfEvaluator();
445:
446:                private IntegerNotMemberOfEvaluator() {
447:                    super (ValueType.PINTEGER_TYPE, Operator.NOTMEMBEROF);
448:                }
449:
450:                public String toString() {
451:                    return "Integer not memberOf";
452:                }
453:            }
454:
455:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.