Source Code Cross Referenced for Temperature.java in  » Science » Cougaar12_4 » org » cougaar » planning » ldm » measure » 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 » Science » Cougaar12_4 » org.cougaar.planning.ldm.measure 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:        /** Immutable implementation of Temperature.
027:         **/package org.cougaar.planning.ldm.measure;
028:
029:        public final class Temperature extends AbstractMeasure {
030:            private static final Conversion CELSIUS_TO_CELSIUS = new Conversion() {
031:                public double convert(double from) {
032:                    return from;
033:                }
034:            };
035:
036:            private static final Conversion CELSIUS_TO_FAHRENHEIT = new Conversion() {
037:                public double convert(double from) {
038:                    return (from * 1.8) + 32.0;
039:                }
040:            };
041:            private static final Conversion FAHRENHEIT_TO_CELSIUS = new Conversion() {
042:                public double convert(double from) {
043:                    return (from - 32.0) / 1.8;
044:                }
045:            };
046:
047:            // basic unit is Celsius
048:            private double theValue;
049:
050:            // private constructor
051:            private Temperature(double v) {
052:                theValue = v;
053:            }
054:
055:            public Temperature(String s) {
056:                int i = indexOfType(s);
057:                if (i < 0)
058:                    throw new UnknownUnitException();
059:                double n = Double.valueOf(s.substring(0, i).trim())
060:                        .doubleValue();
061:                String u = s.substring(i).trim().toLowerCase();
062:                if (u.equals("celsius"))
063:                    theValue = n;
064:                else if (u.equals("fahrenheit"))
065:                    theValue = FAHRENHEIT_TO_CELSIUS.convert(n);
066:                else
067:                    throw new UnknownUnitException();
068:            }
069:
070:            public int getCommonUnit() {
071:                return FAHRENHEIT;
072:            }
073:
074:            public int getMaxUnit() {
075:                return 1;
076:            }
077:
078:            public String getUnitName(int i) {
079:                if (i == 0)
080:                    return "celcius";
081:                else if (i == 1)
082:                    return "fahrenheit";
083:                else
084:                    throw new IllegalArgumentException();
085:            }
086:
087:            // TypeNamed factory methods
088:            public static Temperature newCelsius(double v) {
089:                return new Temperature(v);
090:            }
091:
092:            public static Temperature newCelsius(String s) {
093:                return new Temperature((Double.valueOf(s).doubleValue()));
094:            }
095:
096:            public static Temperature newFahrenheit(double v) {
097:                return new Temperature(FAHRENHEIT_TO_CELSIUS.convert(v));
098:            }
099:
100:            public static Temperature newFahrenheit(String s) {
101:                return new Temperature(FAHRENHEIT_TO_CELSIUS.convert(Double
102:                        .valueOf(s).doubleValue()));
103:            }
104:
105:            // Index Typed factory methods
106:            private static final Conversion convFactor[] = {
107:            // conversions to base units
108:                    CELSIUS_TO_CELSIUS, FAHRENHEIT_TO_CELSIUS,
109:                    // conversions from base units
110:                    CELSIUS_TO_CELSIUS, CELSIUS_TO_FAHRENHEIT };
111:            // indexes into factor array
112:            public static int CELSIUS = 0;
113:            public static int FAHRENHEIT = 1;
114:            private static int MAXUNIT = 1;
115:
116:            // Index Typed factory methods
117:            public static Temperature newTemperature(double v, int unit) {
118:                if (unit >= 0 && unit <= MAXUNIT)
119:                    return new Temperature(convFactor[unit].convert(v));
120:                else
121:                    throw new UnknownUnitException();
122:            }
123:
124:            public static Temperature newTemperature(String s, int unit) {
125:                if (unit >= 0 && unit <= MAXUNIT)
126:                    return new Temperature(convFactor[unit].convert(Double
127:                            .valueOf(s).doubleValue()));
128:                else
129:                    throw new UnknownUnitException();
130:            }
131:
132:            // Support for AbstractMeasure-level constructor
133:            public static AbstractMeasure newMeasure(String s, int unit) {
134:                return newTemperature(s, unit);
135:            }
136:
137:            public static AbstractMeasure newMeasure(double v, int unit) {
138:                return newTemperature(v, unit);
139:            }
140:
141:            // Unit-based Reader methods
142:            public double getCelsius() {
143:                return (theValue);
144:            }
145:
146:            public double getFahrenheit() {
147:                return (CELSIUS_TO_FAHRENHEIT.convert(theValue));
148:            }
149:
150:            public double getValue(int unit) {
151:                if (unit >= 0 && unit <= MAXUNIT)
152:                    return convFactor[MAXUNIT + 1 + unit].convert(theValue);
153:                else
154:                    throw new UnknownUnitException();
155:            }
156:
157:            public static Conversion getConversion(final int from, final int to) {
158:                if (from >= 0 && from <= MAXUNIT && to >= 0 && to <= MAXUNIT) {
159:                    return new Conversion() {
160:                        public double convert(double value) {
161:                            return convFactor[MAXUNIT + 1 + to]
162:                                    .convert(convFactor[from].convert(value));
163:                        }
164:                    };
165:                } else
166:                    throw new UnknownUnitException();
167:            }
168:
169:            public boolean equals(Object o) {
170:                return (o instanceof  Temperature && theValue == ((Temperature) o)
171:                        .getCelsius());
172:            }
173:
174:            public String toString() {
175:                return Double.toString(theValue) + "c";
176:            }
177:
178:            public int hashCode() {
179:                return (new Double(theValue)).hashCode();
180:            }
181:
182:            /**
183:             * TODO : fill in
184:             * @param other
185:             * @return
186:             */
187:            public Measure add(Measure other) {
188:                return null;
189:            }
190:
191:            /**
192:             * TODO : fill in
193:             * @param other
194:             * @return
195:             */
196:            public Measure subtract(Measure other) {
197:                return null;
198:            }
199:
200:            public Measure negate() {
201:                return null;
202:            }
203:
204:            public Measure scale(double scale) {
205:                return null;
206:            }
207:
208:            public Measure floor(int unit) {
209:                return null;
210:            }
211:
212:            public Measure valueOf(double value) {
213:                return null;
214:            }
215:
216:            public Measure valueOf(double value, int unit) {
217:                return null;
218:            }
219:
220:            public int getNativeUnit() {
221:                return 0;
222:            }
223:
224:            public double getNativeValue() {
225:                return getValue(getNativeUnit());
226:            }
227:
228:            public Duration divide(Rate rate) {
229:                return null;
230:            }
231:        } // end Temperature
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.