Source Code Cross Referenced for AbstractCompareExpression.java in  » Report » pentaho-report » org » jfree » report » function » 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 » Report » pentaho report » org.jfree.report.function 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ===========================================
003:         * JFreeReport : a free Java reporting library
004:         * ===========================================
005:         *
006:         * Project Info:  http://reporting.pentaho.org/
007:         *
008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either version 2.1 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         *
022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023:         * in the United States and other countries.]
024:         *
025:         * ------------
026:         * AbstractCompareExpression.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.function;
030:
031:        import java.math.BigDecimal;
032:
033:        /**
034:         * The base class for all expressions that compare a value read from the datarow with another value. This expression and
035:         * all subclasses have been made obsolete by the Formula-Support.
036:         * <p/>
037:         * The given field name is always used to retrieve the left hand operand of the comparison. The value supplied by the
038:         * expression implementation is always the right hand operand. 
039:         *
040:         * @author Thomas Morgner
041:         */
042:        public abstract class AbstractCompareExpression extends
043:                AbstractExpression {
044:            /**
045:             * A constant for an equals comparison.
046:             */
047:            public static final String EQUAL = "equal";
048:            /**
049:             * A constant for a not equals comparison.
050:             */
051:            public static final String NOT_EQUAL = "not-equal";
052:            /**
053:             * A constant for lower than comparison.
054:             */
055:            public static final String LOWER = "lower";
056:            /**
057:             * A constant for greater than comparison.
058:             */
059:            public static final String GREATER = "greater";
060:            /**
061:             * A constant for lower than or equal comparison.
062:             */
063:            public static final String LOWER_EQUAL = "lower-equal";
064:            /**
065:             * A constant for greater than or equal comparison.
066:             */
067:            public static final String GREATER_EQUAL = "greater-equal";
068:
069:            /**
070:             * A field holding the compare method that should be used.
071:             */
072:            private String compareMethod;
073:            /**
074:             * The name of the field that should be read.
075:             */
076:            private String field;
077:
078:            /**
079:             * The default constructor.
080:             */
081:            protected AbstractCompareExpression() {
082:            }
083:
084:            /**
085:             * Compares the value read from the data-row with the value supplied by the expression itself. If the value
086:             * is null or no comparable or cannot be compared for other reasons, this expression returns Boolean.FALSE.  
087:             *
088:             * @return Boolean.TRUE or Boolean.FALSE.
089:             */
090:            public Object getValue() {
091:                final Object o = getDataRow().get(getField());
092:                if (o instanceof  Comparable == false) {
093:                    return Boolean.FALSE;
094:                }
095:
096:                try {
097:                    final Comparable c = (Comparable) o;
098:                    final Comparable comparable = getComparable();
099:                    if (comparable == null) {
100:                        return Boolean.FALSE;
101:                    }
102:
103:                    int result;
104:                    try {
105:                        // Comparing the easy way: Both values are the same type ..
106:                        result = c.compareTo(comparable);
107:                        // this results in a class-cast exception if they are not the same type.
108:                    } catch (Exception e) {
109:                        try {
110:                            // invert it ..
111:                            // Comparing the easy way: Both values are the same type ..
112:                            result = -comparable.compareTo(c);
113:                            // this results in a class-cast exception if they are not the same type.
114:                        } catch (Exception e2) {
115:                            if (c instanceof  Number
116:                                    && comparable instanceof  Number) {
117:                                final BigDecimal bd1 = new BigDecimal(String
118:                                        .valueOf(c));
119:                                final BigDecimal bd2 = new BigDecimal(String
120:                                        .valueOf(comparable));
121:                                result = bd1.compareTo(bd2);
122:                            } else {
123:                                // not comparable ..
124:                                return Boolean.FALSE;
125:                            }
126:                        }
127:                    }
128:
129:                    final String method = getCompareMethod();
130:                    if (EQUAL.equals(method)) {
131:                        if (result == 0) {
132:                            return Boolean.TRUE;
133:                        }
134:                        return Boolean.FALSE;
135:                    }
136:                    if (NOT_EQUAL.equals(method)) {
137:                        if (result != 0) {
138:                            return Boolean.TRUE;
139:                        }
140:                        return Boolean.FALSE;
141:                    }
142:                    if (LOWER.equals(method)) {
143:                        if (result < 0) {
144:                            return Boolean.TRUE;
145:                        }
146:                        return Boolean.FALSE;
147:                    }
148:                    if (LOWER_EQUAL.equals(method)) {
149:                        if (result <= 0) {
150:                            return Boolean.TRUE;
151:                        }
152:                        return Boolean.FALSE;
153:                    }
154:                    if (GREATER.equals(method)) {
155:                        if (result > 0) {
156:                            return Boolean.TRUE;
157:                        }
158:                        return Boolean.FALSE;
159:                    }
160:                    if (GREATER_EQUAL.equals(method)) {
161:                        if (result >= 0) {
162:                            return Boolean.TRUE;
163:                        }
164:                        return Boolean.FALSE;
165:                    }
166:                } catch (Exception e) {
167:                    // ignore ...
168:                }
169:                return Boolean.FALSE;
170:            }
171:
172:            /**
173:             * Returns the name of the field from where to read the first operand.
174:             *
175:             * @return the field name.
176:             */
177:            public String getField() {
178:                return field;
179:            }
180:
181:            /**
182:             * Defines the name of the field from where to read the first operand.
183:             *
184:             * @param field the field name.
185:             */
186:            public void setField(final String field) {
187:                this .field = field;
188:            }
189:
190:            /**
191:             * Returns the compare method that should be used in the expression evaluation. Must be one of the constants declared
192:             * in this expression.
193:             *
194:             * @return the compare method.
195:             */
196:            public String getCompareMethod() {
197:                return compareMethod;
198:            }
199:
200:            /**
201:             * Defines the compare method that should be used in the expression evaluation. Must be one of the constants declared
202:             * in this expression.
203:             *
204:             * @param compareMethod the compare method.
205:             */
206:            public void setCompareMethod(final String compareMethod) {
207:                this .compareMethod = compareMethod;
208:            }
209:
210:            /**
211:             * Returns the right-hand operand used in the comparison.
212:             *
213:             * @return the right-hand operand.
214:             */
215:            protected abstract Comparable getComparable();
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.