Source Code Cross Referenced for RelationalOperationEval.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » record » formula » eval » 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 » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.record.formula.eval 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        /*
018:         * Created on May 10, 2005
019:         *
020:         */
021:        package org.apache.poi.hssf.record.formula.eval;
022:
023:        /**
024:         * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
025:         *
026:         */
027:        public abstract class RelationalOperationEval implements  OperationEval {
028:
029:            protected class RelationalValues {
030:                public Double[] ds = new Double[2];
031:                public Boolean[] bs = new Boolean[2];
032:                public String[] ss = new String[3];
033:                public ErrorEval ee = null;
034:            }
035:
036:            /*
037:             * This is a description of how the relational operators apply in MS Excel.
038:             * Use this as a guideline when testing/implementing the evaluate methods 
039:             * for the relational operators Evals.
040:             * 
041:             * Bool > any number. ALWAYS
042:             * Bool > any string. ALWAYS
043:             * Bool.TRUE > Bool.FALSE
044:             * 
045:             * String > any number. ALWAYS
046:             * String > Blank. ALWAYS
047:             * String are sorted dictionary wise
048:             * 
049:             * Blank == 0 (numeric)
050:             */
051:            public RelationalValues doEvaluate(Eval[] operands, int srcRow,
052:                    short srcCol) {
053:                RelationalValues retval = new RelationalValues();
054:
055:                switch (operands.length) {
056:                default:
057:                    retval.ee = ErrorEval.VALUE_INVALID;
058:                    break;
059:                case 2:
060:                    internalDoEvaluate(operands, srcRow, srcCol, retval, 0);
061:                    internalDoEvaluate(operands, srcRow, srcCol, retval, 1);
062:                } // end switch
063:                return retval;
064:            }
065:
066:            /**
067:             * convenience method to avoid code duplication for multiple operands
068:             * @param operands
069:             * @param srcRow
070:             * @param srcCol
071:             * @param retval
072:             * @param index
073:             */
074:            private void internalDoEvaluate(Eval[] operands, int srcRow,
075:                    short srcCol, RelationalValues retval, int index) {
076:                if (operands[index] instanceof  BoolEval) {
077:                    BoolEval be = (BoolEval) operands[index];
078:                    retval.bs[index] = Boolean.valueOf(be.getBooleanValue());
079:                } else if (operands[index] instanceof  NumericValueEval) {
080:                    NumericValueEval ne = (NumericValueEval) operands[index];
081:                    retval.ds[index] = new Double(ne.getNumberValue());
082:                } else if (operands[index] instanceof  StringValueEval) {
083:                    StringValueEval se = (StringValueEval) operands[index];
084:                    retval.ss[index] = se.getStringValue();
085:                } else if (operands[index] instanceof  RefEval) {
086:                    RefEval re = (RefEval) operands[index];
087:                    ValueEval ve = re.getInnerValueEval();
088:                    if (ve instanceof  BoolEval) {
089:                        BoolEval be = (BoolEval) ve;
090:                        retval.bs[index] = Boolean
091:                                .valueOf(be.getBooleanValue());
092:                    } else if (ve instanceof  BlankEval) {
093:                        retval.ds[index] = new Double(0);
094:                    } else if (ve instanceof  NumericValueEval) {
095:                        NumericValueEval ne = (NumericValueEval) ve;
096:                        retval.ds[index] = new Double(ne.getNumberValue());
097:                    } else if (ve instanceof  StringValueEval) {
098:                        StringValueEval se = (StringValueEval) ve;
099:                        retval.ss[index] = se.getStringValue();
100:                    }
101:                } else if (operands[index] instanceof  AreaEval) {
102:                    AreaEval ae = (AreaEval) operands[index];
103:                    if (ae.isRow()) {
104:                        if (ae.containsColumn(srcCol)) {
105:                            ValueEval ve = ae.getValueAt(ae.getFirstRow(),
106:                                    srcCol);
107:                            if (ve instanceof  BoolEval) {
108:                                BoolEval be = (BoolEval) ve;
109:                                retval.bs[index] = Boolean.valueOf(be
110:                                        .getBooleanValue());
111:                            } else if (ve instanceof  BlankEval) {
112:                                retval.ds[index] = new Double(0);
113:                            } else if (ve instanceof  NumericValueEval) {
114:                                NumericValueEval ne = (NumericValueEval) ve;
115:                                retval.ds[index] = new Double(ne
116:                                        .getNumberValue());
117:                            } else if (ve instanceof  StringValueEval) {
118:                                StringValueEval se = (StringValueEval) ve;
119:                                retval.ss[index] = se.getStringValue();
120:                            } else {
121:                                retval.ee = ErrorEval.VALUE_INVALID;
122:                            }
123:                        } else {
124:                            retval.ee = ErrorEval.VALUE_INVALID;
125:                        }
126:                    } else if (ae.isColumn()) {
127:                        if (ae.containsRow(srcRow)) {
128:                            ValueEval ve = ae.getValueAt(srcRow, ae
129:                                    .getFirstColumn());
130:                            if (ve instanceof  BoolEval) {
131:                                BoolEval be = (BoolEval) ve;
132:                                retval.bs[index] = Boolean.valueOf(be
133:                                        .getBooleanValue());
134:                            } else if (ve instanceof  BlankEval) {
135:                                retval.ds[index] = new Double(0);
136:                            } else if (ve instanceof  NumericValueEval) {
137:                                NumericValueEval ne = (NumericValueEval) ve;
138:                                retval.ds[index] = new Double(ne
139:                                        .getNumberValue());
140:                            } else if (ve instanceof  StringValueEval) {
141:                                StringValueEval se = (StringValueEval) ve;
142:                                retval.ss[index] = se.getStringValue();
143:                            } else {
144:                                retval.ee = ErrorEval.VALUE_INVALID;
145:                            }
146:                        } else {
147:                            retval.ee = ErrorEval.VALUE_INVALID;
148:                        }
149:                    } else {
150:                        retval.ee = ErrorEval.VALUE_INVALID;
151:                    }
152:                }
153:            }
154:
155:            // if both null return 0, else non null wins, else TRUE wins
156:            protected int doComparison(Boolean[] bs) {
157:                int retval = 0;
158:                if (bs[0] != null || bs[1] != null) {
159:                    retval = bs[0] != null ? bs[1] != null ? bs[0]
160:                            .booleanValue() ? bs[1].booleanValue() ? 0 : 1
161:                            : bs[1].booleanValue() ? -1 : 0 : 1
162:                            : bs[1] != null ? -1 : 0;
163:                }
164:                return retval;
165:            }
166:
167:            // if both null return 0, else non null wins, else string compare
168:            protected int doComparison(String[] ss) {
169:                int retval = 0;
170:                if (ss[0] != null || ss[1] != null) {
171:                    retval = ss[0] != null ? ss[1] != null ? ss[0]
172:                            .compareTo(ss[1]) : 1 : ss[1] != null ? -1 : 0;
173:                }
174:                return retval;
175:            }
176:
177:            // if both null return 0, else non null wins, else doublevalue compare
178:            protected int doComparison(Double[] ds) {
179:                int retval = 0;
180:                if (ds[0] != null || ds[1] != null) {
181:                    retval = ds[0] != null ? ds[1] != null ? ds[0]
182:                            .compareTo(ds[1]) : 1 : ds[1] != null ? -1 : 0;
183:                }
184:                return retval;
185:            }
186:        }
w__w_w_.j___a___v__a2__s_.c__o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.