Source Code Cross Referenced for ConverterUtil.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portlet » unitconverter » util » 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 » Portal » liferay portal 4.4.2 » com.liferay.portlet.unitconverter.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portlet.unitconverter.util;
022:
023:        import com.liferay.portlet.unitconverter.model.Conversion;
024:
025:        /**
026:         * <a href="ConverterUtil.java.html"><b><i>View Source</i></b></a>
027:         *
028:         * @author James Lefeu
029:         *
030:         */
031:        public class ConverterUtil {
032:
033:            public static int TEMPERATURE_CELSIUS = 1;
034:
035:            public static int TEMPERATURE_FAHRENHEIHT = 2;
036:
037:            public static Conversion getConversion(int type, int fromId,
038:                    int toId, double fromValue) {
039:                double toValue = 0;
040:
041:                if (type == 0) {
042:                    toValue = convertLength(fromId, toId, fromValue);
043:                } else if (type == 1) {
044:                    toValue = convertArea(fromId, toId, fromValue);
045:                } else if (type == 2) {
046:                    toValue = convertVolume(fromId, toId, fromValue);
047:                } else if (type == 3) {
048:                    toValue = convertMass(fromId, toId, fromValue);
049:                } else if (type == 4) {
050:                    toValue = convertTemperature(fromId, toId, fromValue);
051:                }
052:
053:                return new Conversion(type, fromId, toId, fromValue, toValue);
054:            }
055:
056:            public static double convertArea(int fromId, int toId,
057:                    double fromValue) {
058:                return (fromValue / _AREA[fromId]) * _AREA[toId];
059:            }
060:
061:            public static double convertLength(int fromId, int toId,
062:                    double fromValue) {
063:                return (fromValue / _LENGTH[fromId]) * _LENGTH[toId];
064:            }
065:
066:            public static double convertMass(int fromId, int toId,
067:                    double fromValue) {
068:                return (fromValue / _MASS[fromId]) * _MASS[toId];
069:            }
070:
071:            public static double convertTemperature(int fromId, int toId,
072:                    double fromValue) {
073:                return _fromTemperature(toId, _toTemperature(fromId, fromValue));
074:            }
075:
076:            public static double convertVolume(int fromId, int toId,
077:                    double fromValue) {
078:                return (fromValue / _VOLUME[fromId]) * _VOLUME[toId];
079:            }
080:
081:            private final static double _fromTemperature(int toId,
082:                    double fromValue) {
083:                if (toId == 0) {
084:                    return fromValue; // Kelvin
085:                } else if (toId == 1) {
086:                    return fromValue - 273.15; // Celsius
087:                } else if (toId == 2) {
088:                    return (1.8 * fromValue) - 459.67; // Fahrenheit
089:                } else if (toId == 3) {
090:                    return 1.8 * fromValue; // Rankine
091:                } else if (toId == 4) {
092:                    return .8 * (fromValue - 273.15); // Réaumure
093:                } else {
094:                    return 0;
095:                }
096:            }
097:
098:            private final static double _toTemperature(int fromId,
099:                    double fromValue) {
100:                if (fromId == 0) { // Kelvin
101:                    return fromValue;
102:                } else if (fromId == 1) { // Celsius
103:                    return fromValue + 273.15;
104:                } else if (fromId == 2) { // Fahrenheit
105:                    return .5555555555 * (fromValue + 459.67);
106:                } else if (fromId == 3) { // Rankine
107:                    return .5555555555 * fromValue;
108:                } else if (fromId == 4) {
109:                    return (1.25 * fromValue) + 273.15; // Réaumure
110:                } else {
111:                    return 0;
112:                }
113:            }
114:
115:            private final static double _AREA[] = new double[] { 1.0, // Square Kilometer
116:                    1000000.0, // Square Meter
117:                    10000000000.0, // Square Centimeter
118:                    1000000000000.0, // Square Millimeter
119:                    10763910, // Square Foot
120:                    1550003000, // Square Inch
121:                    1195990, // Square Yard
122:                    0.3861022, // Square Mile
123:                    100, // Hectare
124:                    247.1054, // Acre
125:            };
126:
127:            private final static double _LENGTH[] = new double[] { 1.0, // Meter
128:                    1000.0, // Millimeter
129:                    100.0, // Centimeter
130:                    0.001, // Kilometer
131:                    3.28084, // Foot
132:                    39.37008, // Inch
133:                    1.093613, // Yard
134:                    0.000621, // Mile
135:                    2.187227, // Cubit
136:                    4.374453, // Talent
137:                    13.12336 // Handbreath
138:            };
139:
140:            private final static double _MASS[] = new double[] { 1.0, // Kilogram
141:                    2.204623, // Pound
142:                    0.00110, // Ton
143:                    0.02939497, // Talent
144:                    1.763698, // Mina
145:                    88.18491, // Shekel
146:                    132.2774, // Pim
147:                    176.2698, // Beka
148:                    1763.698, // Gerah
149:            };
150:
151:            private final static double _VOLUME[] = new double[] { 1.0, // Liter
152:                    1000, // Cubic Centimeter
153:                    61.02374, // Cubic Inch (Liquid Measure)
154:                    1.816166, // Pint (Dry Measure)
155:                    0.004729599, // Cor (Homer)
156:                    0.009459198, // Lethek
157:                    0.04729599, // Ephah
158:                    0.141888, // Seah
159:                    0.4729599, // Omer
160:                    0.851328, // Cab
161:                    0.04402868, // Bath
162:                    0.2641721, // Hin
163:                    3.170065, // Log
164:            };
165:
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.