Source Code Cross Referenced for ValueDouble.java in  » Database-DBMS » h2database » org » h2 » value » 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 » Database DBMS » h2database » org.h2.value 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (http://h2database.com/html/license.html).
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.value;
007:
008:        import java.sql.PreparedStatement;
009:        import java.sql.SQLException;
010:
011:        import org.h2.constant.ErrorCode;
012:        import org.h2.message.Message;
013:        import org.h2.util.ObjectUtils;
014:
015:        /**
016:         * Implementation of the DOUBLE data type.
017:         */
018:        public class ValueDouble extends Value {
019:            public static final int PRECISION = 17;
020:            public static final int DISPLAY_SIZE = 24; // -3.3333333333333334E-100
021:
022:            private final double value;
023:            private static final double DOUBLE_ZERO = 0.0;
024:            private static final double DOUBLE_ONE = 1.0;
025:            private static final ValueDouble ZERO = new ValueDouble(DOUBLE_ZERO);
026:            private static final ValueDouble ONE = new ValueDouble(DOUBLE_ONE);
027:
028:            private ValueDouble(double value) {
029:                this .value = value;
030:            }
031:
032:            public Value add(Value v) {
033:                ValueDouble v2 = (ValueDouble) v;
034:                return ValueDouble.get(value + v2.value);
035:            }
036:
037:            public Value subtract(Value v) {
038:                ValueDouble v2 = (ValueDouble) v;
039:                return ValueDouble.get(value - v2.value);
040:            }
041:
042:            public Value negate() {
043:                return ValueDouble.get(-value);
044:            }
045:
046:            public Value multiply(Value v) {
047:                ValueDouble v2 = (ValueDouble) v;
048:                return ValueDouble.get(value * v2.value);
049:            }
050:
051:            public Value divide(Value v) throws SQLException {
052:                ValueDouble v2 = (ValueDouble) v;
053:                if (v2.value == 0.0) {
054:                    throw Message.getSQLException(ErrorCode.DIVISION_BY_ZERO_1,
055:                            getSQL());
056:                }
057:                return ValueDouble.get(value / v2.value);
058:            }
059:
060:            public String getSQL() {
061:                return getString();
062:            }
063:
064:            public int getType() {
065:                return Value.DOUBLE;
066:            }
067:
068:            protected int compareSecure(Value o, CompareMode mode) {
069:                ValueDouble v = (ValueDouble) o;
070:                if (value == v.value) {
071:                    return 0;
072:                }
073:                return value > v.value ? 1 : -1;
074:            }
075:
076:            public int getSignum() {
077:                return value == 0 ? 0 : (value < 0 ? -1 : 1);
078:            }
079:
080:            public double getDouble() {
081:                return value;
082:            }
083:
084:            public String getString() {
085:                return String.valueOf(value);
086:            }
087:
088:            public long getPrecision() {
089:                return PRECISION;
090:            }
091:
092:            public int getScale() {
093:                // TODO value: what is the scale of a double?
094:                return 0;
095:            }
096:
097:            public int hashCode() {
098:                long hash = Double.doubleToLongBits(value);
099:                return (int) (hash ^ (hash >> 32));
100:            }
101:
102:            public Object getObject() {
103:                return ObjectUtils.getDouble(value);
104:            }
105:
106:            public void set(PreparedStatement prep, int parameterIndex)
107:                    throws SQLException {
108:                prep.setDouble(parameterIndex, value);
109:            }
110:
111:            public static ValueDouble get(double d) {
112:                if (DOUBLE_ZERO == d) {
113:                    return ZERO;
114:                } else if (DOUBLE_ONE == d) {
115:                    return ONE;
116:                }
117:                return (ValueDouble) Value.cache(new ValueDouble(d));
118:            }
119:
120:            public int getDisplaySize() {
121:                return DISPLAY_SIZE;
122:            }
123:
124:            public boolean equals(Object other) {
125:                return other instanceof  ValueDouble
126:                        && value == ((ValueDouble) other).value;
127:            }
128:
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.